]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
gcc_update (files_and_dependencies): Insert libffi dependencies.
[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
8bb418a3
ZL
220/* AltiVec requires a few more basic types in addition to the vector
221 types already defined in tree.c. */
222static GTY(()) tree bool_char_type_node; /* __bool char */
223static GTY(()) tree bool_short_type_node; /* __bool short */
224static GTY(()) tree bool_int_type_node; /* __bool int */
225static GTY(()) tree pixel_type_node; /* __pixel */
226static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
227static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
228static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
229static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
230
231int rs6000_warn_altivec_long = 1; /* On by default. */
232const char *rs6000_warn_altivec_long_switch;
233
57ac7be9
AM
234const char *rs6000_traceback_name;
235static enum {
236 traceback_default = 0,
237 traceback_none,
238 traceback_part,
239 traceback_full
240} rs6000_traceback;
241
38c1f2d7
MM
242/* Flag to say the TOC is initialized */
243int toc_initialized;
9ebbca7d 244char toc_label_name[10];
38c1f2d7 245
9ebbca7d 246/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 247static GTY(()) int rs6000_sr_alias_set;
c8023011 248
a5c76ee6
ZW
249/* Call distance, overridden by -mlongcall and #pragma longcall(1).
250 The only place that looks at this is rs6000_set_default_type_attributes;
251 everywhere else should rely on the presence or absence of a longcall
252 attribute on the function declaration. */
253int rs6000_default_long_calls;
254const char *rs6000_longcall_switch;
255
a3c9585f
KH
256/* Control alignment for fields within structures. */
257/* String from -malign-XXXXX. */
025d9908
KH
258const char *rs6000_alignment_string;
259int rs6000_alignment_flags;
260
a3170dc6
AH
261struct builtin_description
262{
263 /* mask is not const because we're going to alter it below. This
264 nonsense will go away when we rewrite the -march infrastructure
265 to give us more target flag bits. */
266 unsigned int mask;
267 const enum insn_code icode;
268 const char *const name;
269 const enum rs6000_builtins code;
270};
271
a2369ed3
DJ
272static bool rs6000_function_ok_for_sibcall (tree, tree);
273static int num_insns_constant_wide (HOST_WIDE_INT);
274static void validate_condition_mode (enum rtx_code, enum machine_mode);
275static rtx rs6000_generate_compare (enum rtx_code);
276static void rs6000_maybe_dead (rtx);
277static void rs6000_emit_stack_tie (void);
278static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
279static rtx spe_synthesize_frame_save (rtx);
280static bool spe_func_has_64bit_regs_p (void);
b20a9cca 281static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 282 int, HOST_WIDE_INT);
a2369ed3
DJ
283static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
284static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
285static unsigned rs6000_hash_constant (rtx);
286static unsigned toc_hash_function (const void *);
287static int toc_hash_eq (const void *, const void *);
288static int constant_pool_expr_1 (rtx, int *, int *);
289static bool constant_pool_expr_p (rtx);
290static bool toc_relative_expr_p (rtx);
291static bool legitimate_small_data_p (enum machine_mode, rtx);
292static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
293static bool legitimate_indexed_address_p (rtx, int);
294static bool legitimate_indirect_address_p (rtx, int);
4c81e946 295static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
296static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
297static struct machine_function * rs6000_init_machine_status (void);
298static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 299#ifdef HAVE_GAS_HIDDEN
a2369ed3 300static void rs6000_assemble_visibility (tree, int);
5add3202 301#endif
a2369ed3
DJ
302static int rs6000_ra_ever_killed (void);
303static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 304static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
b86fe7b4 305extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
306static void rs6000_set_default_type_attributes (tree);
307static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
308static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
309static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
310 tree);
a2369ed3 311static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 312static bool rs6000_return_in_memory (tree, tree);
a2369ed3 313static void rs6000_file_start (void);
7c262518 314#if TARGET_ELF
a2369ed3
DJ
315static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
316static void rs6000_elf_asm_out_constructor (rtx, int);
317static void rs6000_elf_asm_out_destructor (rtx, int);
318static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
319static void rs6000_elf_unique_section (tree, int);
320static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 321 unsigned HOST_WIDE_INT);
a56d7372 322static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 323 ATTRIBUTE_UNUSED;
a2369ed3 324static bool rs6000_elf_in_small_data_p (tree);
7c262518 325#endif
cbaaba19 326#if TARGET_XCOFF
a2369ed3
DJ
327static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
328static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
329static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
330static void rs6000_xcoff_unique_section (tree, int);
331static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 332 unsigned HOST_WIDE_INT);
a2369ed3
DJ
333static const char * rs6000_xcoff_strip_name_encoding (const char *);
334static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
335static void rs6000_xcoff_file_start (void);
336static void rs6000_xcoff_file_end (void);
f1384257
AM
337#endif
338#if TARGET_MACHO
a2369ed3 339static bool rs6000_binds_local_p (tree);
f1384257 340#endif
a2369ed3
DJ
341static int rs6000_use_dfa_pipeline_interface (void);
342static int rs6000_variable_issue (FILE *, int, rtx, int);
343static bool rs6000_rtx_costs (rtx, int, int, int *);
344static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 345static bool is_microcoded_insn (rtx);
79ae11c4 346static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
347static bool is_cracked_insn (rtx);
348static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
349static int rs6000_adjust_priority (rtx, int);
350static int rs6000_issue_rate (void);
569fa502 351static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
352static rtx get_next_active_insn (rtx, rtx);
353static bool insn_terminates_group_p (rtx , enum group_termination);
354static bool is_costly_group (rtx *, rtx);
355static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
356static int redefine_groups (FILE *, int, rtx, rtx);
357static int pad_groups (FILE *, int, rtx, rtx);
358static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
359static int rs6000_use_sched_lookahead (void);
360
361static void rs6000_init_builtins (void);
362static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
363static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
364static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
365static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
366static void altivec_init_builtins (void);
367static void rs6000_common_init_builtins (void);
c15c90bb 368static void rs6000_init_libfuncs (void);
a2369ed3 369
b20a9cca
AM
370static void enable_mask_for_builtins (struct builtin_description *, int,
371 enum rs6000_builtins,
372 enum rs6000_builtins);
a2369ed3
DJ
373static void spe_init_builtins (void);
374static rtx spe_expand_builtin (tree, rtx, bool *);
375static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
376static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
377static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
378static rs6000_stack_t *rs6000_stack_info (void);
379static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
380
381static rtx altivec_expand_builtin (tree, rtx, bool *);
382static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
383static rtx altivec_expand_st_builtin (tree, rtx, bool *);
384static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
385static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
386static rtx altivec_expand_predicate_builtin (enum insn_code,
387 const char *, tree, rtx);
b4a62fa0 388static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
389static rtx altivec_expand_stv_builtin (enum insn_code, tree);
390static void rs6000_parse_abi_options (void);
391static void rs6000_parse_alignment_option (void);
392static void rs6000_parse_tls_size_option (void);
5da702b1 393static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
394static int first_altivec_reg_to_save (void);
395static unsigned int compute_vrsave_mask (void);
396static void is_altivec_return_reg (rtx, void *);
397static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
398int easy_vector_constant (rtx, enum machine_mode);
399static int easy_vector_same (rtx, enum machine_mode);
400static bool is_ev64_opaque_type (tree);
401static rtx rs6000_dwarf_register_span (rtx);
402static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
403static rtx rs6000_tls_get_addr (void);
404static rtx rs6000_got_sym (void);
405static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
406static const char *rs6000_get_some_local_dynamic_name (void);
407static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 408static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 409static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 410 enum machine_mode, tree);
b78d48dd
FJ
411static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *,
412 enum machine_mode, tree, int);
b1917422 413static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
414static void setup_incoming_varargs (CUMULATIVE_ARGS *,
415 enum machine_mode, tree,
416 int *, int);
efdba735
SH
417#if TARGET_MACHO
418static void macho_branch_islands (void);
419static void add_compiler_branch_island (tree, tree, int);
420static int no_previous_def (tree function_name);
421static tree get_prev_label (tree function_name);
422#endif
423
c35d187f 424static tree rs6000_build_builtin_va_list (void);
17211ab5
GK
425
426/* Hash table stuff for keeping track of TOC entries. */
427
428struct toc_hash_struct GTY(())
429{
430 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
431 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
432 rtx key;
433 enum machine_mode key_mode;
434 int labelno;
435};
436
437static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
438\f
439/* Default register names. */
440char rs6000_reg_names[][8] =
441{
802a0058
MM
442 "0", "1", "2", "3", "4", "5", "6", "7",
443 "8", "9", "10", "11", "12", "13", "14", "15",
444 "16", "17", "18", "19", "20", "21", "22", "23",
445 "24", "25", "26", "27", "28", "29", "30", "31",
446 "0", "1", "2", "3", "4", "5", "6", "7",
447 "8", "9", "10", "11", "12", "13", "14", "15",
448 "16", "17", "18", "19", "20", "21", "22", "23",
449 "24", "25", "26", "27", "28", "29", "30", "31",
450 "mq", "lr", "ctr","ap",
451 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
452 "xer",
453 /* AltiVec registers. */
0cd5e3a1
AH
454 "0", "1", "2", "3", "4", "5", "6", "7",
455 "8", "9", "10", "11", "12", "13", "14", "15",
456 "16", "17", "18", "19", "20", "21", "22", "23",
457 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
458 "vrsave", "vscr",
459 /* SPE registers. */
460 "spe_acc", "spefscr"
c81bebd7
MM
461};
462
463#ifdef TARGET_REGNAMES
8b60264b 464static const char alt_reg_names[][8] =
c81bebd7 465{
802a0058
MM
466 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
467 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
468 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
469 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
470 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
471 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
472 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
473 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
474 "mq", "lr", "ctr", "ap",
475 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 476 "xer",
59a4c851 477 /* AltiVec registers. */
0ac081f6 478 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
479 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
480 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
481 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
482 "vrsave", "vscr",
483 /* SPE registers. */
484 "spe_acc", "spefscr"
c81bebd7
MM
485};
486#endif
9878760c 487\f
daf11973
MM
488#ifndef MASK_STRICT_ALIGN
489#define MASK_STRICT_ALIGN 0
490#endif
ffcfcb5f
AM
491#ifndef TARGET_PROFILE_KERNEL
492#define TARGET_PROFILE_KERNEL 0
493#endif
3961e8fe
RH
494
495/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
496#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
497
498/* Return 1 for a symbol ref for a thread-local storage symbol. */
499#define RS6000_SYMBOL_REF_TLS_P(RTX) \
500 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
501\f
502/* Initialize the GCC target structure. */
91d231cb
JM
503#undef TARGET_ATTRIBUTE_TABLE
504#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
505#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
506#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 507
301d03af
RS
508#undef TARGET_ASM_ALIGNED_DI_OP
509#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
510
511/* Default unaligned ops are only provided for ELF. Find the ops needed
512 for non-ELF systems. */
513#ifndef OBJECT_FORMAT_ELF
cbaaba19 514#if TARGET_XCOFF
ae6c1efd 515/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
516 64-bit targets. */
517#undef TARGET_ASM_UNALIGNED_HI_OP
518#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
519#undef TARGET_ASM_UNALIGNED_SI_OP
520#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
521#undef TARGET_ASM_UNALIGNED_DI_OP
522#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
523#else
524/* For Darwin. */
525#undef TARGET_ASM_UNALIGNED_HI_OP
526#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
527#undef TARGET_ASM_UNALIGNED_SI_OP
528#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
529#endif
530#endif
531
532/* This hook deals with fixups for relocatable code and DI-mode objects
533 in 64-bit code. */
534#undef TARGET_ASM_INTEGER
535#define TARGET_ASM_INTEGER rs6000_assemble_integer
536
93638d7a
AM
537#ifdef HAVE_GAS_HIDDEN
538#undef TARGET_ASM_ASSEMBLE_VISIBILITY
539#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
540#endif
541
c4501e62
JJ
542#undef TARGET_HAVE_TLS
543#define TARGET_HAVE_TLS HAVE_AS_TLS
544
545#undef TARGET_CANNOT_FORCE_CONST_MEM
546#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
547
08c148a8
NB
548#undef TARGET_ASM_FUNCTION_PROLOGUE
549#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
550#undef TARGET_ASM_FUNCTION_EPILOGUE
551#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
552
b54cf83a
DE
553#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
554#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
555#undef TARGET_SCHED_VARIABLE_ISSUE
556#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
557
c237e94a
ZW
558#undef TARGET_SCHED_ISSUE_RATE
559#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
560#undef TARGET_SCHED_ADJUST_COST
561#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
562#undef TARGET_SCHED_ADJUST_PRIORITY
563#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
569fa502
DN
564#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
565#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
566#undef TARGET_SCHED_FINISH
567#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 568
be12c2b0
VM
569#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
570#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
571
0ac081f6
AH
572#undef TARGET_INIT_BUILTINS
573#define TARGET_INIT_BUILTINS rs6000_init_builtins
574
575#undef TARGET_EXPAND_BUILTIN
576#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
577
c15c90bb
ZW
578#undef TARGET_INIT_LIBFUNCS
579#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
580
f1384257 581#if TARGET_MACHO
0e5dbd9b
DE
582#undef TARGET_BINDS_LOCAL_P
583#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 584#endif
0e5dbd9b 585
3961e8fe
RH
586#undef TARGET_ASM_OUTPUT_MI_THUNK
587#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
588
3961e8fe 589#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 590#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 591
4977bab6
ZW
592#undef TARGET_FUNCTION_OK_FOR_SIBCALL
593#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
594
3c50106f
RH
595#undef TARGET_RTX_COSTS
596#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
597#undef TARGET_ADDRESS_COST
598#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 599
c8e4f0e9
AH
600#undef TARGET_VECTOR_OPAQUE_P
601#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 602
96714395
AH
603#undef TARGET_DWARF_REGISTER_SPAN
604#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
605
c6e8c921
GK
606/* On rs6000, function arguments are promoted, as are function return
607 values. */
608#undef TARGET_PROMOTE_FUNCTION_ARGS
609#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
610#undef TARGET_PROMOTE_FUNCTION_RETURN
611#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
612
c6e8c921
GK
613#undef TARGET_RETURN_IN_MEMORY
614#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
615
616#undef TARGET_SETUP_INCOMING_VARARGS
617#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
618
619/* Always strict argument naming on rs6000. */
620#undef TARGET_STRICT_ARGUMENT_NAMING
621#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
622#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
623#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
624#undef TARGET_SPLIT_COMPLEX_ARG
625#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
c6e8c921 626
c35d187f
RH
627#undef TARGET_BUILD_BUILTIN_VA_LIST
628#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
629
f6897b10 630struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 631\f
5248c961
RK
632/* Override command line options. Mostly we process the processor
633 type and sometimes adjust other TARGET_ options. */
634
635void
d779d0dc 636rs6000_override_options (const char *default_cpu)
5248c961 637{
c4d38ccb 638 size_t i, j;
8e3f41e7 639 struct rs6000_cpu_select *ptr;
66188a7e 640 int set_masks;
5248c961 641
66188a7e 642 /* Simplifications for entries below. */
85638c0d 643
66188a7e
GK
644 enum {
645 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
646 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
647 };
85638c0d 648
66188a7e
GK
649 /* This table occasionally claims that a processor does not support
650 a particular feature even though it does, but the feature is slower
651 than the alternative. Thus, it shouldn't be relied on as a
652 complete description of the processor's support.
653
654 Please keep this list in order, and don't forget to update the
655 documentation in invoke.texi when adding a new processor or
656 flag. */
5248c961
RK
657 static struct ptt
658 {
8b60264b
KG
659 const char *const name; /* Canonical processor name. */
660 const enum processor_type processor; /* Processor type enum value. */
661 const int target_enable; /* Target flags to enable. */
8b60264b 662 } const processor_target_table[]
66188a7e 663 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 664 {"403", PROCESSOR_PPC403,
66188a7e
GK
665 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
666 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
667 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
668 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
669 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
670 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 671 {"601", PROCESSOR_PPC601,
66188a7e
GK
672 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
673 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
674 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
675 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
676 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
677 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
678 {"620", PROCESSOR_PPC620,
679 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
680 {"630", PROCESSOR_PPC630,
681 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
682 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
683 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
684 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
685 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
686 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
687 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
688 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
689 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
690 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 691 {"970", PROCESSOR_POWER4,
66188a7e
GK
692 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
693 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
694 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
695 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
696 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 697 {"G5", PROCESSOR_POWER4,
66188a7e
GK
698 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
699 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
700 {"power2", PROCESSOR_POWER,
701 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
702 {"power3", PROCESSOR_PPC630,
703 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
704 {"power4", PROCESSOR_POWER4,
705 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
706 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
707 {"powerpc64", PROCESSOR_POWERPC64,
708 POWERPC_BASE_MASK | MASK_POWERPC64},
709 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
710 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
711 {"rios2", PROCESSOR_RIOS2,
712 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
713 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
714 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 715 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 716 };
5248c961 717
ca7558fc 718 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 719
66188a7e
GK
720 /* Some OSs don't support saving the high part of 64-bit registers on
721 context switch. Other OSs don't support saving Altivec registers.
722 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
723 settings; if the user wants either, the user must explicitly specify
724 them and we won't interfere with the user's specification. */
725
726 enum {
727 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
728 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
729 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
730 | MASK_MFCRF)
731 };
732 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
733#ifdef OS_MISSING_POWERPC64
734 if (OS_MISSING_POWERPC64)
735 set_masks &= ~MASK_POWERPC64;
736#endif
737#ifdef OS_MISSING_ALTIVEC
738 if (OS_MISSING_ALTIVEC)
739 set_masks &= ~MASK_ALTIVEC;
740#endif
741
957211c3
AM
742 /* Don't override these by the processor default if given explicitly. */
743 set_masks &= ~(target_flags_explicit
744 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
745
a4f6c312 746 /* Identify the processor type. */
8e3f41e7 747 rs6000_select[0].string = default_cpu;
3cb999d8 748 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 749
b6a1cbae 750 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 751 {
8e3f41e7
MM
752 ptr = &rs6000_select[i];
753 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 754 {
8e3f41e7
MM
755 for (j = 0; j < ptt_size; j++)
756 if (! strcmp (ptr->string, processor_target_table[j].name))
757 {
758 if (ptr->set_tune_p)
759 rs6000_cpu = processor_target_table[j].processor;
760
761 if (ptr->set_arch_p)
762 {
66188a7e
GK
763 target_flags &= ~set_masks;
764 target_flags |= (processor_target_table[j].target_enable
765 & set_masks);
8e3f41e7
MM
766 }
767 break;
768 }
769
4406229e 770 if (j == ptt_size)
8e3f41e7 771 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
772 }
773 }
8a61d227 774
993f19a8 775 if (TARGET_E500)
a3170dc6
AH
776 rs6000_isel = 1;
777
dff9f1b6
DE
778 /* If we are optimizing big endian systems for space, use the load/store
779 multiple and string instructions. */
ef792183 780 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 781 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 782
a4f6c312
SS
783 /* Don't allow -mmultiple or -mstring on little endian systems
784 unless the cpu is a 750, because the hardware doesn't support the
785 instructions used in little endian mode, and causes an alignment
786 trap. The 750 does not cause an alignment trap (except when the
787 target is unaligned). */
bef84347 788
b21fb038 789 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
790 {
791 if (TARGET_MULTIPLE)
792 {
793 target_flags &= ~MASK_MULTIPLE;
b21fb038 794 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
795 warning ("-mmultiple is not supported on little endian systems");
796 }
797
798 if (TARGET_STRING)
799 {
800 target_flags &= ~MASK_STRING;
b21fb038 801 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 802 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
803 }
804 }
3933e0e1 805
38c1f2d7
MM
806 /* Set debug flags */
807 if (rs6000_debug_name)
808 {
bfc79d3b 809 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 810 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 811 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 812 rs6000_debug_stack = 1;
bfc79d3b 813 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
814 rs6000_debug_arg = 1;
815 else
c725bd79 816 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
817 }
818
57ac7be9
AM
819 if (rs6000_traceback_name)
820 {
821 if (! strncmp (rs6000_traceback_name, "full", 4))
822 rs6000_traceback = traceback_full;
823 else if (! strncmp (rs6000_traceback_name, "part", 4))
824 rs6000_traceback = traceback_part;
825 else if (! strncmp (rs6000_traceback_name, "no", 2))
826 rs6000_traceback = traceback_none;
827 else
828 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
829 rs6000_traceback_name);
830 }
831
6fa3f289
ZW
832 /* Set size of long double */
833 rs6000_long_double_type_size = 64;
834 if (rs6000_long_double_size_string)
835 {
836 char *tail;
837 int size = strtol (rs6000_long_double_size_string, &tail, 10);
838 if (*tail != '\0' || (size != 64 && size != 128))
839 error ("Unknown switch -mlong-double-%s",
840 rs6000_long_double_size_string);
841 else
842 rs6000_long_double_type_size = size;
843 }
844
6d0ef01e
HP
845 /* Set Altivec ABI as default for powerpc64 linux. */
846 if (TARGET_ELF && TARGET_64BIT)
847 {
848 rs6000_altivec_abi = 1;
849 rs6000_altivec_vrsave = 1;
850 }
851
0ac081f6
AH
852 /* Handle -mabi= options. */
853 rs6000_parse_abi_options ();
854
025d9908
KH
855 /* Handle -malign-XXXXX option. */
856 rs6000_parse_alignment_option ();
857
5da702b1
AH
858 /* Handle generic -mFOO=YES/NO options. */
859 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
860 &rs6000_altivec_vrsave);
861 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
862 &rs6000_isel);
863 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
864 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
865 &rs6000_float_gprs);
993f19a8 866
c4501e62
JJ
867 /* Handle -mtls-size option. */
868 rs6000_parse_tls_size_option ();
869
a7ae18e2
AH
870#ifdef SUBTARGET_OVERRIDE_OPTIONS
871 SUBTARGET_OVERRIDE_OPTIONS;
872#endif
873#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
874 SUBSUBTARGET_OVERRIDE_OPTIONS;
875#endif
876
5da702b1
AH
877 if (TARGET_E500)
878 {
879 /* The e500 does not have string instructions, and we set
880 MASK_STRING above when optimizing for size. */
881 if ((target_flags & MASK_STRING) != 0)
882 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
883
884 /* No SPE means 64-bit long doubles, even if an E500. */
885 if (rs6000_spe_string != 0
886 && !strcmp (rs6000_spe_string, "no"))
887 rs6000_long_double_type_size = 64;
5da702b1
AH
888 }
889 else if (rs6000_select[1].string != NULL)
890 {
891 /* For the powerpc-eabispe configuration, we set all these by
892 default, so let's unset them if we manually set another
893 CPU that is not the E500. */
894 if (rs6000_abi_string == 0)
895 rs6000_spe_abi = 0;
896 if (rs6000_spe_string == 0)
897 rs6000_spe = 0;
898 if (rs6000_float_gprs_string == 0)
899 rs6000_float_gprs = 0;
900 if (rs6000_isel_string == 0)
901 rs6000_isel = 0;
b6e59a3a
AH
902 if (rs6000_long_double_size_string == 0)
903 rs6000_long_double_type_size = 64;
5da702b1 904 }
b5044283 905
a5c76ee6
ZW
906 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
907 using TARGET_OPTIONS to handle a toggle switch, but we're out of
908 bits in target_flags so TARGET_SWITCHES cannot be used.
909 Assumption here is that rs6000_longcall_switch points into the
910 text of the complete option, rather than being a copy, so we can
911 scan back for the presence or absence of the no- modifier. */
912 if (rs6000_longcall_switch)
913 {
914 const char *base = rs6000_longcall_switch;
915 while (base[-1] != 'm') base--;
916
917 if (*rs6000_longcall_switch != '\0')
918 error ("invalid option `%s'", base);
919 rs6000_default_long_calls = (base[0] != 'n');
920 }
921
8bb418a3
ZL
922 /* Handle -m(no-)warn-altivec-long similarly. */
923 if (rs6000_warn_altivec_long_switch)
924 {
925 const char *base = rs6000_warn_altivec_long_switch;
926 while (base[-1] != 'm') base--;
927
928 if (*rs6000_warn_altivec_long_switch != '\0')
929 error ("invalid option `%s'", base);
930 rs6000_warn_altivec_long = (base[0] != 'n');
931 }
932
cbe26ab8 933 /* Handle -mprioritize-restricted-insns option. */
79ae11c4
DN
934 rs6000_sched_restricted_insns_priority = DEFAULT_RESTRICTED_INSNS_PRIORITY;
935 if (rs6000_sched_restricted_insns_priority_str)
936 rs6000_sched_restricted_insns_priority =
937 atoi (rs6000_sched_restricted_insns_priority_str);
938
569fa502
DN
939 /* Handle -msched-costly-dep option. */
940 rs6000_sched_costly_dep = DEFAULT_SCHED_COSTLY_DEP;
941 if (rs6000_sched_costly_dep_str)
942 {
943 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
944 rs6000_sched_costly_dep = no_dep_costly;
945 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
946 rs6000_sched_costly_dep = all_deps_costly;
947 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
948 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
949 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
950 rs6000_sched_costly_dep = store_to_load_dep_costly;
cbe26ab8
DN
951 else
952 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
953 }
954
955 /* Handle -minsert-sched-nops option. */
956 rs6000_sched_insert_nops = DEFAULT_SCHED_FINISH_NOP_INSERTION_SCHEME;
957 if (rs6000_sched_insert_nops_str)
958 {
959 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
960 rs6000_sched_insert_nops = sched_finish_none;
961 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
962 rs6000_sched_insert_nops = sched_finish_pad_groups;
963 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
964 rs6000_sched_insert_nops = sched_finish_regroup_exact;
965 else
966 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
967 }
968
c81bebd7 969#ifdef TARGET_REGNAMES
a4f6c312
SS
970 /* If the user desires alternate register names, copy in the
971 alternate names now. */
c81bebd7 972 if (TARGET_REGNAMES)
4e135bdd 973 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
974#endif
975
6fa3f289
ZW
976 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
977 If -maix-struct-return or -msvr4-struct-return was explicitly
978 used, don't override with the ABI default. */
b21fb038 979 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
980 {
981 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
982 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
983 else
984 target_flags |= MASK_AIX_STRUCT_RET;
985 }
986
fcce224d
DE
987 if (TARGET_LONG_DOUBLE_128
988 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 989 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 990
9ebbca7d
GK
991 /* Allocate an alias set for register saves & restores from stack. */
992 rs6000_sr_alias_set = new_alias_set ();
993
994 if (TARGET_TOC)
995 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 996
301d03af
RS
997 /* We can only guarantee the availability of DI pseudo-ops when
998 assembling for 64-bit targets. */
ae6c1efd 999 if (!TARGET_64BIT)
301d03af
RS
1000 {
1001 targetm.asm_out.aligned_op.di = NULL;
1002 targetm.asm_out.unaligned_op.di = NULL;
1003 }
1004
2792d578
DE
1005 /* Set maximum branch target alignment at two instructions, eight bytes. */
1006 align_jumps_max_skip = 8;
1007 align_loops_max_skip = 8;
1008
71f123ca
FS
1009 /* Arrange to save and restore machine status around nested functions. */
1010 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1011
1012 /* We should always be splitting complex arguments, but we can't break
1013 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1014 if (DEFAULT_ABI != ABI_AIX)
1015 targetm.calls.split_complex_arg = NULL;
5248c961 1016}
5accd822 1017
5da702b1
AH
1018/* Handle generic options of the form -mfoo=yes/no.
1019 NAME is the option name.
1020 VALUE is the option value.
1021 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1022 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1023static void
5da702b1 1024rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1025{
5da702b1 1026 if (value == 0)
993f19a8 1027 return;
5da702b1
AH
1028 else if (!strcmp (value, "yes"))
1029 *flag = 1;
1030 else if (!strcmp (value, "no"))
1031 *flag = 0;
08b57fb3 1032 else
5da702b1 1033 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1034}
1035
0ac081f6 1036/* Handle -mabi= options. */
00b960c7 1037static void
863d938c 1038rs6000_parse_abi_options (void)
0ac081f6
AH
1039{
1040 if (rs6000_abi_string == 0)
1041 return;
1042 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1043 {
1044 rs6000_altivec_abi = 1;
1045 rs6000_spe_abi = 0;
1046 }
76a773f3
AH
1047 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1048 rs6000_altivec_abi = 0;
a3170dc6 1049 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1050 {
1051 rs6000_spe_abi = 1;
5cc73f91 1052 rs6000_altivec_abi = 0;
01f4962d
NS
1053 if (!TARGET_SPE_ABI)
1054 error ("not configured for ABI: '%s'", rs6000_abi_string);
1055 }
1056
a3170dc6
AH
1057 else if (! strcmp (rs6000_abi_string, "no-spe"))
1058 rs6000_spe_abi = 0;
0ac081f6 1059 else
c725bd79 1060 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1061}
1062
025d9908
KH
1063/* Handle -malign-XXXXXX options. */
1064static void
863d938c 1065rs6000_parse_alignment_option (void)
025d9908 1066{
b20a9cca
AM
1067 if (rs6000_alignment_string == 0)
1068 return;
1069 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1070 rs6000_alignment_flags = MASK_ALIGN_POWER;
1071 else if (! strcmp (rs6000_alignment_string, "natural"))
1072 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1073 else
1074 error ("unknown -malign-XXXXX option specified: '%s'",
1075 rs6000_alignment_string);
1076}
1077
c4501e62
JJ
1078/* Validate and record the size specified with the -mtls-size option. */
1079
1080static void
863d938c 1081rs6000_parse_tls_size_option (void)
c4501e62
JJ
1082{
1083 if (rs6000_tls_size_string == 0)
1084 return;
1085 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1086 rs6000_tls_size = 16;
1087 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1088 rs6000_tls_size = 32;
1089 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1090 rs6000_tls_size = 64;
1091 else
1092 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1093}
1094
5accd822 1095void
a2369ed3 1096optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1097{
5accd822 1098}
3cfa4909
MM
1099\f
1100/* Do anything needed at the start of the asm file. */
1101
1bc7c5b6 1102static void
863d938c 1103rs6000_file_start (void)
3cfa4909 1104{
c4d38ccb 1105 size_t i;
3cfa4909 1106 char buffer[80];
d330fd93 1107 const char *start = buffer;
3cfa4909 1108 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1109 const char *default_cpu = TARGET_CPU_DEFAULT;
1110 FILE *file = asm_out_file;
1111
1112 default_file_start ();
1113
1114#ifdef TARGET_BI_ARCH
1115 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1116 default_cpu = 0;
1117#endif
3cfa4909
MM
1118
1119 if (flag_verbose_asm)
1120 {
1121 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1122 rs6000_select[0].string = default_cpu;
1123
b6a1cbae 1124 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1125 {
1126 ptr = &rs6000_select[i];
1127 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1128 {
1129 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1130 start = "";
1131 }
1132 }
1133
b91da81f 1134#ifdef USING_ELFOS_H
3cfa4909
MM
1135 switch (rs6000_sdata)
1136 {
1137 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1138 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1139 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1140 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1141 }
1142
1143 if (rs6000_sdata && g_switch_value)
1144 {
307b599c
MK
1145 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1146 g_switch_value);
3cfa4909
MM
1147 start = "";
1148 }
1149#endif
1150
1151 if (*start == '\0')
949ea356 1152 putc ('\n', file);
3cfa4909
MM
1153 }
1154}
5248c961 1155\f
a0ab749a 1156/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1157
1158int
863d938c 1159direct_return (void)
9878760c 1160{
4697a36c
MM
1161 if (reload_completed)
1162 {
1163 rs6000_stack_t *info = rs6000_stack_info ();
1164
1165 if (info->first_gp_reg_save == 32
1166 && info->first_fp_reg_save == 64
00b960c7 1167 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1168 && ! info->lr_save_p
1169 && ! info->cr_save_p
00b960c7 1170 && info->vrsave_mask == 0
c81fc13e 1171 && ! info->push_p)
4697a36c
MM
1172 return 1;
1173 }
1174
1175 return 0;
9878760c
RK
1176}
1177
1178/* Returns 1 always. */
1179
1180int
a2369ed3
DJ
1181any_operand (rtx op ATTRIBUTE_UNUSED,
1182 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1183{
1184 return 1;
1185}
1186
a4f6c312 1187/* Returns 1 if op is the count register. */
38c1f2d7 1188int
a2369ed3 1189count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1190{
1191 if (GET_CODE (op) != REG)
1192 return 0;
1193
1194 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1195 return 1;
1196
1197 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1198 return 1;
1199
1200 return 0;
1201}
1202
0ec4e2a8
AH
1203/* Returns 1 if op is an altivec register. */
1204int
a2369ed3 1205altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1206{
1207
1208 return (register_operand (op, mode)
1209 && (GET_CODE (op) != REG
1210 || REGNO (op) > FIRST_PSEUDO_REGISTER
1211 || ALTIVEC_REGNO_P (REGNO (op))));
1212}
1213
38c1f2d7 1214int
a2369ed3 1215xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1216{
1217 if (GET_CODE (op) != REG)
1218 return 0;
1219
9ebbca7d 1220 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1221 return 1;
1222
802a0058
MM
1223 return 0;
1224}
1225
c859cda6 1226/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1227 by such constants completes more quickly. */
c859cda6
DJ
1228
1229int
a2369ed3 1230s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1231{
1232 return ( GET_CODE (op) == CONST_INT
1233 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1234}
1235
9878760c
RK
1236/* Return 1 if OP is a constant that can fit in a D field. */
1237
1238int
a2369ed3 1239short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1240{
5f59ecb7
DE
1241 return (GET_CODE (op) == CONST_INT
1242 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1243}
1244
5519a4f9 1245/* Similar for an unsigned D field. */
9878760c
RK
1246
1247int
a2369ed3 1248u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1249{
19684119 1250 return (GET_CODE (op) == CONST_INT
c1f11548 1251 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1252}
1253
dcfedcd0
RK
1254/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1255
1256int
a2369ed3 1257non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1258{
1259 return (GET_CODE (op) == CONST_INT
a7653a2c 1260 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1261}
1262
2bfcf297
DB
1263/* Returns 1 if OP is a CONST_INT that is a positive value
1264 and an exact power of 2. */
1265
1266int
a2369ed3 1267exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1268{
1269 return (GET_CODE (op) == CONST_INT
1270 && INTVAL (op) > 0
1271 && exact_log2 (INTVAL (op)) >= 0);
1272}
1273
9878760c
RK
1274/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1275 ctr, or lr). */
1276
1277int
a2369ed3 1278gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1279{
1280 return (register_operand (op, mode)
802a0058 1281 && (GET_CODE (op) != REG
9ebbca7d
GK
1282 || (REGNO (op) >= ARG_POINTER_REGNUM
1283 && !XER_REGNO_P (REGNO (op)))
1284 || REGNO (op) < MQ_REGNO));
9878760c
RK
1285}
1286
1287/* Returns 1 if OP is either a pseudo-register or a register denoting a
1288 CR field. */
1289
1290int
a2369ed3 1291cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1292{
1293 return (register_operand (op, mode)
1294 && (GET_CODE (op) != REG
1295 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1296 || CR_REGNO_P (REGNO (op))));
1297}
1298
815cdc52
MM
1299/* Returns 1 if OP is either a pseudo-register or a register denoting a
1300 CR field that isn't CR0. */
1301
1302int
a2369ed3 1303cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1304{
1305 return (register_operand (op, mode)
1306 && (GET_CODE (op) != REG
1307 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1308 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1309}
1310
a4f6c312
SS
1311/* Returns 1 if OP is either a constant integer valid for a D-field or
1312 a non-special register. If a register, it must be in the proper
1313 mode unless MODE is VOIDmode. */
9878760c
RK
1314
1315int
a2369ed3 1316reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1317{
f5a28898 1318 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1319}
1320
a4f6c312
SS
1321/* Similar, except check if the negation of the constant would be
1322 valid for a D-field. */
9878760c
RK
1323
1324int
a2369ed3 1325reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1326{
1327 if (GET_CODE (op) == CONST_INT)
1328 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1329
cd2b37d9 1330 return gpc_reg_operand (op, mode);
9878760c
RK
1331}
1332
768070a0
TR
1333/* Returns 1 if OP is either a constant integer valid for a DS-field or
1334 a non-special register. If a register, it must be in the proper
1335 mode unless MODE is VOIDmode. */
1336
1337int
a2369ed3 1338reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1339{
1340 if (gpc_reg_operand (op, mode))
1341 return 1;
1342 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1343 return 1;
1344
1345 return 0;
1346}
1347
1348
a4f6c312
SS
1349/* Return 1 if the operand is either a register or an integer whose
1350 high-order 16 bits are zero. */
9878760c
RK
1351
1352int
a2369ed3 1353reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1354{
e675f625 1355 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1356}
1357
1358/* Return 1 is the operand is either a non-special register or ANY
1359 constant integer. */
1360
1361int
a2369ed3 1362reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1363{
a4f6c312 1364 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1365}
1366
1367/* Return 1 is the operand is either a non-special register or ANY
1368 32-bit signed constant integer. */
1369
1370int
a2369ed3 1371reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1372{
a4f6c312
SS
1373 return (gpc_reg_operand (op, mode)
1374 || (GET_CODE (op) == CONST_INT
f6bf7de2 1375#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1376 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1377 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1378#endif
a4f6c312 1379 ));
9878760c
RK
1380}
1381
2bfcf297
DB
1382/* Return 1 is the operand is either a non-special register or a 32-bit
1383 signed constant integer valid for 64-bit addition. */
1384
1385int
a2369ed3 1386reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1387{
a4f6c312
SS
1388 return (gpc_reg_operand (op, mode)
1389 || (GET_CODE (op) == CONST_INT
a65c591c 1390#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1391 && INTVAL (op) < 0x7fff8000
a65c591c 1392#else
a4f6c312
SS
1393 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1394 < 0x100000000ll)
2bfcf297 1395#endif
a4f6c312 1396 ));
2bfcf297
DB
1397}
1398
1399/* Return 1 is the operand is either a non-special register or a 32-bit
1400 signed constant integer valid for 64-bit subtraction. */
1401
1402int
a2369ed3 1403reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1404{
a4f6c312
SS
1405 return (gpc_reg_operand (op, mode)
1406 || (GET_CODE (op) == CONST_INT
a65c591c 1407#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1408 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1409#else
a4f6c312
SS
1410 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1411 < 0x100000000ll)
2bfcf297 1412#endif
a4f6c312 1413 ));
2bfcf297
DB
1414}
1415
9ebbca7d
GK
1416/* Return 1 is the operand is either a non-special register or ANY
1417 32-bit unsigned constant integer. */
1418
1419int
a2369ed3 1420reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1421{
1d328b19
GK
1422 if (GET_CODE (op) == CONST_INT)
1423 {
1424 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1425 {
1426 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1427 abort ();
1d328b19
GK
1428
1429 if (INTVAL (op) < 0)
1430 return 0;
1431 }
1432
1433 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1434 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1435 }
1436 else if (GET_CODE (op) == CONST_DOUBLE)
1437 {
1438 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1439 || mode != DImode)
a4f6c312 1440 abort ();
1d328b19
GK
1441
1442 return CONST_DOUBLE_HIGH (op) == 0;
1443 }
1444 else
1445 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1446}
1447
51d3e7d6 1448/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1449
1450int
a2369ed3 1451got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1452{
1453 return (GET_CODE (op) == SYMBOL_REF
1454 || GET_CODE (op) == CONST
1455 || GET_CODE (op) == LABEL_REF);
1456}
1457
38c1f2d7
MM
1458/* Return 1 if the operand is a simple references that can be loaded via
1459 the GOT (labels involving addition aren't allowed). */
1460
1461int
a2369ed3 1462got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1463{
1464 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1465}
1466
4e74d8ec
MM
1467/* Return the number of instructions it takes to form a constant in an
1468 integer register. */
1469
1470static int
a2369ed3 1471num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1472{
1473 /* signed constant loadable with {cal|addi} */
5f59ecb7 1474 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1475 return 1;
1476
4e74d8ec 1477 /* constant loadable with {cau|addis} */
5f59ecb7 1478 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1479 return 1;
1480
5f59ecb7 1481#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1482 else if (TARGET_POWERPC64)
4e74d8ec 1483 {
a65c591c
DE
1484 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1485 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1486
a65c591c 1487 if (high == 0 || high == -1)
4e74d8ec
MM
1488 return 2;
1489
a65c591c 1490 high >>= 1;
4e74d8ec 1491
a65c591c 1492 if (low == 0)
4e74d8ec 1493 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1494 else
1495 return (num_insns_constant_wide (high)
e396202a 1496 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1497 }
1498#endif
1499
1500 else
1501 return 2;
1502}
1503
1504int
a2369ed3 1505num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1506{
4e74d8ec 1507 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1508 {
1509#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1510 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1511 && mask64_operand (op, mode))
0d30d435
DE
1512 return 2;
1513 else
1514#endif
1515 return num_insns_constant_wide (INTVAL (op));
1516 }
4e74d8ec 1517
6fc48950
MM
1518 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1519 {
1520 long l;
1521 REAL_VALUE_TYPE rv;
1522
1523 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1524 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1525 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1526 }
1527
47ad8c61 1528 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1529 {
47ad8c61
MM
1530 HOST_WIDE_INT low;
1531 HOST_WIDE_INT high;
1532 long l[2];
1533 REAL_VALUE_TYPE rv;
1534 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1535
47ad8c61
MM
1536 if (mode == VOIDmode || mode == DImode)
1537 {
1538 high = CONST_DOUBLE_HIGH (op);
1539 low = CONST_DOUBLE_LOW (op);
1540 }
1541 else
1542 {
1543 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1544 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1545 high = l[endian];
1546 low = l[1 - endian];
1547 }
4e74d8ec 1548
47ad8c61
MM
1549 if (TARGET_32BIT)
1550 return (num_insns_constant_wide (low)
1551 + num_insns_constant_wide (high));
4e74d8ec
MM
1552
1553 else
47ad8c61 1554 {
e72247f4 1555 if (high == 0 && low >= 0)
47ad8c61
MM
1556 return num_insns_constant_wide (low);
1557
e72247f4 1558 else if (high == -1 && low < 0)
47ad8c61
MM
1559 return num_insns_constant_wide (low);
1560
a260abc9
DE
1561 else if (mask64_operand (op, mode))
1562 return 2;
1563
47ad8c61
MM
1564 else if (low == 0)
1565 return num_insns_constant_wide (high) + 1;
1566
1567 else
1568 return (num_insns_constant_wide (high)
1569 + num_insns_constant_wide (low) + 1);
1570 }
4e74d8ec
MM
1571 }
1572
1573 else
1574 abort ();
1575}
1576
a4f6c312
SS
1577/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1578 register with one instruction per word. We only do this if we can
1579 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1580
1581int
a2369ed3 1582easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1583{
9878760c
RK
1584 if (GET_CODE (op) != CONST_DOUBLE
1585 || GET_MODE (op) != mode
4e74d8ec 1586 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1587 return 0;
1588
a4f6c312 1589 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1590 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1591 && mode != DImode)
b6c9286a
MM
1592 return 1;
1593
a4f6c312 1594 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1595 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1596 return 0;
1597
5ae4759c 1598#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1599 /* Similarly if we are using -mrelocatable, consider all constants
1600 to be hard. */
5ae4759c
MM
1601 if (TARGET_RELOCATABLE)
1602 return 0;
1603#endif
1604
fcce224d
DE
1605 if (mode == TFmode)
1606 {
1607 long k[4];
1608 REAL_VALUE_TYPE rv;
1609
1610 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1611 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1612
1613 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1614 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1615 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1616 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1617 }
1618
1619 else if (mode == DFmode)
042259f2
DE
1620 {
1621 long k[2];
1622 REAL_VALUE_TYPE rv;
1623
1624 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1625 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1626
a65c591c
DE
1627 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1628 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1629 }
4e74d8ec
MM
1630
1631 else if (mode == SFmode)
042259f2
DE
1632 {
1633 long l;
1634 REAL_VALUE_TYPE rv;
1635
1636 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1637 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1638
4e74d8ec 1639 return num_insns_constant_wide (l) == 1;
042259f2 1640 }
4e74d8ec 1641
a260abc9 1642 else if (mode == DImode)
c81fc13e 1643 return ((TARGET_POWERPC64
a260abc9
DE
1644 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1645 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1646
a9098fd0
GK
1647 else if (mode == SImode)
1648 return 1;
4e74d8ec
MM
1649 else
1650 abort ();
9878760c 1651}
8f75773e 1652
72ac76be 1653/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1654
1655static int
a2369ed3 1656easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1657{
1658 int units, i, cst;
1659
1660 units = CONST_VECTOR_NUNITS (op);
1661
1662 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1663 for (i = 1; i < units; ++i)
1664 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1665 break;
1666 if (i == units)
1667 return 1;
1668 return 0;
1669}
1670
1671/* Return 1 if the operand is a CONST_INT and can be put into a
1672 register without using memory. */
1673
1674int
a2369ed3 1675easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1676{
d744e06e 1677 int cst, cst2;
69ef87e2 1678
d744e06e
AH
1679 if (GET_CODE (op) != CONST_VECTOR
1680 || (!TARGET_ALTIVEC
1681 && !TARGET_SPE))
69ef87e2
AH
1682 return 0;
1683
d744e06e
AH
1684 if (zero_constant (op, mode)
1685 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1686 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1687 return 1;
69ef87e2 1688
d744e06e
AH
1689 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1690 return 0;
1691
f5119d10
AH
1692 if (TARGET_SPE && mode == V1DImode)
1693 return 0;
1694
d744e06e
AH
1695 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1696 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1697
1698 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1699 li r0, CONSTANT1
1700 evmergelo r0, r0, r0
1701 li r0, CONSTANT2
1702
1703 I don't know how efficient it would be to allow bigger constants,
1704 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1705 instructions is better than a 64-bit memory load, but I don't
1706 have the e500 timing specs. */
1707 if (TARGET_SPE && mode == V2SImode
1708 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1709 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1710 return 1;
1711
ce1f50b2
HP
1712 if (TARGET_ALTIVEC)
1713 switch (mode)
1714 {
1715 case V4SImode:
1716 if (EASY_VECTOR_15 (cst, op, mode))
1717 return 1;
1718 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
1719 break;
1720 cst = cst >> 16;
1721 case V8HImode:
1722 if (EASY_VECTOR_15 (cst, op, mode))
1723 return 1;
1724 if ((cst & 0xff) != ((cst >> 8) & 0xff))
1725 break;
1726 cst = cst >> 8;
1727 case V16QImode:
1728 if (EASY_VECTOR_15 (cst, op, mode))
1729 return 1;
1730 default:
1731 break;
1732 }
d744e06e
AH
1733
1734 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1735 return 1;
1736
1737 return 0;
1738}
1739
1740/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1741
1742int
a2369ed3 1743easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1744{
1745 int cst;
1746
1747 if (!easy_vector_constant (op, mode))
1748 return 0;
1749
1750 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1751
1752 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1753}
1754
1755const char *
a2369ed3 1756output_vec_const_move (rtx *operands)
d744e06e
AH
1757{
1758 int cst, cst2;
1759 enum machine_mode mode;
1760 rtx dest, vec;
1761
1762 dest = operands[0];
1763 vec = operands[1];
69ef87e2 1764
d744e06e
AH
1765 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1766 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1767 mode = GET_MODE (dest);
69ef87e2 1768
d744e06e
AH
1769 if (TARGET_ALTIVEC)
1770 {
1771 if (zero_constant (vec, mode))
1772 return "vxor %0,%0,%0";
ce1f50b2
HP
1773 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1774 return "#";
1775 else if (easy_vector_constant (vec, mode))
98ef3137 1776 {
d744e06e
AH
1777 operands[1] = GEN_INT (cst);
1778 switch (mode)
1779 {
1780 case V4SImode:
ce1f50b2
HP
1781 if (EASY_VECTOR_15 (cst, vec, mode))
1782 {
1783 operands[1] = GEN_INT (cst);
1784 return "vspltisw %0,%1";
1785 }
1786 cst = cst >> 16;
d744e06e 1787 case V8HImode:
ce1f50b2
HP
1788 if (EASY_VECTOR_15 (cst, vec, mode))
1789 {
1790 operands[1] = GEN_INT (cst);
1791 return "vspltish %0,%1";
1792 }
1793 cst = cst >> 8;
d744e06e 1794 case V16QImode:
ce1f50b2
HP
1795 if (EASY_VECTOR_15 (cst, vec, mode))
1796 {
1797 operands[1] = GEN_INT (cst);
1798 return "vspltisb %0,%1";
1799 }
d744e06e
AH
1800 default:
1801 abort ();
1802 }
98ef3137 1803 }
d744e06e
AH
1804 else
1805 abort ();
69ef87e2
AH
1806 }
1807
d744e06e
AH
1808 if (TARGET_SPE)
1809 {
1810 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1811 pattern of V1DI, V4HI, and V2SF.
1812
c1207243 1813 FIXME: We should probably return # and add post reload
d744e06e
AH
1814 splitters for these, but this way is so easy ;-).
1815 */
1816 operands[1] = GEN_INT (cst);
1817 operands[2] = GEN_INT (cst2);
1818 if (cst == cst2)
1819 return "li %0,%1\n\tevmergelo %0,%0,%0";
1820 else
1821 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1822 }
1823
1824 abort ();
69ef87e2
AH
1825}
1826
1827/* Return 1 if the operand is the constant 0. This works for scalars
1828 as well as vectors. */
1829int
a2369ed3 1830zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1831{
1832 return op == CONST0_RTX (mode);
1833}
1834
50a0b056
GK
1835/* Return 1 if the operand is 0.0. */
1836int
a2369ed3 1837zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1838{
1839 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1840}
1841
a4f6c312
SS
1842/* Return 1 if the operand is in volatile memory. Note that during
1843 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1844 volatile memory references. So this function allows us to
1845 recognize volatile references where its safe. */
1846
1847int
a2369ed3 1848volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1849{
1850 if (GET_CODE (op) != MEM)
1851 return 0;
1852
1853 if (!MEM_VOLATILE_P (op))
1854 return 0;
1855
1856 if (mode != GET_MODE (op))
1857 return 0;
1858
1859 if (reload_completed)
1860 return memory_operand (op, mode);
1861
1862 if (reload_in_progress)
1863 return strict_memory_address_p (mode, XEXP (op, 0));
1864
1865 return memory_address_p (mode, XEXP (op, 0));
1866}
1867
97f6e72f 1868/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1869
1870int
a2369ed3 1871offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1872{
97f6e72f 1873 return ((GET_CODE (op) == MEM)
677a9668 1874 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1875 mode, XEXP (op, 0)));
914c2e77
RK
1876}
1877
9878760c
RK
1878/* Return 1 if the operand is either an easy FP constant (see above) or
1879 memory. */
1880
1881int
a2369ed3 1882mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
1883{
1884 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1885}
1886
1887/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1888 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1889
1890int
a2369ed3 1891add_operand (rtx op, enum machine_mode mode)
9878760c 1892{
2bfcf297 1893 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1894 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1895 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1896
1897 return gpc_reg_operand (op, mode);
9878760c
RK
1898}
1899
dcfedcd0
RK
1900/* Return 1 if OP is a constant but not a valid add_operand. */
1901
1902int
a2369ed3 1903non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1904{
1905 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1906 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1907 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1908}
1909
9878760c
RK
1910/* Return 1 if the operand is a non-special register or a constant that
1911 can be used as the operand of an OR or XOR insn on the RS/6000. */
1912
1913int
a2369ed3 1914logical_operand (rtx op, enum machine_mode mode)
9878760c 1915{
40501e5f 1916 HOST_WIDE_INT opl, oph;
1d328b19 1917
dfbdccdb
GK
1918 if (gpc_reg_operand (op, mode))
1919 return 1;
1d328b19 1920
dfbdccdb 1921 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1922 {
1923 opl = INTVAL (op) & GET_MODE_MASK (mode);
1924
1925#if HOST_BITS_PER_WIDE_INT <= 32
1926 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1927 return 0;
1928#endif
1929 }
dfbdccdb
GK
1930 else if (GET_CODE (op) == CONST_DOUBLE)
1931 {
1d328b19 1932 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1933 abort ();
1d328b19
GK
1934
1935 opl = CONST_DOUBLE_LOW (op);
1936 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1937 if (oph != 0)
38886f37 1938 return 0;
dfbdccdb
GK
1939 }
1940 else
1941 return 0;
1d328b19 1942
40501e5f
AM
1943 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1944 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1945}
1946
dcfedcd0 1947/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1948 above), but could be split into one. */
dcfedcd0
RK
1949
1950int
a2369ed3 1951non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 1952{
dfbdccdb 1953 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1954 && ! logical_operand (op, mode)
1955 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1956}
1957
19ba8161 1958/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1959 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1960 Reject all ones and all zeros, since these should have been optimized
1961 away and confuse the making of MB and ME. */
1962
1963int
a2369ed3 1964mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1965{
02071907 1966 HOST_WIDE_INT c, lsb;
9878760c 1967
19ba8161
DE
1968 if (GET_CODE (op) != CONST_INT)
1969 return 0;
1970
1971 c = INTVAL (op);
1972
57deb3a1
AM
1973 /* Fail in 64-bit mode if the mask wraps around because the upper
1974 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1975 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1976 return 0;
1977
c5059423
AM
1978 /* We don't change the number of transitions by inverting,
1979 so make sure we start with the LS bit zero. */
1980 if (c & 1)
1981 c = ~c;
1982
1983 /* Reject all zeros or all ones. */
1984 if (c == 0)
9878760c
RK
1985 return 0;
1986
c5059423
AM
1987 /* Find the first transition. */
1988 lsb = c & -c;
1989
1990 /* Invert to look for a second transition. */
1991 c = ~c;
9878760c 1992
c5059423
AM
1993 /* Erase first transition. */
1994 c &= -lsb;
9878760c 1995
c5059423
AM
1996 /* Find the second transition (if any). */
1997 lsb = c & -c;
1998
1999 /* Match if all the bits above are 1's (or c is zero). */
2000 return c == -lsb;
9878760c
RK
2001}
2002
0ba1b2ff
AM
2003/* Return 1 for the PowerPC64 rlwinm corner case. */
2004
2005int
a2369ed3 2006mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2007{
2008 HOST_WIDE_INT c, lsb;
2009
2010 if (GET_CODE (op) != CONST_INT)
2011 return 0;
2012
2013 c = INTVAL (op);
2014
2015 if ((c & 0x80000001) != 0x80000001)
2016 return 0;
2017
2018 c = ~c;
2019 if (c == 0)
2020 return 0;
2021
2022 lsb = c & -c;
2023 c = ~c;
2024 c &= -lsb;
2025 lsb = c & -c;
2026 return c == -lsb;
2027}
2028
a260abc9
DE
2029/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2030 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2031 Reject all zeros, since zero should have been optimized away and
2032 confuses the making of MB and ME. */
9878760c
RK
2033
2034int
a2369ed3 2035mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2036{
2037 if (GET_CODE (op) == CONST_INT)
2038 {
02071907 2039 HOST_WIDE_INT c, lsb;
a260abc9 2040
c5059423 2041 c = INTVAL (op);
a260abc9 2042
0ba1b2ff 2043 /* Reject all zeros. */
c5059423 2044 if (c == 0)
e2c953b6
DE
2045 return 0;
2046
0ba1b2ff
AM
2047 /* We don't change the number of transitions by inverting,
2048 so make sure we start with the LS bit zero. */
2049 if (c & 1)
2050 c = ~c;
2051
c5059423
AM
2052 /* Find the transition, and check that all bits above are 1's. */
2053 lsb = c & -c;
e3981aab
DE
2054
2055 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2056 return c == -lsb;
e2c953b6 2057 }
0ba1b2ff
AM
2058 return 0;
2059}
2060
2061/* Like mask64_operand, but allow up to three transitions. This
2062 predicate is used by insn patterns that generate two rldicl or
2063 rldicr machine insns. */
2064
2065int
a2369ed3 2066mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2067{
2068 if (GET_CODE (op) == CONST_INT)
a260abc9 2069 {
0ba1b2ff 2070 HOST_WIDE_INT c, lsb;
a260abc9 2071
0ba1b2ff 2072 c = INTVAL (op);
a260abc9 2073
0ba1b2ff
AM
2074 /* Disallow all zeros. */
2075 if (c == 0)
2076 return 0;
a260abc9 2077
0ba1b2ff
AM
2078 /* We don't change the number of transitions by inverting,
2079 so make sure we start with the LS bit zero. */
2080 if (c & 1)
2081 c = ~c;
a260abc9 2082
0ba1b2ff
AM
2083 /* Find the first transition. */
2084 lsb = c & -c;
a260abc9 2085
0ba1b2ff
AM
2086 /* Invert to look for a second transition. */
2087 c = ~c;
2088
2089 /* Erase first transition. */
2090 c &= -lsb;
2091
2092 /* Find the second transition. */
2093 lsb = c & -c;
2094
2095 /* Invert to look for a third transition. */
2096 c = ~c;
2097
2098 /* Erase second transition. */
2099 c &= -lsb;
2100
2101 /* Find the third transition (if any). */
2102 lsb = c & -c;
2103
2104 /* Match if all the bits above are 1's (or c is zero). */
2105 return c == -lsb;
2106 }
2107 return 0;
2108}
2109
2110/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2111 implement ANDing by the mask IN. */
2112void
a2369ed3 2113build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2114{
2115#if HOST_BITS_PER_WIDE_INT >= 64
2116 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2117 int shift;
2118
2119 if (GET_CODE (in) != CONST_INT)
2120 abort ();
2121
2122 c = INTVAL (in);
2123 if (c & 1)
2124 {
2125 /* Assume c initially something like 0x00fff000000fffff. The idea
2126 is to rotate the word so that the middle ^^^^^^ group of zeros
2127 is at the MS end and can be cleared with an rldicl mask. We then
2128 rotate back and clear off the MS ^^ group of zeros with a
2129 second rldicl. */
2130 c = ~c; /* c == 0xff000ffffff00000 */
2131 lsb = c & -c; /* lsb == 0x0000000000100000 */
2132 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2133 c = ~c; /* c == 0x00fff000000fffff */
2134 c &= -lsb; /* c == 0x00fff00000000000 */
2135 lsb = c & -c; /* lsb == 0x0000100000000000 */
2136 c = ~c; /* c == 0xff000fffffffffff */
2137 c &= -lsb; /* c == 0xff00000000000000 */
2138 shift = 0;
2139 while ((lsb >>= 1) != 0)
2140 shift++; /* shift == 44 on exit from loop */
2141 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2142 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2143 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2144 }
2145 else
0ba1b2ff
AM
2146 {
2147 /* Assume c initially something like 0xff000f0000000000. The idea
2148 is to rotate the word so that the ^^^ middle group of zeros
2149 is at the LS end and can be cleared with an rldicr mask. We then
2150 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2151 a second rldicr. */
2152 lsb = c & -c; /* lsb == 0x0000010000000000 */
2153 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2154 c = ~c; /* c == 0x00fff0ffffffffff */
2155 c &= -lsb; /* c == 0x00fff00000000000 */
2156 lsb = c & -c; /* lsb == 0x0000100000000000 */
2157 c = ~c; /* c == 0xff000fffffffffff */
2158 c &= -lsb; /* c == 0xff00000000000000 */
2159 shift = 0;
2160 while ((lsb >>= 1) != 0)
2161 shift++; /* shift == 44 on exit from loop */
2162 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2163 m1 >>= shift; /* m1 == 0x0000000000000fff */
2164 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2165 }
2166
2167 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2168 masks will be all 1's. We are guaranteed more than one transition. */
2169 out[0] = GEN_INT (64 - shift);
2170 out[1] = GEN_INT (m1);
2171 out[2] = GEN_INT (shift);
2172 out[3] = GEN_INT (m2);
2173#else
045572c7
GK
2174 (void)in;
2175 (void)out;
0ba1b2ff
AM
2176 abort ();
2177#endif
a260abc9
DE
2178}
2179
2180/* Return 1 if the operand is either a non-special register or a constant
2181 that can be used as the operand of a PowerPC64 logical AND insn. */
2182
2183int
a2369ed3 2184and64_operand (rtx op, enum machine_mode mode)
9878760c 2185{
a4f6c312 2186 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2187 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2188
2189 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2190}
2191
0ba1b2ff
AM
2192/* Like the above, but also match constants that can be implemented
2193 with two rldicl or rldicr insns. */
2194
2195int
a2369ed3 2196and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2197{
a3c9585f 2198 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2199 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2200
2201 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2202}
2203
a260abc9
DE
2204/* Return 1 if the operand is either a non-special register or a
2205 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2206
2207int
a2369ed3 2208and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2209{
a4f6c312 2210 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2211 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2212
2213 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2214}
2215
9878760c
RK
2216/* Return 1 if the operand is a general register or memory operand. */
2217
2218int
a2369ed3 2219reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2220{
b6c9286a
MM
2221 return (gpc_reg_operand (op, mode)
2222 || memory_operand (op, mode)
4c81e946 2223 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2224 || volatile_mem_operand (op, mode));
9878760c
RK
2225}
2226
a7a813f7 2227/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2228 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2229 instruction. */
2230
2231int
a2369ed3 2232lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2233{
2234 rtx inner = op;
2235
2236 if (reload_completed && GET_CODE (inner) == SUBREG)
2237 inner = SUBREG_REG (inner);
2238
2239 return gpc_reg_operand (inner, mode)
2240 || (memory_operand (inner, mode)
2241 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2242 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2243 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2244 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2245 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2246}
2247
cc4d5fec
JH
2248/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2249
2250int
a2369ed3 2251symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2252{
2253 if (mode != VOIDmode && GET_MODE (op) != mode)
2254 return 0;
2255
473f51b6
DE
2256 return (GET_CODE (op) == SYMBOL_REF
2257 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2258}
2259
9878760c 2260/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2261 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2262
2263int
a2369ed3 2264call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2265{
2266 if (mode != VOIDmode && GET_MODE (op) != mode)
2267 return 0;
2268
2269 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2270 || (GET_CODE (op) == REG
2271 && (REGNO (op) == LINK_REGISTER_REGNUM
2272 || REGNO (op) == COUNT_REGISTER_REGNUM
2273 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2274}
2275
2af3d377 2276/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2277 this file. */
2af3d377
RK
2278
2279int
a2369ed3
DJ
2280current_file_function_operand (rtx op,
2281 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2282{
473f51b6
DE
2283 return (GET_CODE (op) == SYMBOL_REF
2284 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2285 && (SYMBOL_REF_LOCAL_P (op)
2286 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2287}
2288
9878760c
RK
2289/* Return 1 if this operand is a valid input for a move insn. */
2290
2291int
a2369ed3 2292input_operand (rtx op, enum machine_mode mode)
9878760c 2293{
eb4e8003 2294 /* Memory is always valid. */
9878760c
RK
2295 if (memory_operand (op, mode))
2296 return 1;
2297
34792e82 2298 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2299 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2300 return 1;
2301
eb4e8003
RK
2302 /* For floating-point, easy constants are valid. */
2303 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2304 && CONSTANT_P (op)
2305 && easy_fp_constant (op, mode))
2306 return 1;
2307
4e74d8ec
MM
2308 /* Allow any integer constant. */
2309 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2310 && (GET_CODE (op) == CONST_INT
e675f625 2311 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2312 return 1;
2313
d744e06e
AH
2314 /* Allow easy vector constants. */
2315 if (GET_CODE (op) == CONST_VECTOR
2316 && easy_vector_constant (op, mode))
2317 return 1;
2318
eb4e8003
RK
2319 /* For floating-point or multi-word mode, the only remaining valid type
2320 is a register. */
9878760c
RK
2321 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2322 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2323 return register_operand (op, mode);
9878760c 2324
88fe15a1
RK
2325 /* The only cases left are integral modes one word or smaller (we
2326 do not get called for MODE_CC values). These can be in any
2327 register. */
2328 if (register_operand (op, mode))
a8b3aeda 2329 return 1;
88fe15a1 2330
84cf9dda 2331 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2332 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2333 return 1;
2334
9ebbca7d 2335 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2336 if (toc_relative_expr_p (op))
b6c9286a
MM
2337 return 1;
2338
88228c4b
MM
2339 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2340 to be valid. */
f607bc57 2341 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2342 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2343 && small_data_operand (op, Pmode))
2344 return 1;
2345
042259f2 2346 return 0;
9878760c 2347}
7509c759 2348
95727fb8
AP
2349
2350/* Darwin, AIX increases natural record alignment to doubleword if the first
2351 field is an FP double while the FP fields remain word aligned. */
2352
19d66194 2353unsigned int
95727fb8
AP
2354rs6000_special_round_type_align (tree type, int computed, int specified)
2355{
2356 tree field = TYPE_FIELDS (type);
95727fb8
AP
2357
2358 /* Skip all the static variables only if ABI is greater than
71cc389b 2359 1 or equal to 0. */
3ce5437a 2360 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2361 field = TREE_CHAIN (field);
2362
3ce5437a 2363 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2364 return MAX (computed, specified);
2365
2366 return MAX (MAX (computed, specified), 64);
2367}
2368
a4f6c312 2369/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2370
2371int
a2369ed3
DJ
2372small_data_operand (rtx op ATTRIBUTE_UNUSED,
2373 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2374{
38c1f2d7 2375#if TARGET_ELF
5f59ecb7 2376 rtx sym_ref;
7509c759 2377
d9407988 2378 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2379 return 0;
a54d04b7 2380
f607bc57 2381 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2382 return 0;
2383
88228c4b
MM
2384 if (GET_CODE (op) == SYMBOL_REF)
2385 sym_ref = op;
2386
2387 else if (GET_CODE (op) != CONST
2388 || GET_CODE (XEXP (op, 0)) != PLUS
2389 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2390 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2391 return 0;
2392
88228c4b 2393 else
dbf55e53
MM
2394 {
2395 rtx sum = XEXP (op, 0);
2396 HOST_WIDE_INT summand;
2397
2398 /* We have to be careful here, because it is the referenced address
2399 that must be 32k from _SDA_BASE_, not just the symbol. */
2400 summand = INTVAL (XEXP (sum, 1));
307b599c 2401 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2402 return 0;
2403
2404 sym_ref = XEXP (sum, 0);
2405 }
88228c4b 2406
20bfcd69 2407 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2408#else
2409 return 0;
2410#endif
7509c759 2411}
46c07df8 2412
d2288d5d
HP
2413/* Return true, if operand is a memory operand and has a
2414 displacement divisible by 4. */
2415
2416int
2417word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2418{
2419 rtx addr;
2420 int off = 0;
2421
2422 if (!memory_operand (op, mode))
2423 return 0;
2424
2425 addr = XEXP (op, 0);
2426 if (GET_CODE (addr) == PLUS
2427 && GET_CODE (XEXP (addr, 0)) == REG
2428 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2429 off = INTVAL (XEXP (addr, 1));
2430
2431 return (off % 4) == 0;
2432}
2433
3a1f863f 2434/* Return true if either operand is a general purpose register. */
46c07df8 2435
3a1f863f
DE
2436bool
2437gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2438{
3a1f863f
DE
2439 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2440 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2441}
2442
9ebbca7d 2443\f
4d588c14
RH
2444/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2445
9ebbca7d 2446static int
a2369ed3 2447constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2448{
2449 switch (GET_CODE(op))
2450 {
2451 case SYMBOL_REF:
c4501e62
JJ
2452 if (RS6000_SYMBOL_REF_TLS_P (op))
2453 return 0;
2454 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2455 {
2456 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2457 {
2458 *have_sym = 1;
2459 return 1;
2460 }
2461 else
2462 return 0;
2463 }
2464 else if (! strcmp (XSTR (op, 0), toc_label_name))
2465 {
2466 *have_toc = 1;
2467 return 1;
2468 }
2469 else
2470 return 0;
9ebbca7d
GK
2471 case PLUS:
2472 case MINUS:
c1f11548
DE
2473 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2474 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2475 case CONST:
a4f6c312 2476 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2477 case CONST_INT:
a4f6c312 2478 return 1;
9ebbca7d 2479 default:
a4f6c312 2480 return 0;
9ebbca7d
GK
2481 }
2482}
2483
4d588c14 2484static bool
a2369ed3 2485constant_pool_expr_p (rtx op)
9ebbca7d
GK
2486{
2487 int have_sym = 0;
2488 int have_toc = 0;
2489 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2490}
2491
4d588c14 2492static bool
a2369ed3 2493toc_relative_expr_p (rtx op)
9ebbca7d 2494{
4d588c14
RH
2495 int have_sym = 0;
2496 int have_toc = 0;
2497 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2498}
2499
2500/* SPE offset addressing is limited to 5-bits worth of double words. */
2501#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2502
2503bool
a2369ed3 2504legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2505{
2506 return (TARGET_TOC
2507 && GET_CODE (x) == PLUS
2508 && GET_CODE (XEXP (x, 0)) == REG
2509 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2510 && constant_pool_expr_p (XEXP (x, 1)));
2511}
2512
2513static bool
a2369ed3 2514legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2515{
2516 return (DEFAULT_ABI == ABI_V4
2517 && !flag_pic && !TARGET_TOC
2518 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2519 && small_data_operand (x, mode));
2520}
2521
2522static bool
a2369ed3 2523legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2524{
2525 unsigned HOST_WIDE_INT offset, extra;
2526
2527 if (GET_CODE (x) != PLUS)
2528 return false;
2529 if (GET_CODE (XEXP (x, 0)) != REG)
2530 return false;
2531 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2532 return false;
2533 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2534 return false;
2535
2536 offset = INTVAL (XEXP (x, 1));
2537 extra = 0;
2538 switch (mode)
2539 {
2540 case V16QImode:
2541 case V8HImode:
2542 case V4SFmode:
2543 case V4SImode:
2544 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2545 which leaves the only valid constant offset of zero, which by
2546 canonicalization rules is also invalid. */
2547 return false;
2548
2549 case V4HImode:
2550 case V2SImode:
2551 case V1DImode:
2552 case V2SFmode:
2553 /* SPE vector modes. */
2554 return SPE_CONST_OFFSET_OK (offset);
2555
2556 case DFmode:
2557 case DImode:
3364872d 2558 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2559 extra = 4;
2560 else if (offset & 3)
2561 return false;
2562 break;
2563
2564 case TFmode:
2565 case TImode:
3364872d 2566 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2567 extra = 12;
2568 else if (offset & 3)
2569 return false;
2570 else
2571 extra = 8;
2572 break;
2573
2574 default:
2575 break;
2576 }
2577
b1917422
AM
2578 offset += 0x8000;
2579 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
2580}
2581
2582static bool
a2369ed3 2583legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2584{
2585 rtx op0, op1;
2586
2587 if (GET_CODE (x) != PLUS)
2588 return false;
2589 op0 = XEXP (x, 0);
2590 op1 = XEXP (x, 1);
2591
2592 if (!REG_P (op0) || !REG_P (op1))
2593 return false;
2594
2595 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2596 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2597 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2598 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2599}
2600
4d588c14 2601static inline bool
a2369ed3 2602legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2603{
2604 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2605}
2606
4c81e946
FJ
2607static bool
2608macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2609{
2610 if (!TARGET_MACHO || !flag_pic
2611 || mode != SImode || GET_CODE(x) != MEM)
2612 return false;
2613 x = XEXP (x, 0);
2614
2615 if (GET_CODE (x) != LO_SUM)
2616 return false;
2617 if (GET_CODE (XEXP (x, 0)) != REG)
2618 return false;
2619 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2620 return false;
2621 x = XEXP (x, 1);
2622
2623 return CONSTANT_P (x);
2624}
2625
4d588c14 2626static bool
a2369ed3 2627legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2628{
2629 if (GET_CODE (x) != LO_SUM)
2630 return false;
2631 if (GET_CODE (XEXP (x, 0)) != REG)
2632 return false;
2633 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2634 return false;
2635 x = XEXP (x, 1);
2636
8622e235 2637 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2638 {
a29077da 2639 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2640 return false;
2641 if (TARGET_TOC)
2642 return false;
2643 if (GET_MODE_NUNITS (mode) != 1)
2644 return false;
2645 if (GET_MODE_BITSIZE (mode) > 32
2646 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2647 return false;
2648
2649 return CONSTANT_P (x);
2650 }
2651
2652 return false;
2653}
2654
2655
9ebbca7d
GK
2656/* Try machine-dependent ways of modifying an illegitimate address
2657 to be legitimate. If we find one, return the new, valid address.
2658 This is used from only one place: `memory_address' in explow.c.
2659
a4f6c312
SS
2660 OLDX is the address as it was before break_out_memory_refs was
2661 called. In some cases it is useful to look at this to decide what
2662 needs to be done.
9ebbca7d 2663
a4f6c312 2664 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2665
a4f6c312
SS
2666 It is always safe for this function to do nothing. It exists to
2667 recognize opportunities to optimize the output.
9ebbca7d
GK
2668
2669 On RS/6000, first check for the sum of a register with a constant
2670 integer that is out of range. If so, generate code to add the
2671 constant with the low-order 16 bits masked to the register and force
2672 this result into another register (this can be done with `cau').
2673 Then generate an address of REG+(CONST&0xffff), allowing for the
2674 possibility of bit 16 being a one.
2675
2676 Then check for the sum of a register and something not constant, try to
2677 load the other things into a register and return the sum. */
4d588c14 2678
9ebbca7d 2679rtx
a2369ed3
DJ
2680rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2681 enum machine_mode mode)
0ac081f6 2682{
c4501e62
JJ
2683 if (GET_CODE (x) == SYMBOL_REF)
2684 {
2685 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2686 if (model != 0)
2687 return rs6000_legitimize_tls_address (x, model);
2688 }
2689
9ebbca7d
GK
2690 if (GET_CODE (x) == PLUS
2691 && GET_CODE (XEXP (x, 0)) == REG
2692 && GET_CODE (XEXP (x, 1)) == CONST_INT
2693 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2694 {
2695 HOST_WIDE_INT high_int, low_int;
2696 rtx sum;
a65c591c
DE
2697 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2698 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2699 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2700 GEN_INT (high_int)), 0);
2701 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2702 }
2703 else if (GET_CODE (x) == PLUS
2704 && GET_CODE (XEXP (x, 0)) == REG
2705 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2706 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2707 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2708 || TARGET_POWERPC64
fcce224d 2709 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2710 && (TARGET_POWERPC64 || mode != DImode)
2711 && mode != TImode)
2712 {
2713 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2714 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2715 }
0ac081f6
AH
2716 else if (ALTIVEC_VECTOR_MODE (mode))
2717 {
2718 rtx reg;
2719
2720 /* Make sure both operands are registers. */
2721 if (GET_CODE (x) == PLUS)
9f85ed45 2722 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2723 force_reg (Pmode, XEXP (x, 1)));
2724
2725 reg = force_reg (Pmode, x);
2726 return reg;
2727 }
a3170dc6
AH
2728 else if (SPE_VECTOR_MODE (mode))
2729 {
2730 /* We accept [reg + reg] and [reg + OFFSET]. */
2731
2732 if (GET_CODE (x) == PLUS)
2733 {
2734 rtx op1 = XEXP (x, 0);
2735 rtx op2 = XEXP (x, 1);
2736
2737 op1 = force_reg (Pmode, op1);
2738
2739 if (GET_CODE (op2) != REG
2740 && (GET_CODE (op2) != CONST_INT
2741 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2742 op2 = force_reg (Pmode, op2);
2743
2744 return gen_rtx_PLUS (Pmode, op1, op2);
2745 }
2746
2747 return force_reg (Pmode, x);
2748 }
f1384257
AM
2749 else if (TARGET_ELF
2750 && TARGET_32BIT
2751 && TARGET_NO_TOC
2752 && ! flag_pic
9ebbca7d
GK
2753 && GET_CODE (x) != CONST_INT
2754 && GET_CODE (x) != CONST_DOUBLE
2755 && CONSTANT_P (x)
6ac7bf2c
GK
2756 && GET_MODE_NUNITS (mode) == 1
2757 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2758 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2759 {
2760 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2761 emit_insn (gen_elf_high (reg, x));
2762 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2763 }
ee890fe2
SS
2764 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2765 && ! flag_pic
ab82a49f
AP
2766#if TARGET_MACHO
2767 && ! MACHO_DYNAMIC_NO_PIC_P
2768#endif
ee890fe2
SS
2769 && GET_CODE (x) != CONST_INT
2770 && GET_CODE (x) != CONST_DOUBLE
2771 && CONSTANT_P (x)
a3170dc6 2772 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2773 && mode != DImode
2774 && mode != TImode)
2775 {
2776 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2777 emit_insn (gen_macho_high (reg, x));
2778 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2779 }
9ebbca7d 2780 else if (TARGET_TOC
4d588c14 2781 && constant_pool_expr_p (x)
a9098fd0 2782 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2783 {
2784 return create_TOC_reference (x);
2785 }
2786 else
2787 return NULL_RTX;
2788}
258bfae2 2789
c973d557
JJ
2790/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
2791 We need to emit DTP-relative relocations. */
2792
2793void
2794rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2795{
2796 switch (size)
2797 {
2798 case 4:
2799 fputs ("\t.long\t", file);
2800 break;
2801 case 8:
2802 fputs (DOUBLE_INT_ASM_OP, file);
2803 break;
2804 default:
2805 abort ();
2806 }
2807 output_addr_const (file, x);
2808 fputs ("@dtprel+0x8000", file);
2809}
2810
c4501e62
JJ
2811/* Construct the SYMBOL_REF for the tls_get_addr function. */
2812
2813static GTY(()) rtx rs6000_tls_symbol;
2814static rtx
863d938c 2815rs6000_tls_get_addr (void)
c4501e62
JJ
2816{
2817 if (!rs6000_tls_symbol)
2818 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2819
2820 return rs6000_tls_symbol;
2821}
2822
2823/* Construct the SYMBOL_REF for TLS GOT references. */
2824
2825static GTY(()) rtx rs6000_got_symbol;
2826static rtx
863d938c 2827rs6000_got_sym (void)
c4501e62
JJ
2828{
2829 if (!rs6000_got_symbol)
2830 {
2831 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2832 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2833 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2834 }
2835
2836 return rs6000_got_symbol;
2837}
2838
2839/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2840 this (thread-local) address. */
2841
2842static rtx
a2369ed3 2843rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2844{
2845 rtx dest, insn;
2846
2847 dest = gen_reg_rtx (Pmode);
2848 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2849 {
2850 rtx tlsreg;
2851
2852 if (TARGET_64BIT)
2853 {
2854 tlsreg = gen_rtx_REG (Pmode, 13);
2855 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2856 }
2857 else
2858 {
2859 tlsreg = gen_rtx_REG (Pmode, 2);
2860 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2861 }
2862 emit_insn (insn);
2863 }
2864 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2865 {
2866 rtx tlsreg, tmp;
2867
2868 tmp = gen_reg_rtx (Pmode);
2869 if (TARGET_64BIT)
2870 {
2871 tlsreg = gen_rtx_REG (Pmode, 13);
2872 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2873 }
2874 else
2875 {
2876 tlsreg = gen_rtx_REG (Pmode, 2);
2877 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2878 }
2879 emit_insn (insn);
2880 if (TARGET_64BIT)
2881 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2882 else
2883 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2884 emit_insn (insn);
2885 }
2886 else
2887 {
2888 rtx r3, got, tga, tmp1, tmp2, eqv;
2889
2890 if (TARGET_64BIT)
2891 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2892 else
2893 {
2894 if (flag_pic == 1)
2895 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2896 else
2897 {
2898 rtx gsym = rs6000_got_sym ();
2899 got = gen_reg_rtx (Pmode);
2900 if (flag_pic == 0)
2901 rs6000_emit_move (got, gsym, Pmode);
2902 else
2903 {
2904 char buf[30];
2905 static int tls_got_labelno = 0;
2906 rtx tempLR, lab, tmp3, mem;
2907 rtx first, last;
2908
2909 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2910 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2911 tempLR = gen_reg_rtx (Pmode);
2912 tmp1 = gen_reg_rtx (Pmode);
2913 tmp2 = gen_reg_rtx (Pmode);
2914 tmp3 = gen_reg_rtx (Pmode);
2915 mem = gen_rtx_MEM (Pmode, tmp1);
2916 RTX_UNCHANGING_P (mem) = 1;
2917
2918 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2919 gsym));
2920 emit_move_insn (tmp1, tempLR);
2921 emit_move_insn (tmp2, mem);
2922 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2923 last = emit_move_insn (got, tmp3);
2924 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2925 REG_NOTES (last));
2926 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2927 REG_NOTES (first));
2928 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2929 REG_NOTES (last));
2930 }
2931 }
2932 }
2933
2934 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2935 {
2936 r3 = gen_rtx_REG (Pmode, 3);
2937 if (TARGET_64BIT)
2938 insn = gen_tls_gd_64 (r3, got, addr);
2939 else
2940 insn = gen_tls_gd_32 (r3, got, addr);
2941 start_sequence ();
2942 emit_insn (insn);
2943 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2944 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2945 insn = emit_call_insn (insn);
2946 CONST_OR_PURE_CALL_P (insn) = 1;
2947 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2948 insn = get_insns ();
2949 end_sequence ();
2950 emit_libcall_block (insn, dest, r3, addr);
2951 }
2952 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2953 {
2954 r3 = gen_rtx_REG (Pmode, 3);
2955 if (TARGET_64BIT)
2956 insn = gen_tls_ld_64 (r3, got);
2957 else
2958 insn = gen_tls_ld_32 (r3, got);
2959 start_sequence ();
2960 emit_insn (insn);
2961 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2962 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2963 insn = emit_call_insn (insn);
2964 CONST_OR_PURE_CALL_P (insn) = 1;
2965 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2966 insn = get_insns ();
2967 end_sequence ();
2968 tmp1 = gen_reg_rtx (Pmode);
2969 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2970 UNSPEC_TLSLD);
2971 emit_libcall_block (insn, tmp1, r3, eqv);
2972 if (rs6000_tls_size == 16)
2973 {
2974 if (TARGET_64BIT)
2975 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
2976 else
2977 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
2978 }
2979 else if (rs6000_tls_size == 32)
2980 {
2981 tmp2 = gen_reg_rtx (Pmode);
2982 if (TARGET_64BIT)
2983 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
2984 else
2985 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
2986 emit_insn (insn);
2987 if (TARGET_64BIT)
2988 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
2989 else
2990 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
2991 }
2992 else
2993 {
2994 tmp2 = gen_reg_rtx (Pmode);
2995 if (TARGET_64BIT)
2996 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
2997 else
2998 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
2999 emit_insn (insn);
3000 insn = gen_rtx_SET (Pmode, dest,
3001 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3002 }
3003 emit_insn (insn);
3004 }
3005 else
3006 {
3007 /* IE, or 64 bit offset LE. */
3008 tmp2 = gen_reg_rtx (Pmode);
3009 if (TARGET_64BIT)
3010 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3011 else
3012 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3013 emit_insn (insn);
3014 if (TARGET_64BIT)
3015 insn = gen_tls_tls_64 (dest, tmp2, addr);
3016 else
3017 insn = gen_tls_tls_32 (dest, tmp2, addr);
3018 emit_insn (insn);
3019 }
3020 }
3021
3022 return dest;
3023}
3024
3025/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3026 instruction definitions. */
3027
3028int
a2369ed3 3029rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3030{
3031 return RS6000_SYMBOL_REF_TLS_P (x);
3032}
3033
3034/* Return 1 if X contains a thread-local symbol. */
3035
3036bool
a2369ed3 3037rs6000_tls_referenced_p (rtx x)
c4501e62 3038{
cd413cab
AP
3039 if (! TARGET_HAVE_TLS)
3040 return false;
3041
c4501e62
JJ
3042 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3043}
3044
3045/* Return 1 if *X is a thread-local symbol. This is the same as
3046 rs6000_tls_symbol_ref except for the type of the unused argument. */
3047
3048static inline int
a2369ed3 3049rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3050{
3051 return RS6000_SYMBOL_REF_TLS_P (*x);
3052}
3053
24ea750e
DJ
3054/* The convention appears to be to define this wherever it is used.
3055 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3056 is now used here. */
3057#ifndef REG_MODE_OK_FOR_BASE_P
3058#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3059#endif
3060
3061/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3062 replace the input X, or the original X if no replacement is called for.
3063 The output parameter *WIN is 1 if the calling macro should goto WIN,
3064 0 if it should not.
3065
3066 For RS/6000, we wish to handle large displacements off a base
3067 register by splitting the addend across an addiu/addis and the mem insn.
3068 This cuts number of extra insns needed from 3 to 1.
3069
3070 On Darwin, we use this to generate code for floating point constants.
3071 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3072 The Darwin code is inside #if TARGET_MACHO because only then is
3073 machopic_function_base_name() defined. */
3074rtx
a2369ed3
DJ
3075rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3076 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3077{
3078 /* We must recognize output that we have already generated ourselves. */
3079 if (GET_CODE (x) == PLUS
3080 && GET_CODE (XEXP (x, 0)) == PLUS
3081 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3082 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3083 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3084 {
3085 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3086 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3087 opnum, (enum reload_type)type);
3088 *win = 1;
3089 return x;
3090 }
3deb2758 3091
24ea750e
DJ
3092#if TARGET_MACHO
3093 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3094 && GET_CODE (x) == LO_SUM
3095 && GET_CODE (XEXP (x, 0)) == PLUS
3096 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3097 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3098 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3099 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3100 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3101 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3102 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3103 {
3104 /* Result of previous invocation of this function on Darwin
6f317ef3 3105 floating point constant. */
24ea750e
DJ
3106 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3107 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3108 opnum, (enum reload_type)type);
3109 *win = 1;
3110 return x;
3111 }
3112#endif
3113 if (GET_CODE (x) == PLUS
3114 && GET_CODE (XEXP (x, 0)) == REG
3115 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3116 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3117 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3118 && !SPE_VECTOR_MODE (mode)
78c875e8 3119 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3120 {
3121 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3122 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3123 HOST_WIDE_INT high
3124 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3125
3126 /* Check for 32-bit overflow. */
3127 if (high + low != val)
3128 {
3129 *win = 0;
3130 return x;
3131 }
3132
3133 /* Reload the high part into a base reg; leave the low part
3134 in the mem directly. */
3135
3136 x = gen_rtx_PLUS (GET_MODE (x),
3137 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3138 GEN_INT (high)),
3139 GEN_INT (low));
3140
3141 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3142 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3143 opnum, (enum reload_type)type);
3144 *win = 1;
3145 return x;
3146 }
3147#if TARGET_MACHO
3148 if (GET_CODE (x) == SYMBOL_REF
3149 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3150 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3151 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3152 /* Don't do this for TFmode, since the result isn't offsettable. */
3153 && mode != TFmode)
24ea750e 3154 {
a29077da
GK
3155 if (flag_pic)
3156 {
3157 rtx offset = gen_rtx_CONST (Pmode,
3158 gen_rtx_MINUS (Pmode, x,
3159 gen_rtx_SYMBOL_REF (Pmode,
3160 machopic_function_base_name ())));
3161 x = gen_rtx_LO_SUM (GET_MODE (x),
3162 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3163 gen_rtx_HIGH (Pmode, offset)), offset);
3164 }
3165 else
3166 x = gen_rtx_LO_SUM (GET_MODE (x),
3167 gen_rtx_HIGH (Pmode, x), x);
3168
24ea750e 3169 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3170 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3171 opnum, (enum reload_type)type);
24ea750e
DJ
3172 *win = 1;
3173 return x;
3174 }
3175#endif
3176 if (TARGET_TOC
4d588c14 3177 && constant_pool_expr_p (x)
c1f11548 3178 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3179 {
3180 (x) = create_TOC_reference (x);
3181 *win = 1;
3182 return x;
3183 }
3184 *win = 0;
3185 return x;
3186}
3187
258bfae2
FS
3188/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3189 that is a valid memory address for an instruction.
3190 The MODE argument is the machine mode for the MEM expression
3191 that wants to use this address.
3192
3193 On the RS/6000, there are four valid address: a SYMBOL_REF that
3194 refers to a constant pool entry of an address (or the sum of it
3195 plus a constant), a short (16-bit signed) constant plus a register,
3196 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3197 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3198 we must ensure that both words are addressable or PowerPC64 with offset
3199 word aligned.
3200
3201 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3202 32-bit DImode, TImode), indexed addressing cannot be used because
3203 adjacent memory cells are accessed by adding word-sized offsets
3204 during assembly output. */
3205int
a2369ed3 3206rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3207{
c4501e62
JJ
3208 if (RS6000_SYMBOL_REF_TLS_P (x))
3209 return 0;
4d588c14 3210 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3211 return 1;
3212 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3213 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3214 && !SPE_VECTOR_MODE (mode)
258bfae2 3215 && TARGET_UPDATE
4d588c14 3216 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3217 return 1;
4d588c14 3218 if (legitimate_small_data_p (mode, x))
258bfae2 3219 return 1;
4d588c14 3220 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3221 return 1;
3222 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3223 if (! reg_ok_strict
3224 && GET_CODE (x) == PLUS
3225 && GET_CODE (XEXP (x, 0)) == REG
3226 && XEXP (x, 0) == virtual_stack_vars_rtx
3227 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3228 return 1;
4d588c14 3229 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3230 return 1;
3231 if (mode != TImode
a3170dc6
AH
3232 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3233 || TARGET_POWERPC64
fcce224d 3234 || (mode != DFmode && mode != TFmode))
258bfae2 3235 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3236 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3237 return 1;
4d588c14 3238 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3239 return 1;
3240 return 0;
3241}
4d588c14
RH
3242
3243/* Go to LABEL if ADDR (a legitimate address expression)
3244 has an effect that depends on the machine mode it is used for.
3245
3246 On the RS/6000 this is true of all integral offsets (since AltiVec
3247 modes don't allow them) or is a pre-increment or decrement.
3248
3249 ??? Except that due to conceptual problems in offsettable_address_p
3250 we can't really report the problems of integral offsets. So leave
3251 this assuming that the adjustable offset must be valid for the
3252 sub-words of a TFmode operand, which is what we had before. */
3253
3254bool
a2369ed3 3255rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3256{
3257 switch (GET_CODE (addr))
3258 {
3259 case PLUS:
3260 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3261 {
3262 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3263 return val + 12 + 0x8000 >= 0x10000;
3264 }
3265 break;
3266
3267 case LO_SUM:
3268 return true;
3269
3270 case PRE_INC:
3271 case PRE_DEC:
3272 return TARGET_UPDATE;
3273
3274 default:
3275 break;
3276 }
3277
3278 return false;
3279}
fb4d4348 3280\f
a4f6c312
SS
3281/* Try to output insns to set TARGET equal to the constant C if it can
3282 be done in less than N insns. Do all computations in MODE.
3283 Returns the place where the output has been placed if it can be
3284 done and the insns have been emitted. If it would take more than N
3285 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3286
3287rtx
a2369ed3
DJ
3288rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3289 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3290{
af8cb5c5 3291 rtx result, insn, set;
2bfcf297
DB
3292 HOST_WIDE_INT c0, c1;
3293
af8cb5c5 3294 if (mode == QImode || mode == HImode)
2bfcf297
DB
3295 {
3296 if (dest == NULL)
3297 dest = gen_reg_rtx (mode);
3298 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3299 return dest;
3300 }
af8cb5c5 3301 else if (mode == SImode)
2bfcf297 3302 {
af8cb5c5
DE
3303 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3304
3305 emit_insn (gen_rtx_SET (VOIDmode, result,
3306 GEN_INT (INTVAL (source)
3307 & (~ (HOST_WIDE_INT) 0xffff))));
3308 emit_insn (gen_rtx_SET (VOIDmode, dest,
3309 gen_rtx_IOR (SImode, result,
3310 GEN_INT (INTVAL (source) & 0xffff))));
3311 result = dest;
2bfcf297 3312 }
af8cb5c5 3313 else if (mode == DImode)
2bfcf297 3314 {
af8cb5c5
DE
3315 if (GET_CODE (source) == CONST_INT)
3316 {
3317 c0 = INTVAL (source);
3318 c1 = -(c0 < 0);
3319 }
3320 else if (GET_CODE (source) == CONST_DOUBLE)
3321 {
2bfcf297 3322#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3323 c0 = CONST_DOUBLE_LOW (source);
3324 c1 = -(c0 < 0);
2bfcf297 3325#else
af8cb5c5
DE
3326 c0 = CONST_DOUBLE_LOW (source);
3327 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3328#endif
af8cb5c5
DE
3329 }
3330 else
3331 abort ();
3332
3333 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3334 }
3335 else
a4f6c312 3336 abort ();
2bfcf297 3337
af8cb5c5
DE
3338 insn = get_last_insn ();
3339 set = single_set (insn);
3340 if (! CONSTANT_P (SET_SRC (set)))
3341 set_unique_reg_note (insn, REG_EQUAL, source);
3342
3343 return result;
2bfcf297
DB
3344}
3345
3346/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3347 fall back to a straight forward decomposition. We do this to avoid
3348 exponential run times encountered when looking for longer sequences
3349 with rs6000_emit_set_const. */
3350static rtx
a2369ed3 3351rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3352{
3353 if (!TARGET_POWERPC64)
3354 {
3355 rtx operand1, operand2;
3356
3357 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3358 DImode);
3359 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3360 DImode);
3361 emit_move_insn (operand1, GEN_INT (c1));
3362 emit_move_insn (operand2, GEN_INT (c2));
3363 }
3364 else
3365 {
bc06712d 3366 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3367
bc06712d 3368 ud1 = c1 & 0xffff;
f921c9c9 3369 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3370#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3371 c2 = c1 >> 32;
2bfcf297 3372#endif
bc06712d 3373 ud3 = c2 & 0xffff;
f921c9c9 3374 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3375
bc06712d
TR
3376 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3377 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3378 {
bc06712d 3379 if (ud1 & 0x8000)
b78d48dd 3380 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3381 else
3382 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3383 }
2bfcf297 3384
bc06712d
TR
3385 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3386 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3387 {
bc06712d
TR
3388 if (ud2 & 0x8000)
3389 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3390 - 0x80000000));
252b88f7 3391 else
bc06712d
TR
3392 emit_move_insn (dest, GEN_INT (ud2 << 16));
3393 if (ud1 != 0)
3394 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3395 }
bc06712d
TR
3396 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3397 || (ud4 == 0 && ! (ud3 & 0x8000)))
3398 {
3399 if (ud3 & 0x8000)
3400 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3401 - 0x80000000));
3402 else
3403 emit_move_insn (dest, GEN_INT (ud3 << 16));
3404
3405 if (ud2 != 0)
3406 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3407 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3408 if (ud1 != 0)
3409 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3410 }
3411 else
3412 {
3413 if (ud4 & 0x8000)
3414 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3415 - 0x80000000));
3416 else
3417 emit_move_insn (dest, GEN_INT (ud4 << 16));
3418
3419 if (ud3 != 0)
3420 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3421
bc06712d
TR
3422 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3423 if (ud2 != 0)
3424 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3425 GEN_INT (ud2 << 16)));
3426 if (ud1 != 0)
3427 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3428 }
3429 }
2bfcf297
DB
3430 return dest;
3431}
3432
fb4d4348
GK
3433/* Emit a move from SOURCE to DEST in mode MODE. */
3434void
a2369ed3 3435rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3436{
3437 rtx operands[2];
3438 operands[0] = dest;
3439 operands[1] = source;
3440
3441 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3442 if (GET_CODE (operands[1]) == CONST_DOUBLE
3443 && ! FLOAT_MODE_P (mode)
3444 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3445 {
3446 /* FIXME. This should never happen. */
3447 /* Since it seems that it does, do the safe thing and convert
3448 to a CONST_INT. */
2496c7bd 3449 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3450 }
3451 if (GET_CODE (operands[1]) == CONST_DOUBLE
3452 && ! FLOAT_MODE_P (mode)
3453 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3454 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3455 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3456 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3457 abort ();
c9e8cb32
DD
3458
3459 /* Check if GCC is setting up a block move that will end up using FP
3460 registers as temporaries. We must make sure this is acceptable. */
3461 if (GET_CODE (operands[0]) == MEM
3462 && GET_CODE (operands[1]) == MEM
3463 && mode == DImode
41543739
GK
3464 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3465 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3466 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3467 ? 32 : MEM_ALIGN (operands[0])))
3468 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3469 ? 32
3470 : MEM_ALIGN (operands[1]))))
3471 && ! MEM_VOLATILE_P (operands [0])
3472 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3473 {
41543739
GK
3474 emit_move_insn (adjust_address (operands[0], SImode, 0),
3475 adjust_address (operands[1], SImode, 0));
3476 emit_move_insn (adjust_address (operands[0], SImode, 4),
3477 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3478 return;
3479 }
630d42a0 3480
67cef334
DE
3481 if (!no_new_pseudos)
3482 {
3483 if (GET_CODE (operands[1]) == MEM && optimize > 0
3484 && (mode == QImode || mode == HImode || mode == SImode)
3485 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3486 {
3487 rtx reg = gen_reg_rtx (word_mode);
3488
3489 emit_insn (gen_rtx_SET (word_mode, reg,
3490 gen_rtx_ZERO_EXTEND (word_mode,
3491 operands[1])));
3492 operands[1] = gen_lowpart (mode, reg);
3493 }
3494 if (GET_CODE (operands[0]) != REG)
3495 operands[1] = force_reg (mode, operands[1]);
3496 }
a9098fd0 3497
a3170dc6
AH
3498 if (mode == SFmode && ! TARGET_POWERPC
3499 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3500 && GET_CODE (operands[0]) == MEM)
fb4d4348 3501 {
ffc14f31
GK
3502 int regnum;
3503
3504 if (reload_in_progress || reload_completed)
3505 regnum = true_regnum (operands[1]);
3506 else if (GET_CODE (operands[1]) == REG)
3507 regnum = REGNO (operands[1]);
3508 else
3509 regnum = -1;
fb4d4348
GK
3510
3511 /* If operands[1] is a register, on POWER it may have
3512 double-precision data in it, so truncate it to single
3513 precision. */
3514 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3515 {
3516 rtx newreg;
3517 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3518 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3519 operands[1] = newreg;
3520 }
3521 }
3522
c4501e62
JJ
3523 /* Recognize the case where operand[1] is a reference to thread-local
3524 data and load its address to a register. */
3525 if (GET_CODE (operands[1]) == SYMBOL_REF)
3526 {
3527 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3528 if (model != 0)
3529 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3530 }
3531
8f4e6caf
RH
3532 /* Handle the case where reload calls us with an invalid address. */
3533 if (reload_in_progress && mode == Pmode
69ef87e2 3534 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3535 || ! nonimmediate_operand (operands[0], mode)))
3536 goto emit_set;
3537
3538 /* Handle the case of CONSTANT_P_RTX. */
3539 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3540 goto emit_set;
a9baceb1
GK
3541
3542 /* 128-bit constant floating-point values on Darwin should really be
3543 loaded as two parts. */
3544 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3545 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3546 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3547 {
3548 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3549 know how to get a DFmode SUBREG of a TFmode. */
3550 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3551 simplify_gen_subreg (DImode, operands[1], mode, 0),
3552 DImode);
3553 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3554 GET_MODE_SIZE (DImode)),
3555 simplify_gen_subreg (DImode, operands[1], mode,
3556 GET_MODE_SIZE (DImode)),
3557 DImode);
3558 return;
3559 }
3560
fb4d4348
GK
3561 /* FIXME: In the long term, this switch statement should go away
3562 and be replaced by a sequence of tests based on things like
3563 mode == Pmode. */
3564 switch (mode)
3565 {
3566 case HImode:
3567 case QImode:
3568 if (CONSTANT_P (operands[1])
3569 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3570 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3571 break;
3572
06f4e019 3573 case TFmode:
fb4d4348
GK
3574 case DFmode:
3575 case SFmode:
3576 if (CONSTANT_P (operands[1])
3577 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3578 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3579 break;
3580
0ac081f6
AH
3581 case V16QImode:
3582 case V8HImode:
3583 case V4SFmode:
3584 case V4SImode:
a3170dc6
AH
3585 case V4HImode:
3586 case V2SFmode:
3587 case V2SImode:
00a892b8 3588 case V1DImode:
69ef87e2 3589 if (CONSTANT_P (operands[1])
d744e06e 3590 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3591 operands[1] = force_const_mem (mode, operands[1]);
3592 break;
3593
fb4d4348 3594 case SImode:
a9098fd0 3595 case DImode:
fb4d4348
GK
3596 /* Use default pattern for address of ELF small data */
3597 if (TARGET_ELF
a9098fd0 3598 && mode == Pmode
f607bc57 3599 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3600 && (GET_CODE (operands[1]) == SYMBOL_REF
3601 || GET_CODE (operands[1]) == CONST)
3602 && small_data_operand (operands[1], mode))
fb4d4348
GK
3603 {
3604 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3605 return;
3606 }
3607
f607bc57 3608 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3609 && mode == Pmode && mode == SImode
3610 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3611 {
3612 emit_insn (gen_movsi_got (operands[0], operands[1]));
3613 return;
3614 }
3615
ee890fe2 3616 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3617 && TARGET_NO_TOC
3618 && ! flag_pic
a9098fd0 3619 && mode == Pmode
fb4d4348
GK
3620 && CONSTANT_P (operands[1])
3621 && GET_CODE (operands[1]) != HIGH
3622 && GET_CODE (operands[1]) != CONST_INT)
3623 {
a9098fd0 3624 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3625
3626 /* If this is a function address on -mcall-aixdesc,
3627 convert it to the address of the descriptor. */
3628 if (DEFAULT_ABI == ABI_AIX
3629 && GET_CODE (operands[1]) == SYMBOL_REF
3630 && XSTR (operands[1], 0)[0] == '.')
3631 {
3632 const char *name = XSTR (operands[1], 0);
3633 rtx new_ref;
3634 while (*name == '.')
3635 name++;
3636 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3637 CONSTANT_POOL_ADDRESS_P (new_ref)
3638 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3639 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3640 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3641 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3642 operands[1] = new_ref;
3643 }
7509c759 3644
ee890fe2
SS
3645 if (DEFAULT_ABI == ABI_DARWIN)
3646 {
ab82a49f
AP
3647#if TARGET_MACHO
3648 if (MACHO_DYNAMIC_NO_PIC_P)
3649 {
3650 /* Take care of any required data indirection. */
3651 operands[1] = rs6000_machopic_legitimize_pic_address (
3652 operands[1], mode, operands[0]);
3653 if (operands[0] != operands[1])
3654 emit_insn (gen_rtx_SET (VOIDmode,
3655 operands[0], operands[1]));
3656 return;
3657 }
3658#endif
ee890fe2
SS
3659 emit_insn (gen_macho_high (target, operands[1]));
3660 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3661 return;
3662 }
3663
fb4d4348
GK
3664 emit_insn (gen_elf_high (target, operands[1]));
3665 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3666 return;
3667 }
3668
a9098fd0
GK
3669 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3670 and we have put it in the TOC, we just need to make a TOC-relative
3671 reference to it. */
3672 if (TARGET_TOC
3673 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3674 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3675 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3676 get_pool_mode (operands[1])))
fb4d4348 3677 {
a9098fd0 3678 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3679 }
a9098fd0
GK
3680 else if (mode == Pmode
3681 && CONSTANT_P (operands[1])
38886f37
AO
3682 && ((GET_CODE (operands[1]) != CONST_INT
3683 && ! easy_fp_constant (operands[1], mode))
3684 || (GET_CODE (operands[1]) == CONST_INT
3685 && num_insns_constant (operands[1], mode) > 2)
3686 || (GET_CODE (operands[0]) == REG
3687 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3688 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3689 && ! legitimate_constant_pool_address_p (operands[1])
3690 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3691 {
3692 /* Emit a USE operation so that the constant isn't deleted if
3693 expensive optimizations are turned on because nobody
3694 references it. This should only be done for operands that
3695 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3696 This should not be done for operands that contain LABEL_REFs.
3697 For now, we just handle the obvious case. */
3698 if (GET_CODE (operands[1]) != LABEL_REF)
3699 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3700
c859cda6 3701#if TARGET_MACHO
ee890fe2 3702 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3703 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3704 {
ee890fe2
SS
3705 operands[1] =
3706 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3707 operands[0]);
3708 if (operands[0] != operands[1])
3709 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3710 return;
3711 }
c859cda6 3712#endif
ee890fe2 3713
fb4d4348
GK
3714 /* If we are to limit the number of things we put in the TOC and
3715 this is a symbol plus a constant we can add in one insn,
3716 just put the symbol in the TOC and add the constant. Don't do
3717 this if reload is in progress. */
3718 if (GET_CODE (operands[1]) == CONST
3719 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3720 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3721 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3722 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3723 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3724 && ! side_effects_p (operands[0]))
3725 {
a4f6c312
SS
3726 rtx sym =
3727 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3728 rtx other = XEXP (XEXP (operands[1], 0), 1);
3729
a9098fd0
GK
3730 sym = force_reg (mode, sym);
3731 if (mode == SImode)
3732 emit_insn (gen_addsi3 (operands[0], sym, other));
3733 else
3734 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3735 return;
3736 }
3737
a9098fd0 3738 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3739
3740 if (TARGET_TOC
4d588c14 3741 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3742 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3743 get_pool_constant (XEXP (operands[1], 0)),
3744 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3745 {
ba4828e0
RK
3746 operands[1]
3747 = gen_rtx_MEM (mode,
3748 create_TOC_reference (XEXP (operands[1], 0)));
3749 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3750 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3751 }
fb4d4348
GK
3752 }
3753 break;
a9098fd0 3754
fb4d4348
GK
3755 case TImode:
3756 if (GET_CODE (operands[0]) == MEM
3757 && GET_CODE (XEXP (operands[0], 0)) != REG
3758 && ! reload_in_progress)
792760b9
RK
3759 operands[0]
3760 = replace_equiv_address (operands[0],
3761 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3762
3763 if (GET_CODE (operands[1]) == MEM
3764 && GET_CODE (XEXP (operands[1], 0)) != REG
3765 && ! reload_in_progress)
792760b9
RK
3766 operands[1]
3767 = replace_equiv_address (operands[1],
3768 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3769 if (TARGET_POWER)
3770 {
3771 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3772 gen_rtvec (2,
3773 gen_rtx_SET (VOIDmode,
3774 operands[0], operands[1]),
3775 gen_rtx_CLOBBER (VOIDmode,
3776 gen_rtx_SCRATCH (SImode)))));
3777 return;
3778 }
fb4d4348
GK
3779 break;
3780
3781 default:
3782 abort ();
3783 }
3784
a9098fd0
GK
3785 /* Above, we may have called force_const_mem which may have returned
3786 an invalid address. If we can, fix this up; otherwise, reload will
3787 have to deal with it. */
8f4e6caf
RH
3788 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3789 operands[1] = validize_mem (operands[1]);
a9098fd0 3790
8f4e6caf 3791 emit_set:
fb4d4348
GK
3792 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3793}
4697a36c 3794\f
2858f73a
GK
3795/* Nonzero if we can use a floating-point register to pass this arg. */
3796#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
3797 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
3798 && (CUM)->fregno <= FP_ARG_MAX_REG \
3799 && TARGET_HARD_FLOAT && TARGET_FPRS)
3800
3801/* Nonzero if we can use an AltiVec register to pass this arg. */
3802#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
3803 (ALTIVEC_VECTOR_MODE (MODE) \
3804 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
3805 && TARGET_ALTIVEC_ABI \
83953138 3806 && (NAMED))
2858f73a 3807
c6e8c921
GK
3808/* Return a nonzero value to say to return the function value in
3809 memory, just as large structures are always returned. TYPE will be
3810 the data type of the value, and FNTYPE will be the type of the
3811 function doing the returning, or @code{NULL} for libcalls.
3812
3813 The AIX ABI for the RS/6000 specifies that all structures are
3814 returned in memory. The Darwin ABI does the same. The SVR4 ABI
3815 specifies that structures <= 8 bytes are returned in r3/r4, but a
3816 draft put them in memory, and GCC used to implement the draft
3817 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
3818 controls this instead of DEFAULT_ABI; V.4 targets needing backward
3819 compatibility can change DRAFT_V4_STRUCT_RET to override the
3820 default, and -m switches get the final word. See
3821 rs6000_override_options for more details.
3822
3823 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
3824 long double support is enabled. These values are returned in memory.
3825
3826 int_size_in_bytes returns -1 for variable size objects, which go in
3827 memory always. The cast to unsigned makes -1 > 8. */
3828
3829static bool
3830rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3831{
3832 if (AGGREGATE_TYPE_P (type)
3833 && (TARGET_AIX_STRUCT_RET
3834 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
3835 return true;
3836 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
3837 return true;
3838 return false;
3839}
3840
4697a36c
MM
3841/* Initialize a variable CUM of type CUMULATIVE_ARGS
3842 for a call to a function whose data type is FNTYPE.
3843 For a library call, FNTYPE is 0.
3844
3845 For incoming args we set the number of arguments in the prototype large
1c20ae99 3846 so we never return a PARALLEL. */
4697a36c
MM
3847
3848void
a2369ed3 3849init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
3850 rtx libname ATTRIBUTE_UNUSED, int incoming,
3851 int libcall, int n_named_args)
4697a36c
MM
3852{
3853 static CUMULATIVE_ARGS zero_cumulative;
3854
3855 *cum = zero_cumulative;
3856 cum->words = 0;
3857 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3858 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3859 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3860 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3861 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3862 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3863 cum->stdarg = fntype
3864 && (TYPE_ARG_TYPES (fntype) != 0
3865 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3866 != void_type_node));
4697a36c 3867
0f6937fe
AM
3868 cum->nargs_prototype = 0;
3869 if (incoming || cum->prototype)
3870 cum->nargs_prototype = n_named_args;
4697a36c 3871
a5c76ee6
ZW
3872 /* Check for a longcall attribute. */
3873 if (fntype
3874 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3875 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3876 cum->call_cookie = CALL_LONG;
3877
4697a36c
MM
3878 if (TARGET_DEBUG_ARG)
3879 {
3880 fprintf (stderr, "\ninit_cumulative_args:");
3881 if (fntype)
3882 {
3883 tree ret_type = TREE_TYPE (fntype);
3884 fprintf (stderr, " ret code = %s,",
3885 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3886 }
3887
6a4cee5f
MM
3888 if (cum->call_cookie & CALL_LONG)
3889 fprintf (stderr, " longcall,");
3890
4697a36c
MM
3891 fprintf (stderr, " proto = %d, nargs = %d\n",
3892 cum->prototype, cum->nargs_prototype);
3893 }
6d0ef01e
HP
3894
3895 if (fntype
3896 && !TARGET_ALTIVEC
3897 && TARGET_ALTIVEC_ABI
3898 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
3899 {
3900 error ("Cannot return value in vector register because"
3901 " altivec instructions are disabled, use -maltivec"
3902 " to enable them.");
3903 }
4697a36c
MM
3904}
3905\f
c229cba9
DE
3906/* If defined, a C expression which determines whether, and in which
3907 direction, to pad out an argument with extra space. The value
3908 should be of type `enum direction': either `upward' to pad above
3909 the argument, `downward' to pad below, or `none' to inhibit
3910 padding.
3911
3912 For the AIX ABI structs are always stored left shifted in their
3913 argument slot. */
3914
9ebbca7d 3915enum direction
a2369ed3 3916function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3917{
6e985040
AM
3918#ifndef AGGREGATE_PADDING_FIXED
3919#define AGGREGATE_PADDING_FIXED 0
3920#endif
3921#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3922#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3923#endif
3924
3925 if (!AGGREGATE_PADDING_FIXED)
3926 {
3927 /* GCC used to pass structures of the same size as integer types as
3928 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3929 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3930 passed padded downward, except that -mstrict-align further
3931 muddied the water in that multi-component structures of 2 and 4
3932 bytes in size were passed padded upward.
3933
3934 The following arranges for best compatibility with previous
3935 versions of gcc, but removes the -mstrict-align dependency. */
3936 if (BYTES_BIG_ENDIAN)
3937 {
3938 HOST_WIDE_INT size = 0;
3939
3940 if (mode == BLKmode)
3941 {
3942 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3943 size = int_size_in_bytes (type);
3944 }
3945 else
3946 size = GET_MODE_SIZE (mode);
3947
3948 if (size == 1 || size == 2 || size == 4)
3949 return downward;
3950 }
3951 return upward;
3952 }
3953
3954 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3955 {
3956 if (type != 0 && AGGREGATE_TYPE_P (type))
3957 return upward;
3958 }
c229cba9 3959
d3704c46
KH
3960 /* Fall back to the default. */
3961 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
3962}
3963
b6c9286a
MM
3964/* If defined, a C expression that gives the alignment boundary, in bits,
3965 of an argument with the specified mode and type. If it is not defined,
3966 PARM_BOUNDARY is used for all arguments.
3967
2310f99a 3968 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3969
3970int
a2369ed3 3971function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 3972{
f607bc57 3973 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3974 return 64;
a3170dc6
AH
3975 else if (SPE_VECTOR_MODE (mode))
3976 return 64;
0ac081f6
AH
3977 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3978 return 128;
9ebbca7d 3979 else
b6c9286a 3980 return PARM_BOUNDARY;
b6c9286a 3981}
c53bdcf5
AM
3982
3983/* Compute the size (in words) of a function argument. */
3984
3985static unsigned long
3986rs6000_arg_size (enum machine_mode mode, tree type)
3987{
3988 unsigned long size;
3989
3990 if (mode != BLKmode)
3991 size = GET_MODE_SIZE (mode);
3992 else
3993 size = int_size_in_bytes (type);
3994
3995 if (TARGET_32BIT)
3996 return (size + 3) >> 2;
3997 else
3998 return (size + 7) >> 3;
3999}
b6c9286a 4000\f
4697a36c
MM
4001/* Update the data in CUM to advance over an argument
4002 of mode MODE and data type TYPE.
4003 (TYPE is null for libcalls where that information may not be available.) */
4004
4005void
a2369ed3
DJ
4006function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4007 tree type, int named)
4697a36c
MM
4008{
4009 cum->nargs_prototype--;
4010
0ac081f6
AH
4011 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4012 {
2858f73a 4013 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4014 {
4015 cum->vregno++;
4016 if (!TARGET_ALTIVEC)
4017 error ("Cannot pass argument in vector register because"
4018 " altivec instructions are disabled, use -maltivec"
4019 " to enable them.");
4020 }
c72d6c26
HP
4021 /* PowerPC64 Linux and AIX allocates GPRs for a vector argument
4022 even if it is going to be passed in a vector register.
4023 Darwin does the same for variable-argument functions. */
4024 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4025 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4026 {
a594a19c
GK
4027 int align;
4028
2858f73a
GK
4029 /* Vector parameters must be 16-byte aligned. This places
4030 them at 2 mod 4 in terms of words in 32-bit mode, since
4031 the parameter save area starts at offset 24 from the
4032 stack. In 64-bit mode, they just have to start on an
4033 even word, since the parameter save area is 16-byte
4034 aligned. Space for GPRs is reserved even if the argument
4035 will be passed in memory. */
4036 if (TARGET_32BIT)
4037 align = ((6 - (cum->words & 3)) & 3);
4038 else
4039 align = cum->words & 1;
c53bdcf5 4040 cum->words += align + rs6000_arg_size (mode, type);
2858f73a 4041
a594a19c
GK
4042 if (TARGET_DEBUG_ARG)
4043 {
4044 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4045 cum->words, align);
4046 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4047 cum->nargs_prototype, cum->prototype,
4048 GET_MODE_NAME (mode));
a594a19c
GK
4049 }
4050 }
0ac081f6 4051 }
a4b0320c 4052 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4053 && !cum->stdarg
4054 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4055 cum->sysv_gregno++;
f607bc57 4056 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4057 {
a3170dc6 4058 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4059 && (mode == SFmode || mode == DFmode))
4697a36c 4060 {
4cc833b7
RH
4061 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4062 cum->fregno++;
4063 else
4064 {
4065 if (mode == DFmode)
4066 cum->words += cum->words & 1;
c53bdcf5 4067 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4068 }
4697a36c 4069 }
4cc833b7
RH
4070 else
4071 {
4072 int n_words;
4073 int gregno = cum->sysv_gregno;
4074
4075 /* Aggregates and IEEE quad get passed by reference. */
4076 if ((type && AGGREGATE_TYPE_P (type))
4077 || mode == TFmode)
4078 n_words = 1;
4079 else
c53bdcf5 4080 n_words = rs6000_arg_size (mode, type);
4cc833b7 4081
a4b0320c 4082 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4083 if (n_words == 2 && (gregno & 1) == 0)
4084 gregno += 1;
4085
a4b0320c
AH
4086 /* Long long and SPE vectors are not split between registers
4087 and stack. */
4cc833b7
RH
4088 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4089 {
4090 /* Long long is aligned on the stack. */
4091 if (n_words == 2)
4092 cum->words += cum->words & 1;
4093 cum->words += n_words;
4094 }
4697a36c 4095
4cc833b7
RH
4096 /* Note: continuing to accumulate gregno past when we've started
4097 spilling to the stack indicates the fact that we've started
4098 spilling to the stack to expand_builtin_saveregs. */
4099 cum->sysv_gregno = gregno + n_words;
4100 }
4697a36c 4101
4cc833b7
RH
4102 if (TARGET_DEBUG_ARG)
4103 {
4104 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4105 cum->words, cum->fregno);
4106 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4107 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4108 fprintf (stderr, "mode = %4s, named = %d\n",
4109 GET_MODE_NAME (mode), named);
4110 }
4697a36c
MM
4111 }
4112 else
4cc833b7
RH
4113 {
4114 int align = (TARGET_32BIT && (cum->words & 1) != 0
4115 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 4116
c53bdcf5 4117 cum->words += align + rs6000_arg_size (mode, type);
4697a36c 4118
a3170dc6
AH
4119 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4120 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4121 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4122
4123 if (TARGET_DEBUG_ARG)
4124 {
4125 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4126 cum->words, cum->fregno);
4127 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4128 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4129 fprintf (stderr, "named = %d, align = %d\n", named, align);
4130 }
4131 }
4697a36c 4132}
a6c9bed4
AH
4133
4134/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4135
a6c9bed4 4136static rtx
a2369ed3
DJ
4137rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4138 tree type)
a6c9bed4
AH
4139{
4140 if (cum->stdarg)
4141 {
4142 int gregno = cum->sysv_gregno;
c53bdcf5 4143 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4144
4145 /* SPE vectors are put in odd registers. */
4146 if (n_words == 2 && (gregno & 1) == 0)
4147 gregno += 1;
4148
4149 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4150 {
4151 rtx r1, r2;
4152 enum machine_mode m = SImode;
4153
4154 r1 = gen_rtx_REG (m, gregno);
4155 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4156 r2 = gen_rtx_REG (m, gregno + 1);
4157 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4158 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4159 }
4160 else
b78d48dd 4161 return NULL_RTX;
a6c9bed4
AH
4162 }
4163 else
4164 {
4165 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4166 return gen_rtx_REG (mode, cum->sysv_gregno);
4167 else
b78d48dd 4168 return NULL_RTX;
a6c9bed4
AH
4169 }
4170}
4171
b78d48dd
FJ
4172/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4173
4174static rtx
4175rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4176 tree type, int align_words)
4177{
4178 if (mode == DFmode)
4179 {
4180 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4181 in vararg list into zero, one or two GPRs */
4182 if (align_words >= GP_ARG_NUM_REG)
4183 return gen_rtx_PARALLEL (DFmode,
4184 gen_rtvec (2,
4185 gen_rtx_EXPR_LIST (VOIDmode,
4186 NULL_RTX, const0_rtx),
4187 gen_rtx_EXPR_LIST (VOIDmode,
4188 gen_rtx_REG (mode,
4189 cum->fregno),
4190 const0_rtx)));
c53bdcf5 4191 else if (align_words + rs6000_arg_size (mode, type)
b78d48dd
FJ
4192 > GP_ARG_NUM_REG)
4193 /* If this is partially on the stack, then we only
a3c9585f 4194 include the portion actually in registers here. */
b78d48dd
FJ
4195 return gen_rtx_PARALLEL (DFmode,
4196 gen_rtvec (2,
4197 gen_rtx_EXPR_LIST (VOIDmode,
4198 gen_rtx_REG (SImode,
4199 GP_ARG_MIN_REG
4200 + align_words),
4201 const0_rtx),
4202 gen_rtx_EXPR_LIST (VOIDmode,
4203 gen_rtx_REG (mode,
4204 cum->fregno),
4205 const0_rtx)));
4206
4207 /* split a DFmode arg into two GPRs */
4208 return gen_rtx_PARALLEL (DFmode,
4209 gen_rtvec (3,
4210 gen_rtx_EXPR_LIST (VOIDmode,
4211 gen_rtx_REG (SImode,
4212 GP_ARG_MIN_REG
4213 + align_words),
4214 const0_rtx),
4215 gen_rtx_EXPR_LIST (VOIDmode,
4216 gen_rtx_REG (SImode,
4217 GP_ARG_MIN_REG
4218 + align_words + 1),
4219 GEN_INT (4)),
4220 gen_rtx_EXPR_LIST (VOIDmode,
4221 gen_rtx_REG (mode, cum->fregno),
4222 const0_rtx)));
4223 }
4224 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4225 or two GPRs */
4226 else if (mode == DImode)
4227 {
4228 if (align_words < GP_ARG_NUM_REG - 1)
4229 return gen_rtx_PARALLEL (DImode,
4230 gen_rtvec (2,
4231 gen_rtx_EXPR_LIST (VOIDmode,
4232 gen_rtx_REG (SImode,
4233 GP_ARG_MIN_REG
4234 + align_words),
4235 const0_rtx),
4236 gen_rtx_EXPR_LIST (VOIDmode,
4237 gen_rtx_REG (SImode,
4238 GP_ARG_MIN_REG
4239 + align_words + 1),
4240 GEN_INT (4))));
4241 else if (align_words == GP_ARG_NUM_REG - 1)
4242 return gen_rtx_PARALLEL (DImode,
4243 gen_rtvec (2,
4244 gen_rtx_EXPR_LIST (VOIDmode,
4245 NULL_RTX, const0_rtx),
4246 gen_rtx_EXPR_LIST (VOIDmode,
4247 gen_rtx_REG (SImode,
4248 GP_ARG_MIN_REG
4249 + align_words),
4250 const0_rtx)));
4251 }
4252 else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1))
4253 {
4254 int k;
4255 int size = int_size_in_bytes (type);
2f7b62ef 4256 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4257 int max_no_words = GP_ARG_NUM_REG - align_words;
4258 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4259 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4260
4261 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4262
4263 for (k=0; k < rtlvec_len; k++)
4264 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4265 gen_rtx_REG (SImode,
4266 GP_ARG_MIN_REG
4267 + align_words + k),
4268 k == 0 ? const0_rtx : GEN_INT (k*4));
4269
4270 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec));
4271 }
4272
4273 return NULL_RTX;
4274}
4275
4697a36c
MM
4276/* Determine where to put an argument to a function.
4277 Value is zero to push the argument on the stack,
4278 or a hard register in which to store the argument.
4279
4280 MODE is the argument's machine mode.
4281 TYPE is the data type of the argument (as a tree).
4282 This is null for libcalls where that information may
4283 not be available.
4284 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4285 the preceding args and about the function being called.
4286 NAMED is nonzero if this argument is a named parameter
4287 (otherwise it is an extra parameter matching an ellipsis).
4288
4289 On RS/6000 the first eight words of non-FP are normally in registers
4290 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4291 Under V.4, the first 8 FP args are in registers.
4292
4293 If this is floating-point and no prototype is specified, we use
4294 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4295 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4296 so we can pass the FP value just in one register. emit_library_function
1c20ae99 4297 doesn't support PARALLEL anyway. */
4697a36c
MM
4298
4299struct rtx_def *
a2369ed3
DJ
4300function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4301 tree type, int named)
4697a36c 4302{
4cc833b7 4303 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4304
a4f6c312
SS
4305 /* Return a marker to indicate whether CR1 needs to set or clear the
4306 bit that V.4 uses to say fp args were passed in registers.
4307 Assume that we don't need the marker for software floating point,
4308 or compiler generated library calls. */
4697a36c
MM
4309 if (mode == VOIDmode)
4310 {
f607bc57 4311 if (abi == ABI_V4
7509c759 4312 && cum->nargs_prototype < 0
b9599e46
FS
4313 && (cum->call_cookie & CALL_LIBCALL) == 0
4314 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4315 {
a3170dc6
AH
4316 /* For the SPE, we need to crxor CR6 always. */
4317 if (TARGET_SPE_ABI)
4318 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4319 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4320 return GEN_INT (cum->call_cookie
4321 | ((cum->fregno == FP_ARG_MIN_REG)
4322 ? CALL_V4_SET_FP_ARGS
4323 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4324 }
4697a36c 4325
7509c759 4326 return GEN_INT (cum->call_cookie);
4697a36c
MM
4327 }
4328
2858f73a 4329 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4330 if (TARGET_64BIT && ! cum->prototype)
4331 {
4332 /* Vector parameters get passed in vector register
4333 and also in GPRs or memory, in absence of prototype. */
4334 int align_words;
4335 rtx slot;
4336 align_words = (cum->words + 1) & ~1;
4337
4338 if (align_words >= GP_ARG_NUM_REG)
4339 {
4340 slot = NULL_RTX;
4341 }
4342 else
4343 {
4344 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4345 }
4346 return gen_rtx_PARALLEL (mode,
4347 gen_rtvec (2,
4348 gen_rtx_EXPR_LIST (VOIDmode,
4349 slot, const0_rtx),
4350 gen_rtx_EXPR_LIST (VOIDmode,
4351 gen_rtx_REG (mode, cum->vregno),
4352 const0_rtx)));
4353 }
4354 else
4355 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4356 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4357 {
2858f73a 4358 if (named || abi == ABI_V4)
a594a19c 4359 return NULL_RTX;
0ac081f6 4360 else
a594a19c
GK
4361 {
4362 /* Vector parameters to varargs functions under AIX or Darwin
4363 get passed in memory and possibly also in GPRs. */
4364 int align, align_words;
2858f73a 4365 enum machine_mode part_mode = mode;
a594a19c
GK
4366
4367 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4368 2 mod 4 in terms of words in 32-bit mode, since the parameter
4369 save area starts at offset 24 from the stack. In 64-bit mode,
4370 they just have to start on an even word, since the parameter
4371 save area is 16-byte aligned. */
4372 if (TARGET_32BIT)
4373 align = ((6 - (cum->words & 3)) & 3);
4374 else
4375 align = cum->words & 1;
a594a19c
GK
4376 align_words = cum->words + align;
4377
4378 /* Out of registers? Memory, then. */
4379 if (align_words >= GP_ARG_NUM_REG)
4380 return NULL_RTX;
4381
2858f73a
GK
4382 /* The vector value goes in GPRs. Only the part of the
4383 value in GPRs is reported here. */
4384 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4385 > GP_ARG_NUM_REG)
839a4992 4386 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4387 is either wholly in GPRs or half in GPRs and half not. */
4388 part_mode = DImode;
4389
4390 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4391 }
0ac081f6 4392 }
a6c9bed4
AH
4393 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4394 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4395 else if (abi == ABI_V4)
4697a36c 4396 {
a3170dc6 4397 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4398 && (mode == SFmode || mode == DFmode))
4399 {
4400 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4401 return gen_rtx_REG (mode, cum->fregno);
4402 else
b78d48dd 4403 return NULL_RTX;
4cc833b7
RH
4404 }
4405 else
4406 {
4407 int n_words;
4408 int gregno = cum->sysv_gregno;
4409
4410 /* Aggregates and IEEE quad get passed by reference. */
4411 if ((type && AGGREGATE_TYPE_P (type))
4412 || mode == TFmode)
4413 n_words = 1;
4414 else
c53bdcf5 4415 n_words = rs6000_arg_size (mode, type);
4cc833b7 4416
a4b0320c 4417 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4418 if (n_words == 2 && (gregno & 1) == 0)
4419 gregno += 1;
4420
c53bdcf5 4421 /* Long long does not split between registers and stack. */
4cc833b7 4422 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4423 return gen_rtx_REG (mode, gregno);
4cc833b7 4424 else
b78d48dd 4425 return NULL_RTX;
4cc833b7 4426 }
4697a36c 4427 }
4cc833b7
RH
4428 else
4429 {
4430 int align = (TARGET_32BIT && (cum->words & 1) != 0
4431 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4432 int align_words = cum->words + align;
4697a36c 4433
4cc833b7
RH
4434 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4435 return NULL_RTX;
4436
b78d48dd 4437 if (TARGET_32BIT && TARGET_POWERPC64
e91fa876 4438 && (mode == DImode || mode == BLKmode))
b78d48dd
FJ
4439 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4440
2858f73a 4441 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 4442 {
c53bdcf5
AM
4443 rtx fpr[2];
4444 rtx *r;
4445 bool needs_psave;
4446 enum machine_mode fmode = mode;
4447 int n;
4448 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
4449
4450 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
4451 {
4452 /* Long double split over regs and memory. */
4453 if (fmode == TFmode)
4454 fmode = DFmode;
4455
4456 /* Currently, we only ever need one reg here because complex
4457 doubles are split. */
4458 if (cum->fregno != FP_ARG_MAX_REG - 1)
4459 abort ();
4460 }
4461 fpr[1] = gen_rtx_REG (fmode, cum->fregno);
4462
4463 /* Do we also need to pass this arg in the parameter save
4464 area? */
4465 needs_psave = (type
4466 && (cum->nargs_prototype <= 0
4467 || (DEFAULT_ABI == ABI_AIX
4468 && TARGET_XL_CALL
4469 && align_words >= GP_ARG_NUM_REG)));
4470
4471 if (!needs_psave && mode == fmode)
4472 return fpr[1];
4cc833b7 4473
e91fa876
FJ
4474 if (TARGET_32BIT && TARGET_POWERPC64
4475 && mode == DFmode && cum->stdarg)
4476 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4477
c53bdcf5
AM
4478 /* Describe where this piece goes. */
4479 r = fpr + 1;
4480 *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx);
4481 n = 1;
4482
4483 if (needs_psave)
4484 {
4485 /* Now describe the part that goes in gprs or the stack.
4486 This piece must come first, before the fprs. */
4487 rtx reg = NULL_RTX;
4488 if (align_words < GP_ARG_NUM_REG)
4489 {
4490 unsigned long n_words = rs6000_arg_size (mode, type);
4491 enum machine_mode rmode = mode;
4492
4493 if (align_words + n_words > GP_ARG_NUM_REG)
4494 /* If this is partially on the stack, then we only
4495 include the portion actually in registers here.
4496 We know this can only be one register because
4497 complex doubles are splt. */
4498 rmode = Pmode;
4499 reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
4500 }
4501 *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4502 ++n;
4503 }
4504
4505 return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r));
4cc833b7
RH
4506 }
4507 else if (align_words < GP_ARG_NUM_REG)
4508 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4509 else
4510 return NULL_RTX;
4697a36c 4511 }
4697a36c
MM
4512}
4513\f
4514/* For an arg passed partly in registers and partly in memory,
4515 this is the number of registers used.
4516 For args passed entirely in registers or entirely in memory, zero. */
4517
4518int
a2369ed3 4519function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4520 tree type, int named)
4697a36c 4521{
c53bdcf5
AM
4522 int ret = 0;
4523
f607bc57 4524 if (DEFAULT_ABI == ABI_V4)
4697a36c 4525 return 0;
4697a36c 4526
c53bdcf5
AM
4527 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
4528 && cum->nargs_prototype >= 0)
4529 return 0;
4530
4531 if (USE_FP_FOR_ARG_P (cum, mode, type))
4697a36c 4532 {
c53bdcf5
AM
4533 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
4534 ret = FP_ARG_MAX_REG - cum->fregno;
4535 else if (cum->nargs_prototype >= 0)
4697a36c
MM
4536 return 0;
4537 }
4538
4539 if (cum->words < GP_ARG_NUM_REG
c53bdcf5
AM
4540 && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type))
4541 ret = GP_ARG_NUM_REG - cum->words;
4697a36c 4542
c53bdcf5
AM
4543 if (ret != 0 && TARGET_DEBUG_ARG)
4544 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 4545
c53bdcf5 4546 return ret;
4697a36c
MM
4547}
4548\f
4549/* A C expression that indicates when an argument must be passed by
4550 reference. If nonzero for an argument, a copy of that argument is
4551 made in memory and a pointer to the argument is passed instead of
4552 the argument itself. The pointer is passed in whatever way is
4553 appropriate for passing a pointer to that type.
4554
c8c99a68
DE
4555 Under V.4, structures and unions are passed by reference.
4556
4557 As an extension to all ABIs, variable sized types are passed by
4558 reference. */
4697a36c
MM
4559
4560int
a2369ed3
DJ
4561function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4562 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4563 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4564{
f607bc57 4565 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4566 && ((type && AGGREGATE_TYPE_P (type))
4567 || mode == TFmode))
4697a36c
MM
4568 {
4569 if (TARGET_DEBUG_ARG)
4570 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4571
4572 return 1;
4573 }
fff2cb99 4574 return type && int_size_in_bytes (type) < 0;
4697a36c 4575}
5985c7a6
FJ
4576
4577static void
2d9db8eb 4578rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4579{
4580 int i;
4581 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4582
4583 if (nregs == 0)
4584 return;
4585
4586 for (i = 0; i < nregs; i++)
4587 {
4588 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4589 if (reload_completed)
4590 {
4591 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4592 tem = NULL_RTX;
4593 else
4594 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4595 i * GET_MODE_SIZE(reg_mode));
4596 }
4597 else
4598 tem = replace_equiv_address (tem, XEXP (tem, 0));
4599
4600 if (tem == NULL_RTX)
4601 abort ();
4602
4603 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4604 }
4605}
4606
4697a36c
MM
4607\f
4608/* Perform any needed actions needed for a function that is receiving a
4609 variable number of arguments.
4610
4611 CUM is as above.
4612
4613 MODE and TYPE are the mode and type of the current parameter.
4614
4615 PRETEND_SIZE is a variable that should be set to the amount of stack
4616 that must be pushed by the prolog to pretend that our caller pushed
4617 it.
4618
4619 Normally, this macro will push all remaining incoming registers on the
4620 stack and set PRETEND_SIZE to the length of the registers pushed. */
4621
c6e8c921 4622static void
a2369ed3
DJ
4623setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4624 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4625{
4cc833b7
RH
4626 CUMULATIVE_ARGS next_cum;
4627 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4628 rtx save_area = NULL_RTX, mem;
dfafc897 4629 int first_reg_offset, set;
4697a36c 4630
f31bf321 4631 /* Skip the last named argument. */
d34c5b80 4632 next_cum = *cum;
f31bf321 4633 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4634
f607bc57 4635 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4636 {
4cc833b7 4637 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4638 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4639 if (! no_rtl)
2c4974b7 4640 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4641 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4642
4643 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4644 }
60e2d0ca 4645 else
4697a36c 4646 {
d34c5b80 4647 first_reg_offset = next_cum.words;
4cc833b7 4648 save_area = virtual_incoming_args_rtx;
00dba523 4649 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4650
4651 if (MUST_PASS_IN_STACK (mode, type))
c53bdcf5 4652 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 4653 }
4697a36c 4654
dfafc897 4655 set = get_varargs_alias_set ();
c81fc13e 4656 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4657 {
dfafc897
FS
4658 mem = gen_rtx_MEM (BLKmode,
4659 plus_constant (save_area,
4660 first_reg_offset * reg_size)),
ba4828e0 4661 set_mem_alias_set (mem, set);
8ac61af7 4662 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4663
5985c7a6
FJ
4664 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4665 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4666 }
4667
4697a36c 4668 /* Save FP registers if needed. */
f607bc57 4669 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4670 && TARGET_HARD_FLOAT && TARGET_FPRS
4671 && ! no_rtl
4cc833b7 4672 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4673 {
4cc833b7 4674 int fregno = next_cum.fregno;
9ebbca7d 4675 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4676 rtx lab = gen_label_rtx ();
4677 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4678
4cc833b7 4679 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4680 pc_rtx,
39403d82 4681 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4682 gen_rtx_NE (VOIDmode, cr1,
4683 const0_rtx),
39403d82 4684 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4685 pc_rtx)));
4686
4cc833b7
RH
4687 while (fregno <= FP_ARG_V4_MAX_REG)
4688 {
dfafc897 4689 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4690 set_mem_alias_set (mem, set);
dfafc897 4691 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4692 fregno++;
4693 off += 8;
4697a36c 4694 }
4cc833b7
RH
4695
4696 emit_label (lab);
4697a36c 4697 }
4697a36c 4698}
4697a36c 4699
dfafc897 4700/* Create the va_list data type. */
2c4974b7 4701
c35d187f
RH
4702static tree
4703rs6000_build_builtin_va_list (void)
dfafc897 4704{
64c2816f 4705 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4706
9ebbca7d
GK
4707 /* For AIX, prefer 'char *' because that's what the system
4708 header files like. */
f607bc57 4709 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4710 return build_pointer_type (char_type_node);
dfafc897 4711
f1e639b1 4712 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4713 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4714
9ebbca7d
GK
4715 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4716 unsigned_char_type_node);
4717 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4718 unsigned_char_type_node);
64c2816f
DT
4719 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4720 every user file. */
4721 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4722 short_unsigned_type_node);
dfafc897
FS
4723 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4724 ptr_type_node);
4725 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4726 ptr_type_node);
4727
4728 DECL_FIELD_CONTEXT (f_gpr) = record;
4729 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4730 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4731 DECL_FIELD_CONTEXT (f_ovf) = record;
4732 DECL_FIELD_CONTEXT (f_sav) = record;
4733
bab45a51
FS
4734 TREE_CHAIN (record) = type_decl;
4735 TYPE_NAME (record) = type_decl;
dfafc897
FS
4736 TYPE_FIELDS (record) = f_gpr;
4737 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4738 TREE_CHAIN (f_fpr) = f_res;
4739 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4740 TREE_CHAIN (f_ovf) = f_sav;
4741
4742 layout_type (record);
4743
4744 /* The correct type is an array type of one element. */
4745 return build_array_type (record, build_index_type (size_zero_node));
4746}
4747
4748/* Implement va_start. */
4749
4750void
a2369ed3 4751rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4752{
dfafc897 4753 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4754 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4755 tree gpr, fpr, ovf, sav, t;
2c4974b7 4756
dfafc897 4757 /* Only SVR4 needs something special. */
f607bc57 4758 if (DEFAULT_ABI != ABI_V4)
dfafc897 4759 {
e5faf155 4760 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4761 return;
4762 }
4763
973a648b 4764 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4765 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4766 f_res = TREE_CHAIN (f_fpr);
4767 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4768 f_sav = TREE_CHAIN (f_ovf);
4769
8ebecc3b 4770 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4771 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4772 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4773 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4774 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4775
4776 /* Count number of gp and fp argument registers used. */
4cc833b7 4777 words = current_function_args_info.words;
dfafc897
FS
4778 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4779 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4780
4781 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4782 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4783 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4784 words, n_gpr, n_fpr);
dfafc897
FS
4785
4786 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4787 TREE_SIDE_EFFECTS (t) = 1;
4788 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4789
4790 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4791 TREE_SIDE_EFFECTS (t) = 1;
4792 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4793
4794 /* Find the overflow area. */
4795 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4796 if (words != 0)
4797 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4798 build_int_2 (words * UNITS_PER_WORD, 0));
4799 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4800 TREE_SIDE_EFFECTS (t) = 1;
4801 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4802
4803 /* Find the register save area. */
4804 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4805 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4806 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4807 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4808 TREE_SIDE_EFFECTS (t) = 1;
4809 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4810}
4811
4812/* Implement va_arg. */
4813
4814rtx
a2369ed3 4815rs6000_va_arg (tree valist, tree type)
dfafc897 4816{
c566f9bd 4817 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4818 tree gpr, fpr, ovf, sav, reg, t, u;
4819 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4820 rtx lab_false, lab_over, addr_rtx, r;
4821
f607bc57 4822 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4823 {
4824 /* Variable sized types are passed by reference. */
fff2cb99 4825 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4826 {
4827 u = build_pointer_type (type);
4828
4829 /* Args grow upward. */
4830 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4831 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4832 TREE_SIDE_EFFECTS (t) = 1;
4833
4834 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4835 TREE_SIDE_EFFECTS (t) = 1;
4836
4837 t = build1 (INDIRECT_REF, u, t);
4838 TREE_SIDE_EFFECTS (t) = 1;
4839
4840 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4841 }
fa78dbea 4842 if (targetm.calls.split_complex_arg
c53bdcf5
AM
4843 && TREE_CODE (type) == COMPLEX_TYPE)
4844 {
4845 tree elem_type = TREE_TYPE (type);
4846 enum machine_mode elem_mode = TYPE_MODE (elem_type);
4847 int elem_size = GET_MODE_SIZE (elem_mode);
4848
4849 if (elem_size < UNITS_PER_WORD)
4850 {
4851 rtx real_part, imag_part, dest_real, rr;
4852
4853 real_part = rs6000_va_arg (valist, elem_type);
4854 imag_part = rs6000_va_arg (valist, elem_type);
4855
4856 /* We're not returning the value here, but the address.
4857 real_part and imag_part are not contiguous, and we know
4858 there is space available to pack real_part next to
4859 imag_part. float _Complex is not promoted to
4860 double _Complex by the default promotion rules that
4861 promote float to double. */
4862 if (2 * elem_size > UNITS_PER_WORD)
4863 abort ();
4864
4865 real_part = gen_rtx_MEM (elem_mode, real_part);
4866 imag_part = gen_rtx_MEM (elem_mode, imag_part);
4867
4868 dest_real = adjust_address (imag_part, elem_mode, -elem_size);
4869 rr = gen_reg_rtx (elem_mode);
4870 emit_move_insn (rr, real_part);
4871 emit_move_insn (dest_real, rr);
4872
4873 return XEXP (dest_real, 0);
4874 }
4875 }
4876
4877 return std_expand_builtin_va_arg (valist, type);
c8c99a68 4878 }
dfafc897 4879
973a648b 4880 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4881 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4882 f_res = TREE_CHAIN (f_fpr);
4883 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4884 f_sav = TREE_CHAIN (f_ovf);
4885
8ebecc3b 4886 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4887 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4888 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4889 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4890 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4891
4892 size = int_size_in_bytes (type);
4893 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4894
dfafc897 4895 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4896 {
dfafc897
FS
4897 /* Aggregates and long doubles are passed by reference. */
4898 indirect_p = 1;
4899 reg = gpr;
4900 n_reg = 1;
4901 sav_ofs = 0;
4902 sav_scale = 4;
d3294cd9
FS
4903 size = UNITS_PER_WORD;
4904 rsize = 1;
dfafc897 4905 }
a3170dc6 4906 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4907 {
4908 /* FP args go in FP registers, if present. */
4909 indirect_p = 0;
4910 reg = fpr;
4911 n_reg = 1;
4912 sav_ofs = 8*4;
4913 sav_scale = 8;
4cc833b7 4914 }
dfafc897
FS
4915 else
4916 {
4917 /* Otherwise into GP registers. */
4918 indirect_p = 0;
4919 reg = gpr;
4920 n_reg = rsize;
4921 sav_ofs = 0;
4922 sav_scale = 4;
4923 }
4924
a3c9585f 4925 /* Pull the value out of the saved registers.... */
dfafc897
FS
4926
4927 lab_false = gen_label_rtx ();
4928 lab_over = gen_label_rtx ();
4929 addr_rtx = gen_reg_rtx (Pmode);
4930
16861f33
AH
4931 /* AltiVec vectors never go in registers. */
4932 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4933 {
41daaf0e
AH
4934 TREE_THIS_VOLATILE (reg) = 1;
4935 emit_cmp_and_jump_insns
4936 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4937 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4938 lab_false);
dfafc897 4939
41daaf0e
AH
4940 /* Long long is aligned in the registers. */
4941 if (n_reg > 1)
4942 {
4943 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4944 build_int_2 (n_reg - 1, 0));
4945 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4946 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4947 TREE_SIDE_EFFECTS (u) = 1;
4948 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4949 }
2c4974b7 4950
41daaf0e
AH
4951 if (sav_ofs)
4952 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4953 else
4954 t = sav;
2c4974b7 4955
41daaf0e
AH
4956 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4957 build_int_2 (n_reg, 0));
4958 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4959
41daaf0e
AH
4960 u = build1 (CONVERT_EXPR, integer_type_node, u);
4961 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4962
41daaf0e
AH
4963 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4964 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4965
41daaf0e
AH
4966 t = build (PLUS_EXPR, ptr_type_node, t, u);
4967 TREE_SIDE_EFFECTS (t) = 1;
4968
4969 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4970 if (r != addr_rtx)
4971 emit_move_insn (addr_rtx, r);
4972
4973 emit_jump_insn (gen_jump (lab_over));
4974 emit_barrier ();
4975 }
dfafc897 4976
dfafc897
FS
4977 emit_label (lab_false);
4978
a4f6c312 4979 /* ... otherwise out of the overflow area. */
dfafc897 4980
41daaf0e
AH
4981 /* Make sure we don't find reg 7 for the next int arg.
4982
4983 All AltiVec vectors go in the overflow area. So in the AltiVec
4984 case we need to get the vectors from the overflow area, but
4985 remember where the GPRs and FPRs are. */
16861f33
AH
4986 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
4987 || !TARGET_ALTIVEC))
dfafc897
FS
4988 {
4989 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
4990 TREE_SIDE_EFFECTS (t) = 1;
4991 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4992 }
4993
4994 /* Care for on-stack alignment if needed. */
4995 if (rsize <= 1)
4996 t = ovf;
4997 else
4998 {
41daaf0e
AH
4999 int align;
5000
16861f33
AH
5001 /* AltiVec vectors are 16 byte aligned. */
5002 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
5003 align = 15;
5004 else
5005 align = 7;
5006
5007 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
5008 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
5009 }
5010 t = save_expr (t);
5011
5012 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5013 if (r != addr_rtx)
5014 emit_move_insn (addr_rtx, r);
5015
5016 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
5017 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5018 TREE_SIDE_EFFECTS (t) = 1;
5019 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5020
5021 emit_label (lab_over);
5022
5023 if (indirect_p)
5024 {
5025 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 5026 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
5027 emit_move_insn (addr_rtx, r);
5028 }
5029
5030 return addr_rtx;
4697a36c 5031}
0ac081f6
AH
5032
5033/* Builtins. */
5034
6a2dd09a
RS
5035#define def_builtin(MASK, NAME, TYPE, CODE) \
5036do { \
5037 if ((MASK) & target_flags) \
5038 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5039 NULL, NULL_TREE); \
0ac081f6
AH
5040} while (0)
5041
24408032
AH
5042/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5043
2212663f 5044static const struct builtin_description bdesc_3arg[] =
24408032
AH
5045{
5046 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5047 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5048 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5049 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5050 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5051 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5052 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5053 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5054 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5055 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
5056 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
5057 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5058 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5059 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5060 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5061 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5062 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5063 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5064 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5065 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5066 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5067 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5068 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5069};
2212663f 5070
95385cbb
AH
5071/* DST operations: void foo (void *, const int, const char). */
5072
5073static const struct builtin_description bdesc_dst[] =
5074{
5075 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5076 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5077 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5078 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5079};
5080
2212663f 5081/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5082
a3170dc6 5083static struct builtin_description bdesc_2arg[] =
0ac081f6 5084{
f18c054f
DB
5085 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5086 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5087 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5088 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5089 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5090 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5091 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5092 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5093 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5094 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5095 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5096 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5097 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5098 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5099 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5100 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5101 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5102 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5103 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5104 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5105 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5106 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5107 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5108 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5109 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5110 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5111 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5112 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5113 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5114 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5115 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5116 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5117 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5118 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5119 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5120 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5121 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5122 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5123 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5124 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5125 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5126 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5127 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5128 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5129 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5130 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5131 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5132 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5133 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5134 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5135 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5136 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5137 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5138 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5139 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5140 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5141 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5142 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5143 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5144 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5145 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5146 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5147 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5148 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5149 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5150 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5151 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5152 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5153 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5154 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5155 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5156 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5157 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5158 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5159 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5160 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5161 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5162 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5163 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5164 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5165 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5166 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5167 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5168 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5169 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5170 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5171 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5172 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5173 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5174 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5175 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5176 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5177 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5178 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5179 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5180 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5181 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5182 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5183 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5184 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5185 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5186 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5187 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5188 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5189 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5190 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5191 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5192 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5193 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5194 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5195 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5196 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5197 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5198
5199 /* Place holder, leave as first spe builtin. */
5200 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5201 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5202 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5203 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5204 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5205 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5206 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5207 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5208 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5209 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5210 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5211 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5212 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5213 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5214 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5215 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5216 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5217 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5218 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5219 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5220 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5221 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5222 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5223 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5224 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5225 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5226 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5227 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5228 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5229 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5230 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5231 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5232 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5233 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5234 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5235 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5236 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5237 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5238 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5239 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5240 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5241 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5242 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5243 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5244 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5245 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5246 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5247 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5248 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5249 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5250 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5251 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5252 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5253 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5254 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5255 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5256 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5257 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5258 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5259 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5260 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5261 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5262 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5263 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5264 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5265 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5266 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5267 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5268 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5269 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5270 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5271 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5272 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5273 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5274 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5275 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5276 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5277 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5278 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5279 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5280 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5281 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5282 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5283 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5284 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5285 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5286 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5287 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5288 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5289 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5290 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5291 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5292 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5293 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5294 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5295 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5296 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5297 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5298 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5299 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5300 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5301 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5302 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5303 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5304 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5305 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5306 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5307 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5308 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5309
5310 /* SPE binary operations expecting a 5-bit unsigned literal. */
5311 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5312
5313 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5314 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5315 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5316 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5317 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5318 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5319 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5320 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5321 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5322 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5323 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5324 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5325 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5326 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5327 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5328 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5329 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5330 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5331 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5332 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5333 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5334 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5335 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5336 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5337 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5338 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5339
5340 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5341 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5342};
5343
5344/* AltiVec predicates. */
5345
5346struct builtin_description_predicates
5347{
5348 const unsigned int mask;
5349 const enum insn_code icode;
5350 const char *opcode;
5351 const char *const name;
5352 const enum rs6000_builtins code;
5353};
5354
5355static const struct builtin_description_predicates bdesc_altivec_preds[] =
5356{
5357 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5358 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5359 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5360 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5361 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5362 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5363 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5364 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5365 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5366 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5367 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5368 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5369 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5370};
24408032 5371
a3170dc6
AH
5372/* SPE predicates. */
5373static struct builtin_description bdesc_spe_predicates[] =
5374{
5375 /* Place-holder. Leave as first. */
5376 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5377 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5378 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5379 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5380 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5381 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5382 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5383 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5384 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5385 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5386 /* Place-holder. Leave as last. */
5387 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5388};
5389
5390/* SPE evsel predicates. */
5391static struct builtin_description bdesc_spe_evsel[] =
5392{
5393 /* Place-holder. Leave as first. */
5394 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5395 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5396 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5397 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5398 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5399 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5400 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5401 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5402 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5403 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5404 /* Place-holder. Leave as last. */
5405 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5406};
5407
b6d08ca1 5408/* ABS* operations. */
100c4561
AH
5409
5410static const struct builtin_description bdesc_abs[] =
5411{
5412 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5413 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5414 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5415 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5416 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5417 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5418 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5419};
5420
617e0e1d
DB
5421/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5422 foo (VECa). */
24408032 5423
a3170dc6 5424static struct builtin_description bdesc_1arg[] =
2212663f 5425{
617e0e1d
DB
5426 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5427 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5428 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5429 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5430 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5431 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5432 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5433 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5434 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5435 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5436 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5437 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5438 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5439 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5440 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5441 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5442 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5443
5444 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5445 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5446 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5447 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5448 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5449 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5450 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5451 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5452 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5453 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5454 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5455 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5456 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5457 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5458 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5459 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5460 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5461 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5462 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5463 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5464 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5465 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5466 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5467 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5468 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5469 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5470 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5471 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5472 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5473 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5474
5475 /* Place-holder. Leave as last unary SPE builtin. */
5476 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5477};
5478
5479static rtx
a2369ed3 5480rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5481{
5482 rtx pat;
5483 tree arg0 = TREE_VALUE (arglist);
5484 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5485 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5486 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5487
0559cc77
DE
5488 if (icode == CODE_FOR_nothing)
5489 /* Builtin not supported on this processor. */
5490 return 0;
5491
20e26713
AH
5492 /* If we got invalid arguments bail out before generating bad rtl. */
5493 if (arg0 == error_mark_node)
9a171fcd 5494 return const0_rtx;
20e26713 5495
0559cc77
DE
5496 if (icode == CODE_FOR_altivec_vspltisb
5497 || icode == CODE_FOR_altivec_vspltish
5498 || icode == CODE_FOR_altivec_vspltisw
5499 || icode == CODE_FOR_spe_evsplatfi
5500 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5501 {
5502 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5503 if (GET_CODE (op0) != CONST_INT
5504 || INTVAL (op0) > 0x1f
5505 || INTVAL (op0) < -0x1f)
5506 {
5507 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5508 return const0_rtx;
b44140e7 5509 }
b44140e7
AH
5510 }
5511
c62f2db5 5512 if (target == 0
2212663f
DB
5513 || GET_MODE (target) != tmode
5514 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5515 target = gen_reg_rtx (tmode);
5516
5517 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5518 op0 = copy_to_mode_reg (mode0, op0);
5519
5520 pat = GEN_FCN (icode) (target, op0);
5521 if (! pat)
5522 return 0;
5523 emit_insn (pat);
0ac081f6 5524
2212663f
DB
5525 return target;
5526}
ae4b4a02 5527
100c4561 5528static rtx
a2369ed3 5529altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5530{
5531 rtx pat, scratch1, scratch2;
5532 tree arg0 = TREE_VALUE (arglist);
5533 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5534 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5535 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5536
5537 /* If we have invalid arguments, bail out before generating bad rtl. */
5538 if (arg0 == error_mark_node)
9a171fcd 5539 return const0_rtx;
100c4561
AH
5540
5541 if (target == 0
5542 || GET_MODE (target) != tmode
5543 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5544 target = gen_reg_rtx (tmode);
5545
5546 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5547 op0 = copy_to_mode_reg (mode0, op0);
5548
5549 scratch1 = gen_reg_rtx (mode0);
5550 scratch2 = gen_reg_rtx (mode0);
5551
5552 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5553 if (! pat)
5554 return 0;
5555 emit_insn (pat);
5556
5557 return target;
5558}
5559
0ac081f6 5560static rtx
a2369ed3 5561rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5562{
5563 rtx pat;
5564 tree arg0 = TREE_VALUE (arglist);
5565 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5566 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5567 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5568 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5569 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5570 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5571
0559cc77
DE
5572 if (icode == CODE_FOR_nothing)
5573 /* Builtin not supported on this processor. */
5574 return 0;
5575
20e26713
AH
5576 /* If we got invalid arguments bail out before generating bad rtl. */
5577 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5578 return const0_rtx;
20e26713 5579
0559cc77
DE
5580 if (icode == CODE_FOR_altivec_vcfux
5581 || icode == CODE_FOR_altivec_vcfsx
5582 || icode == CODE_FOR_altivec_vctsxs
5583 || icode == CODE_FOR_altivec_vctuxs
5584 || icode == CODE_FOR_altivec_vspltb
5585 || icode == CODE_FOR_altivec_vsplth
5586 || icode == CODE_FOR_altivec_vspltw
5587 || icode == CODE_FOR_spe_evaddiw
5588 || icode == CODE_FOR_spe_evldd
5589 || icode == CODE_FOR_spe_evldh
5590 || icode == CODE_FOR_spe_evldw
5591 || icode == CODE_FOR_spe_evlhhesplat
5592 || icode == CODE_FOR_spe_evlhhossplat
5593 || icode == CODE_FOR_spe_evlhhousplat
5594 || icode == CODE_FOR_spe_evlwhe
5595 || icode == CODE_FOR_spe_evlwhos
5596 || icode == CODE_FOR_spe_evlwhou
5597 || icode == CODE_FOR_spe_evlwhsplat
5598 || icode == CODE_FOR_spe_evlwwsplat
5599 || icode == CODE_FOR_spe_evrlwi
5600 || icode == CODE_FOR_spe_evslwi
5601 || icode == CODE_FOR_spe_evsrwis
f5119d10 5602 || icode == CODE_FOR_spe_evsubifw
0559cc77 5603 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5604 {
5605 /* Only allow 5-bit unsigned literals. */
8bb418a3 5606 STRIP_NOPS (arg1);
b44140e7
AH
5607 if (TREE_CODE (arg1) != INTEGER_CST
5608 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5609 {
5610 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5611 return const0_rtx;
b44140e7 5612 }
b44140e7
AH
5613 }
5614
c62f2db5 5615 if (target == 0
0ac081f6
AH
5616 || GET_MODE (target) != tmode
5617 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5618 target = gen_reg_rtx (tmode);
5619
5620 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5621 op0 = copy_to_mode_reg (mode0, op0);
5622 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5623 op1 = copy_to_mode_reg (mode1, op1);
5624
5625 pat = GEN_FCN (icode) (target, op0, op1);
5626 if (! pat)
5627 return 0;
5628 emit_insn (pat);
5629
5630 return target;
5631}
6525c0e7 5632
ae4b4a02 5633static rtx
a2369ed3
DJ
5634altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5635 tree arglist, rtx target)
ae4b4a02
AH
5636{
5637 rtx pat, scratch;
5638 tree cr6_form = TREE_VALUE (arglist);
5639 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5640 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5641 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5642 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5643 enum machine_mode tmode = SImode;
5644 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5645 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5646 int cr6_form_int;
5647
5648 if (TREE_CODE (cr6_form) != INTEGER_CST)
5649 {
5650 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5651 return const0_rtx;
ae4b4a02
AH
5652 }
5653 else
5654 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5655
5656 if (mode0 != mode1)
5657 abort ();
5658
5659 /* If we have invalid arguments, bail out before generating bad rtl. */
5660 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5661 return const0_rtx;
ae4b4a02
AH
5662
5663 if (target == 0
5664 || GET_MODE (target) != tmode
5665 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5666 target = gen_reg_rtx (tmode);
5667
5668 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5669 op0 = copy_to_mode_reg (mode0, op0);
5670 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5671 op1 = copy_to_mode_reg (mode1, op1);
5672
5673 scratch = gen_reg_rtx (mode0);
5674
5675 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5676 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5677 if (! pat)
5678 return 0;
5679 emit_insn (pat);
5680
5681 /* The vec_any* and vec_all* predicates use the same opcodes for two
5682 different operations, but the bits in CR6 will be different
5683 depending on what information we want. So we have to play tricks
5684 with CR6 to get the right bits out.
5685
5686 If you think this is disgusting, look at the specs for the
5687 AltiVec predicates. */
5688
5689 switch (cr6_form_int)
5690 {
5691 case 0:
5692 emit_insn (gen_cr6_test_for_zero (target));
5693 break;
5694 case 1:
5695 emit_insn (gen_cr6_test_for_zero_reverse (target));
5696 break;
5697 case 2:
5698 emit_insn (gen_cr6_test_for_lt (target));
5699 break;
5700 case 3:
5701 emit_insn (gen_cr6_test_for_lt_reverse (target));
5702 break;
5703 default:
5704 error ("argument 1 of __builtin_altivec_predicate is out of range");
5705 break;
5706 }
5707
5708 return target;
5709}
5710
b4a62fa0 5711static rtx
38f391a5 5712altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5713{
5714 rtx pat, addr;
5715 tree arg0 = TREE_VALUE (arglist);
5716 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5717 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5718 enum machine_mode mode0 = Pmode;
5719 enum machine_mode mode1 = Pmode;
5720 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5721 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5722
5723 if (icode == CODE_FOR_nothing)
5724 /* Builtin not supported on this processor. */
5725 return 0;
5726
5727 /* If we got invalid arguments bail out before generating bad rtl. */
5728 if (arg0 == error_mark_node || arg1 == error_mark_node)
5729 return const0_rtx;
5730
5731 if (target == 0
5732 || GET_MODE (target) != tmode
5733 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5734 target = gen_reg_rtx (tmode);
5735
5736 op1 = copy_to_mode_reg (mode1, op1);
5737
5738 if (op0 == const0_rtx)
5739 {
5740 addr = gen_rtx_MEM (tmode, op1);
5741 }
5742 else
5743 {
5744 op0 = copy_to_mode_reg (mode0, op0);
5745 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5746 }
5747
5748 pat = GEN_FCN (icode) (target, addr);
5749
5750 if (! pat)
5751 return 0;
5752 emit_insn (pat);
5753
5754 return target;
5755}
5756
6525c0e7 5757static rtx
a2369ed3 5758altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5759{
5760 tree arg0 = TREE_VALUE (arglist);
5761 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5762 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5763 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5764 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5765 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
5766 rtx pat, addr;
5767 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5768 enum machine_mode mode1 = Pmode;
5769 enum machine_mode mode2 = Pmode;
6525c0e7
AH
5770
5771 /* Invalid arguments. Bail before doing anything stoopid! */
5772 if (arg0 == error_mark_node
5773 || arg1 == error_mark_node
5774 || arg2 == error_mark_node)
9a171fcd 5775 return const0_rtx;
6525c0e7 5776
b4a62fa0
SB
5777 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
5778 op0 = copy_to_mode_reg (tmode, op0);
5779
5780 op2 = copy_to_mode_reg (mode2, op2);
5781
5782 if (op1 == const0_rtx)
5783 {
5784 addr = gen_rtx_MEM (tmode, op2);
5785 }
5786 else
5787 {
5788 op1 = copy_to_mode_reg (mode1, op1);
5789 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
5790 }
6525c0e7 5791
b4a62fa0 5792 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
5793 if (pat)
5794 emit_insn (pat);
5795 return NULL_RTX;
5796}
5797
2212663f 5798static rtx
a2369ed3 5799rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5800{
5801 rtx pat;
5802 tree arg0 = TREE_VALUE (arglist);
5803 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5804 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5805 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5806 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5807 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5808 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5809 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5810 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5811 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5812
774b5662
DE
5813 if (icode == CODE_FOR_nothing)
5814 /* Builtin not supported on this processor. */
5815 return 0;
5816
20e26713
AH
5817 /* If we got invalid arguments bail out before generating bad rtl. */
5818 if (arg0 == error_mark_node
5819 || arg1 == error_mark_node
5820 || arg2 == error_mark_node)
9a171fcd 5821 return const0_rtx;
20e26713 5822
774b5662
DE
5823 if (icode == CODE_FOR_altivec_vsldoi_4sf
5824 || icode == CODE_FOR_altivec_vsldoi_4si
5825 || icode == CODE_FOR_altivec_vsldoi_8hi
5826 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5827 {
5828 /* Only allow 4-bit unsigned literals. */
8bb418a3 5829 STRIP_NOPS (arg2);
b44140e7
AH
5830 if (TREE_CODE (arg2) != INTEGER_CST
5831 || TREE_INT_CST_LOW (arg2) & ~0xf)
5832 {
5833 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5834 return const0_rtx;
b44140e7 5835 }
b44140e7
AH
5836 }
5837
c62f2db5 5838 if (target == 0
2212663f
DB
5839 || GET_MODE (target) != tmode
5840 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5841 target = gen_reg_rtx (tmode);
5842
5843 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5844 op0 = copy_to_mode_reg (mode0, op0);
5845 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5846 op1 = copy_to_mode_reg (mode1, op1);
5847 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5848 op2 = copy_to_mode_reg (mode2, op2);
5849
5850 pat = GEN_FCN (icode) (target, op0, op1, op2);
5851 if (! pat)
5852 return 0;
5853 emit_insn (pat);
5854
5855 return target;
5856}
92898235 5857
3a9b8c7e 5858/* Expand the lvx builtins. */
0ac081f6 5859static rtx
a2369ed3 5860altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5861{
0ac081f6
AH
5862 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5863 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5864 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5865 tree arg0;
5866 enum machine_mode tmode, mode0;
7c3abc73 5867 rtx pat, op0;
3a9b8c7e 5868 enum insn_code icode;
92898235 5869
0ac081f6
AH
5870 switch (fcode)
5871 {
f18c054f
DB
5872 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5873 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5874 break;
f18c054f
DB
5875 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5876 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5877 break;
5878 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5879 icode = CODE_FOR_altivec_lvx_4si;
5880 break;
5881 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5882 icode = CODE_FOR_altivec_lvx_4sf;
5883 break;
5884 default:
5885 *expandedp = false;
5886 return NULL_RTX;
5887 }
0ac081f6 5888
3a9b8c7e 5889 *expandedp = true;
f18c054f 5890
3a9b8c7e
AH
5891 arg0 = TREE_VALUE (arglist);
5892 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5893 tmode = insn_data[icode].operand[0].mode;
5894 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5895
3a9b8c7e
AH
5896 if (target == 0
5897 || GET_MODE (target) != tmode
5898 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5899 target = gen_reg_rtx (tmode);
24408032 5900
3a9b8c7e
AH
5901 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5902 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5903
3a9b8c7e
AH
5904 pat = GEN_FCN (icode) (target, op0);
5905 if (! pat)
5906 return 0;
5907 emit_insn (pat);
5908 return target;
5909}
f18c054f 5910
3a9b8c7e
AH
5911/* Expand the stvx builtins. */
5912static rtx
a2369ed3
DJ
5913altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5914 bool *expandedp)
3a9b8c7e
AH
5915{
5916 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5917 tree arglist = TREE_OPERAND (exp, 1);
5918 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5919 tree arg0, arg1;
5920 enum machine_mode mode0, mode1;
7c3abc73 5921 rtx pat, op0, op1;
3a9b8c7e 5922 enum insn_code icode;
f18c054f 5923
3a9b8c7e
AH
5924 switch (fcode)
5925 {
5926 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5927 icode = CODE_FOR_altivec_stvx_16qi;
5928 break;
5929 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5930 icode = CODE_FOR_altivec_stvx_8hi;
5931 break;
5932 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5933 icode = CODE_FOR_altivec_stvx_4si;
5934 break;
5935 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5936 icode = CODE_FOR_altivec_stvx_4sf;
5937 break;
5938 default:
5939 *expandedp = false;
5940 return NULL_RTX;
5941 }
24408032 5942
3a9b8c7e
AH
5943 arg0 = TREE_VALUE (arglist);
5944 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5945 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5946 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5947 mode0 = insn_data[icode].operand[0].mode;
5948 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5949
3a9b8c7e
AH
5950 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5951 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5952 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5953 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5954
3a9b8c7e
AH
5955 pat = GEN_FCN (icode) (op0, op1);
5956 if (pat)
5957 emit_insn (pat);
f18c054f 5958
3a9b8c7e
AH
5959 *expandedp = true;
5960 return NULL_RTX;
5961}
f18c054f 5962
3a9b8c7e
AH
5963/* Expand the dst builtins. */
5964static rtx
a2369ed3
DJ
5965altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5966 bool *expandedp)
3a9b8c7e
AH
5967{
5968 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5969 tree arglist = TREE_OPERAND (exp, 1);
5970 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5971 tree arg0, arg1, arg2;
5972 enum machine_mode mode0, mode1, mode2;
7c3abc73 5973 rtx pat, op0, op1, op2;
3a9b8c7e 5974 struct builtin_description *d;
a3170dc6 5975 size_t i;
f18c054f 5976
3a9b8c7e 5977 *expandedp = false;
f18c054f 5978
3a9b8c7e
AH
5979 /* Handle DST variants. */
5980 d = (struct builtin_description *) bdesc_dst;
5981 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
5982 if (d->code == fcode)
5983 {
5984 arg0 = TREE_VALUE (arglist);
5985 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5986 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5987 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5988 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5989 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5990 mode0 = insn_data[d->icode].operand[0].mode;
5991 mode1 = insn_data[d->icode].operand[1].mode;
5992 mode2 = insn_data[d->icode].operand[2].mode;
24408032 5993
3a9b8c7e
AH
5994 /* Invalid arguments, bail out before generating bad rtl. */
5995 if (arg0 == error_mark_node
5996 || arg1 == error_mark_node
5997 || arg2 == error_mark_node)
5998 return const0_rtx;
f18c054f 5999
8bb418a3 6000 STRIP_NOPS (arg2);
3a9b8c7e
AH
6001 if (TREE_CODE (arg2) != INTEGER_CST
6002 || TREE_INT_CST_LOW (arg2) & ~0x3)
6003 {
6004 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6005 return const0_rtx;
6006 }
f18c054f 6007
3a9b8c7e 6008 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6009 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6010 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6011 op1 = copy_to_mode_reg (mode1, op1);
24408032 6012
3a9b8c7e
AH
6013 pat = GEN_FCN (d->icode) (op0, op1, op2);
6014 if (pat != 0)
6015 emit_insn (pat);
f18c054f 6016
3a9b8c7e
AH
6017 *expandedp = true;
6018 return NULL_RTX;
6019 }
f18c054f 6020
3a9b8c7e
AH
6021 return NULL_RTX;
6022}
24408032 6023
3a9b8c7e
AH
6024/* Expand the builtin in EXP and store the result in TARGET. Store
6025 true in *EXPANDEDP if we found a builtin to expand. */
6026static rtx
a2369ed3 6027altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6028{
6029 struct builtin_description *d;
6030 struct builtin_description_predicates *dp;
6031 size_t i;
6032 enum insn_code icode;
6033 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6034 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6035 tree arg0;
6036 rtx op0, pat;
6037 enum machine_mode tmode, mode0;
3a9b8c7e 6038 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6039
3a9b8c7e
AH
6040 target = altivec_expand_ld_builtin (exp, target, expandedp);
6041 if (*expandedp)
6042 return target;
0ac081f6 6043
3a9b8c7e
AH
6044 target = altivec_expand_st_builtin (exp, target, expandedp);
6045 if (*expandedp)
6046 return target;
6047
6048 target = altivec_expand_dst_builtin (exp, target, expandedp);
6049 if (*expandedp)
6050 return target;
6051
6052 *expandedp = true;
95385cbb 6053
3a9b8c7e
AH
6054 switch (fcode)
6055 {
6525c0e7
AH
6056 case ALTIVEC_BUILTIN_STVX:
6057 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6058 case ALTIVEC_BUILTIN_STVEBX:
6059 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6060 case ALTIVEC_BUILTIN_STVEHX:
6061 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6062 case ALTIVEC_BUILTIN_STVEWX:
6063 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6064 case ALTIVEC_BUILTIN_STVXL:
6065 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6066
95385cbb
AH
6067 case ALTIVEC_BUILTIN_MFVSCR:
6068 icode = CODE_FOR_altivec_mfvscr;
6069 tmode = insn_data[icode].operand[0].mode;
6070
6071 if (target == 0
6072 || GET_MODE (target) != tmode
6073 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6074 target = gen_reg_rtx (tmode);
6075
6076 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6077 if (! pat)
6078 return 0;
6079 emit_insn (pat);
95385cbb
AH
6080 return target;
6081
6082 case ALTIVEC_BUILTIN_MTVSCR:
6083 icode = CODE_FOR_altivec_mtvscr;
6084 arg0 = TREE_VALUE (arglist);
6085 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6086 mode0 = insn_data[icode].operand[0].mode;
6087
6088 /* If we got invalid arguments bail out before generating bad rtl. */
6089 if (arg0 == error_mark_node)
9a171fcd 6090 return const0_rtx;
95385cbb
AH
6091
6092 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6093 op0 = copy_to_mode_reg (mode0, op0);
6094
6095 pat = GEN_FCN (icode) (op0);
6096 if (pat)
6097 emit_insn (pat);
6098 return NULL_RTX;
3a9b8c7e 6099
95385cbb
AH
6100 case ALTIVEC_BUILTIN_DSSALL:
6101 emit_insn (gen_altivec_dssall ());
6102 return NULL_RTX;
6103
6104 case ALTIVEC_BUILTIN_DSS:
6105 icode = CODE_FOR_altivec_dss;
6106 arg0 = TREE_VALUE (arglist);
8bb418a3 6107 STRIP_NOPS (arg0);
95385cbb
AH
6108 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6109 mode0 = insn_data[icode].operand[0].mode;
6110
6111 /* If we got invalid arguments bail out before generating bad rtl. */
6112 if (arg0 == error_mark_node)
9a171fcd 6113 return const0_rtx;
95385cbb 6114
b44140e7
AH
6115 if (TREE_CODE (arg0) != INTEGER_CST
6116 || TREE_INT_CST_LOW (arg0) & ~0x3)
6117 {
6118 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6119 return const0_rtx;
b44140e7
AH
6120 }
6121
95385cbb
AH
6122 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6123 op0 = copy_to_mode_reg (mode0, op0);
6124
6125 emit_insn (gen_altivec_dss (op0));
0ac081f6 6126 return NULL_RTX;
8bb418a3
ZL
6127
6128 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6129 arg0 = TREE_VALUE (arglist);
6130 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR)
6131 arg0 = TREE_OPERAND (arg0, 0);
6132 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6133 TREE_STRING_POINTER (arg0));
6134
6135 return const0_rtx;
0ac081f6 6136 }
24408032 6137
100c4561
AH
6138 /* Expand abs* operations. */
6139 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6140 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6141 if (d->code == fcode)
6142 return altivec_expand_abs_builtin (d->icode, arglist, target);
6143
ae4b4a02
AH
6144 /* Expand the AltiVec predicates. */
6145 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6146 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6147 if (dp->code == fcode)
6148 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6149
6525c0e7
AH
6150 /* LV* are funky. We initialized them differently. */
6151 switch (fcode)
6152 {
6153 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6154 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6155 arglist, target);
6156 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6157 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6158 arglist, target);
6525c0e7 6159 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6160 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6161 arglist, target);
6525c0e7 6162 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6163 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6164 arglist, target);
6525c0e7 6165 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6166 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6167 arglist, target);
6525c0e7 6168 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6169 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6170 arglist, target);
6525c0e7 6171 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6172 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6173 arglist, target);
6525c0e7
AH
6174 default:
6175 break;
6176 /* Fall through. */
6177 }
95385cbb 6178
92898235 6179 *expandedp = false;
0ac081f6
AH
6180 return NULL_RTX;
6181}
6182
a3170dc6
AH
6183/* Binops that need to be initialized manually, but can be expanded
6184 automagically by rs6000_expand_binop_builtin. */
6185static struct builtin_description bdesc_2arg_spe[] =
6186{
6187 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6188 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6189 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6190 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6191 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6192 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6193 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6194 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6195 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6196 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6197 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6198 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6199 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6200 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6201 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6202 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6203 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6204 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6205 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6206 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6207 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6208 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6209};
6210
6211/* Expand the builtin in EXP and store the result in TARGET. Store
6212 true in *EXPANDEDP if we found a builtin to expand.
6213
6214 This expands the SPE builtins that are not simple unary and binary
6215 operations. */
6216static rtx
a2369ed3 6217spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6218{
6219 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6220 tree arglist = TREE_OPERAND (exp, 1);
6221 tree arg1, arg0;
6222 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6223 enum insn_code icode;
6224 enum machine_mode tmode, mode0;
6225 rtx pat, op0;
6226 struct builtin_description *d;
6227 size_t i;
6228
6229 *expandedp = true;
6230
6231 /* Syntax check for a 5-bit unsigned immediate. */
6232 switch (fcode)
6233 {
6234 case SPE_BUILTIN_EVSTDD:
6235 case SPE_BUILTIN_EVSTDH:
6236 case SPE_BUILTIN_EVSTDW:
6237 case SPE_BUILTIN_EVSTWHE:
6238 case SPE_BUILTIN_EVSTWHO:
6239 case SPE_BUILTIN_EVSTWWE:
6240 case SPE_BUILTIN_EVSTWWO:
6241 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6242 if (TREE_CODE (arg1) != INTEGER_CST
6243 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6244 {
6245 error ("argument 2 must be a 5-bit unsigned literal");
6246 return const0_rtx;
6247 }
6248 break;
6249 default:
6250 break;
6251 }
6252
00332c9f
AH
6253 /* The evsplat*i instructions are not quite generic. */
6254 switch (fcode)
6255 {
6256 case SPE_BUILTIN_EVSPLATFI:
6257 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6258 arglist, target);
6259 case SPE_BUILTIN_EVSPLATI:
6260 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6261 arglist, target);
6262 default:
6263 break;
6264 }
6265
a3170dc6
AH
6266 d = (struct builtin_description *) bdesc_2arg_spe;
6267 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6268 if (d->code == fcode)
6269 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6270
6271 d = (struct builtin_description *) bdesc_spe_predicates;
6272 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6273 if (d->code == fcode)
6274 return spe_expand_predicate_builtin (d->icode, arglist, target);
6275
6276 d = (struct builtin_description *) bdesc_spe_evsel;
6277 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6278 if (d->code == fcode)
6279 return spe_expand_evsel_builtin (d->icode, arglist, target);
6280
6281 switch (fcode)
6282 {
6283 case SPE_BUILTIN_EVSTDDX:
6284 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6285 case SPE_BUILTIN_EVSTDHX:
6286 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6287 case SPE_BUILTIN_EVSTDWX:
6288 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6289 case SPE_BUILTIN_EVSTWHEX:
6290 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6291 case SPE_BUILTIN_EVSTWHOX:
6292 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6293 case SPE_BUILTIN_EVSTWWEX:
6294 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6295 case SPE_BUILTIN_EVSTWWOX:
6296 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6297 case SPE_BUILTIN_EVSTDD:
6298 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6299 case SPE_BUILTIN_EVSTDH:
6300 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6301 case SPE_BUILTIN_EVSTDW:
6302 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6303 case SPE_BUILTIN_EVSTWHE:
6304 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6305 case SPE_BUILTIN_EVSTWHO:
6306 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6307 case SPE_BUILTIN_EVSTWWE:
6308 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6309 case SPE_BUILTIN_EVSTWWO:
6310 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6311 case SPE_BUILTIN_MFSPEFSCR:
6312 icode = CODE_FOR_spe_mfspefscr;
6313 tmode = insn_data[icode].operand[0].mode;
6314
6315 if (target == 0
6316 || GET_MODE (target) != tmode
6317 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6318 target = gen_reg_rtx (tmode);
6319
6320 pat = GEN_FCN (icode) (target);
6321 if (! pat)
6322 return 0;
6323 emit_insn (pat);
6324 return target;
6325 case SPE_BUILTIN_MTSPEFSCR:
6326 icode = CODE_FOR_spe_mtspefscr;
6327 arg0 = TREE_VALUE (arglist);
6328 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6329 mode0 = insn_data[icode].operand[0].mode;
6330
6331 if (arg0 == error_mark_node)
6332 return const0_rtx;
6333
6334 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6335 op0 = copy_to_mode_reg (mode0, op0);
6336
6337 pat = GEN_FCN (icode) (op0);
6338 if (pat)
6339 emit_insn (pat);
6340 return NULL_RTX;
6341 default:
6342 break;
6343 }
6344
6345 *expandedp = false;
6346 return NULL_RTX;
6347}
6348
6349static rtx
a2369ed3 6350spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6351{
6352 rtx pat, scratch, tmp;
6353 tree form = TREE_VALUE (arglist);
6354 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6355 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6356 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6357 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6358 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6359 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6360 int form_int;
6361 enum rtx_code code;
6362
6363 if (TREE_CODE (form) != INTEGER_CST)
6364 {
6365 error ("argument 1 of __builtin_spe_predicate must be a constant");
6366 return const0_rtx;
6367 }
6368 else
6369 form_int = TREE_INT_CST_LOW (form);
6370
6371 if (mode0 != mode1)
6372 abort ();
6373
6374 if (arg0 == error_mark_node || arg1 == error_mark_node)
6375 return const0_rtx;
6376
6377 if (target == 0
6378 || GET_MODE (target) != SImode
6379 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6380 target = gen_reg_rtx (SImode);
6381
6382 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6383 op0 = copy_to_mode_reg (mode0, op0);
6384 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6385 op1 = copy_to_mode_reg (mode1, op1);
6386
6387 scratch = gen_reg_rtx (CCmode);
6388
6389 pat = GEN_FCN (icode) (scratch, op0, op1);
6390 if (! pat)
6391 return const0_rtx;
6392 emit_insn (pat);
6393
6394 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6395 _lower_. We use one compare, but look in different bits of the
6396 CR for each variant.
6397
6398 There are 2 elements in each SPE simd type (upper/lower). The CR
6399 bits are set as follows:
6400
6401 BIT0 | BIT 1 | BIT 2 | BIT 3
6402 U | L | (U | L) | (U & L)
6403
6404 So, for an "all" relationship, BIT 3 would be set.
6405 For an "any" relationship, BIT 2 would be set. Etc.
6406
6407 Following traditional nomenclature, these bits map to:
6408
6409 BIT0 | BIT 1 | BIT 2 | BIT 3
6410 LT | GT | EQ | OV
6411
6412 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6413 */
6414
6415 switch (form_int)
6416 {
6417 /* All variant. OV bit. */
6418 case 0:
6419 /* We need to get to the OV bit, which is the ORDERED bit. We
6420 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6421 that's ugly and will trigger a validate_condition_mode abort.
6422 So let's just use another pattern. */
6423 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6424 return target;
6425 /* Any variant. EQ bit. */
6426 case 1:
6427 code = EQ;
6428 break;
6429 /* Upper variant. LT bit. */
6430 case 2:
6431 code = LT;
6432 break;
6433 /* Lower variant. GT bit. */
6434 case 3:
6435 code = GT;
6436 break;
6437 default:
6438 error ("argument 1 of __builtin_spe_predicate is out of range");
6439 return const0_rtx;
6440 }
6441
6442 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6443 emit_move_insn (target, tmp);
6444
6445 return target;
6446}
6447
6448/* The evsel builtins look like this:
6449
6450 e = __builtin_spe_evsel_OP (a, b, c, d);
6451
6452 and work like this:
6453
6454 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6455 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6456*/
6457
6458static rtx
a2369ed3 6459spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6460{
6461 rtx pat, scratch;
6462 tree arg0 = TREE_VALUE (arglist);
6463 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6464 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6465 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6466 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6467 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6468 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6469 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6470 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6471 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6472
6473 if (mode0 != mode1)
6474 abort ();
6475
6476 if (arg0 == error_mark_node || arg1 == error_mark_node
6477 || arg2 == error_mark_node || arg3 == error_mark_node)
6478 return const0_rtx;
6479
6480 if (target == 0
6481 || GET_MODE (target) != mode0
6482 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6483 target = gen_reg_rtx (mode0);
6484
6485 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6486 op0 = copy_to_mode_reg (mode0, op0);
6487 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6488 op1 = copy_to_mode_reg (mode0, op1);
6489 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6490 op2 = copy_to_mode_reg (mode0, op2);
6491 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6492 op3 = copy_to_mode_reg (mode0, op3);
6493
6494 /* Generate the compare. */
6495 scratch = gen_reg_rtx (CCmode);
6496 pat = GEN_FCN (icode) (scratch, op0, op1);
6497 if (! pat)
6498 return const0_rtx;
6499 emit_insn (pat);
6500
6501 if (mode0 == V2SImode)
6502 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6503 else
6504 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6505
6506 return target;
6507}
6508
0ac081f6
AH
6509/* Expand an expression EXP that calls a built-in function,
6510 with result going to TARGET if that's convenient
6511 (and in mode MODE if that's convenient).
6512 SUBTARGET may be used as the target for computing one of EXP's operands.
6513 IGNORE is nonzero if the value is to be ignored. */
6514
6515static rtx
a2369ed3
DJ
6516rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6517 enum machine_mode mode ATTRIBUTE_UNUSED,
6518 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6519{
92898235
AH
6520 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6521 tree arglist = TREE_OPERAND (exp, 1);
6522 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6523 struct builtin_description *d;
6524 size_t i;
6525 rtx ret;
6526 bool success;
6527
0ac081f6 6528 if (TARGET_ALTIVEC)
92898235
AH
6529 {
6530 ret = altivec_expand_builtin (exp, target, &success);
6531
a3170dc6
AH
6532 if (success)
6533 return ret;
6534 }
6535 if (TARGET_SPE)
6536 {
6537 ret = spe_expand_builtin (exp, target, &success);
6538
92898235
AH
6539 if (success)
6540 return ret;
6541 }
6542
0559cc77
DE
6543 if (TARGET_ALTIVEC || TARGET_SPE)
6544 {
6545 /* Handle simple unary operations. */
6546 d = (struct builtin_description *) bdesc_1arg;
6547 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6548 if (d->code == fcode)
6549 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6550
6551 /* Handle simple binary operations. */
6552 d = (struct builtin_description *) bdesc_2arg;
6553 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6554 if (d->code == fcode)
6555 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6556
6557 /* Handle simple ternary operations. */
6558 d = (struct builtin_description *) bdesc_3arg;
6559 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6560 if (d->code == fcode)
6561 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6562 }
0ac081f6
AH
6563
6564 abort ();
92898235 6565 return NULL_RTX;
0ac081f6
AH
6566}
6567
6568static void
863d938c 6569rs6000_init_builtins (void)
0ac081f6 6570{
3fdaa45a
AH
6571 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6572 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6573 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6574
8bb418a3
ZL
6575 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
6576 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
6577 'vector unsigned short'. */
6578
6579 bool_char_type_node = copy_node (unsigned_intQI_type_node);
6580 TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node;
6581 bool_short_type_node = copy_node (unsigned_intHI_type_node);
6582 TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node;
6583 bool_int_type_node = copy_node (unsigned_intSI_type_node);
6584 TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node;
6585 pixel_type_node = copy_node (unsigned_intHI_type_node);
6586 TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node;
6587
6588 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6589 get_identifier ("__bool char"),
6590 bool_char_type_node));
6591 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6592 get_identifier ("__bool short"),
6593 bool_short_type_node));
6594 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6595 get_identifier ("__bool int"),
6596 bool_int_type_node));
6597 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6598 get_identifier ("__pixel"),
6599 pixel_type_node));
6600
6601 bool_V16QI_type_node = make_vector (V16QImode, bool_char_type_node, 1);
6602 bool_V8HI_type_node = make_vector (V8HImode, bool_short_type_node, 1);
6603 bool_V4SI_type_node = make_vector (V4SImode, bool_int_type_node, 1);
6604 pixel_V8HI_type_node = make_vector (V8HImode, pixel_type_node, 1);
6605
6606 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6607 get_identifier ("__vector unsigned char"),
6608 unsigned_V16QI_type_node));
6609 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6610 get_identifier ("__vector signed char"),
6611 V16QI_type_node));
6612 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6613 get_identifier ("__vector __bool char"),
6614 bool_V16QI_type_node));
6615
6616 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6617 get_identifier ("__vector unsigned short"),
6618 unsigned_V8HI_type_node));
6619 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6620 get_identifier ("__vector signed short"),
6621 V8HI_type_node));
6622 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6623 get_identifier ("__vector __bool short"),
6624 bool_V8HI_type_node));
6625
6626 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6627 get_identifier ("__vector unsigned int"),
6628 unsigned_V4SI_type_node));
6629 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6630 get_identifier ("__vector signed int"),
6631 V4SI_type_node));
6632 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6633 get_identifier ("__vector __bool int"),
6634 bool_V4SI_type_node));
6635
6636 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6637 get_identifier ("__vector float"),
6638 V4SF_type_node));
6639 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6640 get_identifier ("__vector __pixel"),
6641 pixel_V8HI_type_node));
6642
a3170dc6 6643 if (TARGET_SPE)
3fdaa45a 6644 spe_init_builtins ();
0ac081f6
AH
6645 if (TARGET_ALTIVEC)
6646 altivec_init_builtins ();
0559cc77
DE
6647 if (TARGET_ALTIVEC || TARGET_SPE)
6648 rs6000_common_init_builtins ();
0ac081f6
AH
6649}
6650
a3170dc6
AH
6651/* Search through a set of builtins and enable the mask bits.
6652 DESC is an array of builtins.
b6d08ca1 6653 SIZE is the total number of builtins.
a3170dc6
AH
6654 START is the builtin enum at which to start.
6655 END is the builtin enum at which to end. */
0ac081f6 6656static void
a2369ed3
DJ
6657enable_mask_for_builtins (struct builtin_description *desc, int size,
6658 enum rs6000_builtins start,
6659 enum rs6000_builtins end)
a3170dc6
AH
6660{
6661 int i;
6662
6663 for (i = 0; i < size; ++i)
6664 if (desc[i].code == start)
6665 break;
6666
6667 if (i == size)
6668 return;
6669
6670 for (; i < size; ++i)
6671 {
6672 /* Flip all the bits on. */
6673 desc[i].mask = target_flags;
6674 if (desc[i].code == end)
6675 break;
6676 }
6677}
6678
6679static void
863d938c 6680spe_init_builtins (void)
0ac081f6 6681{
a3170dc6
AH
6682 tree endlink = void_list_node;
6683 tree puint_type_node = build_pointer_type (unsigned_type_node);
6684 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6685 struct builtin_description *d;
0ac081f6
AH
6686 size_t i;
6687
a3170dc6
AH
6688 tree v2si_ftype_4_v2si
6689 = build_function_type
3fdaa45a
AH
6690 (opaque_V2SI_type_node,
6691 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6692 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6693 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6694 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6695 endlink)))));
6696
6697 tree v2sf_ftype_4_v2sf
6698 = build_function_type
3fdaa45a
AH
6699 (opaque_V2SF_type_node,
6700 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6701 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6702 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6703 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6704 endlink)))));
6705
6706 tree int_ftype_int_v2si_v2si
6707 = build_function_type
6708 (integer_type_node,
6709 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6710 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6711 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6712 endlink))));
6713
6714 tree int_ftype_int_v2sf_v2sf
6715 = build_function_type
6716 (integer_type_node,
6717 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6718 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6719 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6720 endlink))));
6721
6722 tree void_ftype_v2si_puint_int
6723 = build_function_type (void_type_node,
3fdaa45a 6724 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6725 tree_cons (NULL_TREE, puint_type_node,
6726 tree_cons (NULL_TREE,
6727 integer_type_node,
6728 endlink))));
6729
6730 tree void_ftype_v2si_puint_char
6731 = build_function_type (void_type_node,
3fdaa45a 6732 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6733 tree_cons (NULL_TREE, puint_type_node,
6734 tree_cons (NULL_TREE,
6735 char_type_node,
6736 endlink))));
6737
6738 tree void_ftype_v2si_pv2si_int
6739 = build_function_type (void_type_node,
3fdaa45a 6740 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6741 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6742 tree_cons (NULL_TREE,
6743 integer_type_node,
6744 endlink))));
6745
6746 tree void_ftype_v2si_pv2si_char
6747 = build_function_type (void_type_node,
3fdaa45a 6748 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6749 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6750 tree_cons (NULL_TREE,
6751 char_type_node,
6752 endlink))));
6753
6754 tree void_ftype_int
6755 = build_function_type (void_type_node,
6756 tree_cons (NULL_TREE, integer_type_node, endlink));
6757
6758 tree int_ftype_void
36e8d515 6759 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6760
6761 tree v2si_ftype_pv2si_int
3fdaa45a 6762 = build_function_type (opaque_V2SI_type_node,
6035d635 6763 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6764 tree_cons (NULL_TREE, integer_type_node,
6765 endlink)));
6766
6767 tree v2si_ftype_puint_int
3fdaa45a 6768 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6769 tree_cons (NULL_TREE, puint_type_node,
6770 tree_cons (NULL_TREE, integer_type_node,
6771 endlink)));
6772
6773 tree v2si_ftype_pushort_int
3fdaa45a 6774 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6775 tree_cons (NULL_TREE, pushort_type_node,
6776 tree_cons (NULL_TREE, integer_type_node,
6777 endlink)));
6778
00332c9f
AH
6779 tree v2si_ftype_signed_char
6780 = build_function_type (opaque_V2SI_type_node,
6781 tree_cons (NULL_TREE, signed_char_type_node,
6782 endlink));
6783
a3170dc6
AH
6784 /* The initialization of the simple binary and unary builtins is
6785 done in rs6000_common_init_builtins, but we have to enable the
6786 mask bits here manually because we have run out of `target_flags'
6787 bits. We really need to redesign this mask business. */
6788
6789 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6790 ARRAY_SIZE (bdesc_2arg),
6791 SPE_BUILTIN_EVADDW,
6792 SPE_BUILTIN_EVXOR);
6793 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6794 ARRAY_SIZE (bdesc_1arg),
6795 SPE_BUILTIN_EVABS,
6796 SPE_BUILTIN_EVSUBFUSIAAW);
6797 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6798 ARRAY_SIZE (bdesc_spe_predicates),
6799 SPE_BUILTIN_EVCMPEQ,
6800 SPE_BUILTIN_EVFSTSTLT);
6801 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6802 ARRAY_SIZE (bdesc_spe_evsel),
6803 SPE_BUILTIN_EVSEL_CMPGTS,
6804 SPE_BUILTIN_EVSEL_FSTSTEQ);
6805
36252949
AH
6806 (*lang_hooks.decls.pushdecl)
6807 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6808 opaque_V2SI_type_node));
6809
a3170dc6
AH
6810 /* Initialize irregular SPE builtins. */
6811
6812 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6813 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6814 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6815 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6816 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6817 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6818 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6819 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6820 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6821 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6822 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6823 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6824 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6825 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6826 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6827 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6828 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6829 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6830
6831 /* Loads. */
6832 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6833 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6834 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6835 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6836 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6837 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6838 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6839 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6840 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6841 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6842 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6843 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6844 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6845 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6846 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6847 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6848 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6849 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6850 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6851 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6852 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6853 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6854
6855 /* Predicates. */
6856 d = (struct builtin_description *) bdesc_spe_predicates;
6857 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6858 {
6859 tree type;
6860
6861 switch (insn_data[d->icode].operand[1].mode)
6862 {
6863 case V2SImode:
6864 type = int_ftype_int_v2si_v2si;
6865 break;
6866 case V2SFmode:
6867 type = int_ftype_int_v2sf_v2sf;
6868 break;
6869 default:
6870 abort ();
6871 }
6872
6873 def_builtin (d->mask, d->name, type, d->code);
6874 }
6875
6876 /* Evsel predicates. */
6877 d = (struct builtin_description *) bdesc_spe_evsel;
6878 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6879 {
6880 tree type;
6881
6882 switch (insn_data[d->icode].operand[1].mode)
6883 {
6884 case V2SImode:
6885 type = v2si_ftype_4_v2si;
6886 break;
6887 case V2SFmode:
6888 type = v2sf_ftype_4_v2sf;
6889 break;
6890 default:
6891 abort ();
6892 }
6893
6894 def_builtin (d->mask, d->name, type, d->code);
6895 }
6896}
6897
6898static void
863d938c 6899altivec_init_builtins (void)
a3170dc6
AH
6900{
6901 struct builtin_description *d;
6902 struct builtin_description_predicates *dp;
6903 size_t i;
6904 tree pfloat_type_node = build_pointer_type (float_type_node);
6905 tree pint_type_node = build_pointer_type (integer_type_node);
6906 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6907 tree pchar_type_node = build_pointer_type (char_type_node);
6908
6909 tree pvoid_type_node = build_pointer_type (void_type_node);
6910
0dbc3651
ZW
6911 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6912 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6913 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6914 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6915
6916 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6917
a3170dc6
AH
6918 tree int_ftype_int_v4si_v4si
6919 = build_function_type_list (integer_type_node,
6920 integer_type_node, V4SI_type_node,
6921 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6922 tree v4sf_ftype_pcfloat
6923 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6924 tree void_ftype_pfloat_v4sf
b4de2f7d 6925 = build_function_type_list (void_type_node,
a3170dc6 6926 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6927 tree v4si_ftype_pcint
6928 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6929 tree void_ftype_pint_v4si
b4de2f7d
AH
6930 = build_function_type_list (void_type_node,
6931 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6932 tree v8hi_ftype_pcshort
6933 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6934 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6935 = build_function_type_list (void_type_node,
6936 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6937 tree v16qi_ftype_pcchar
6938 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6939 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6940 = build_function_type_list (void_type_node,
6941 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6942 tree void_ftype_v4si
b4de2f7d 6943 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6944 tree v8hi_ftype_void
6945 = build_function_type (V8HI_type_node, void_list_node);
6946 tree void_ftype_void
6947 = build_function_type (void_type_node, void_list_node);
6948 tree void_ftype_qi
6949 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 6950
b4a62fa0 6951 tree v16qi_ftype_long_pcvoid
a3170dc6 6952 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
6953 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6954 tree v8hi_ftype_long_pcvoid
a3170dc6 6955 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
6956 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6957 tree v4si_ftype_long_pcvoid
a3170dc6 6958 = build_function_type_list (V4SI_type_node,
b4a62fa0 6959 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 6960
b4a62fa0 6961 tree void_ftype_v4si_long_pvoid
b4de2f7d 6962 = build_function_type_list (void_type_node,
b4a62fa0 6963 V4SI_type_node, long_integer_type_node,
b4de2f7d 6964 pvoid_type_node, NULL_TREE);
b4a62fa0 6965 tree void_ftype_v16qi_long_pvoid
b4de2f7d 6966 = build_function_type_list (void_type_node,
b4a62fa0 6967 V16QI_type_node, long_integer_type_node,
b4de2f7d 6968 pvoid_type_node, NULL_TREE);
b4a62fa0 6969 tree void_ftype_v8hi_long_pvoid
b4de2f7d 6970 = build_function_type_list (void_type_node,
b4a62fa0 6971 V8HI_type_node, long_integer_type_node,
b4de2f7d 6972 pvoid_type_node, NULL_TREE);
a3170dc6
AH
6973 tree int_ftype_int_v8hi_v8hi
6974 = build_function_type_list (integer_type_node,
6975 integer_type_node, V8HI_type_node,
6976 V8HI_type_node, NULL_TREE);
6977 tree int_ftype_int_v16qi_v16qi
6978 = build_function_type_list (integer_type_node,
6979 integer_type_node, V16QI_type_node,
6980 V16QI_type_node, NULL_TREE);
6981 tree int_ftype_int_v4sf_v4sf
6982 = build_function_type_list (integer_type_node,
6983 integer_type_node, V4SF_type_node,
6984 V4SF_type_node, NULL_TREE);
6985 tree v4si_ftype_v4si
6986 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
6987 tree v8hi_ftype_v8hi
6988 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
6989 tree v16qi_ftype_v16qi
6990 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
6991 tree v4sf_ftype_v4sf
6992 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 6993 tree void_ftype_pcvoid_int_int
a3170dc6 6994 = build_function_type_list (void_type_node,
0dbc3651 6995 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
6996 integer_type_node, NULL_TREE);
6997 tree int_ftype_pcchar
6998 = build_function_type_list (integer_type_node,
6999 pcchar_type_node, NULL_TREE);
7000
0dbc3651
ZW
7001 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7002 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7003 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7004 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7005 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7006 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7007 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7008 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7009 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7010 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7011 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7012 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7013 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7014 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7015 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7016 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7017 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7018 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7019 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
7020 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7021 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7022 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7023 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7024 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7025 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7026 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7027 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7028 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7029 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7030 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7031 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7032 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7033
8bb418a3
ZL
7034 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7035 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7036 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7037
a3170dc6
AH
7038 /* Add the DST variants. */
7039 d = (struct builtin_description *) bdesc_dst;
7040 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7041 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7042
7043 /* Initialize the predicates. */
7044 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7045 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7046 {
7047 enum machine_mode mode1;
7048 tree type;
7049
7050 mode1 = insn_data[dp->icode].operand[1].mode;
7051
7052 switch (mode1)
7053 {
7054 case V4SImode:
7055 type = int_ftype_int_v4si_v4si;
7056 break;
7057 case V8HImode:
7058 type = int_ftype_int_v8hi_v8hi;
7059 break;
7060 case V16QImode:
7061 type = int_ftype_int_v16qi_v16qi;
7062 break;
7063 case V4SFmode:
7064 type = int_ftype_int_v4sf_v4sf;
7065 break;
7066 default:
7067 abort ();
7068 }
7069
7070 def_builtin (dp->mask, dp->name, type, dp->code);
7071 }
7072
7073 /* Initialize the abs* operators. */
7074 d = (struct builtin_description *) bdesc_abs;
7075 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7076 {
7077 enum machine_mode mode0;
7078 tree type;
7079
7080 mode0 = insn_data[d->icode].operand[0].mode;
7081
7082 switch (mode0)
7083 {
7084 case V4SImode:
7085 type = v4si_ftype_v4si;
7086 break;
7087 case V8HImode:
7088 type = v8hi_ftype_v8hi;
7089 break;
7090 case V16QImode:
7091 type = v16qi_ftype_v16qi;
7092 break;
7093 case V4SFmode:
7094 type = v4sf_ftype_v4sf;
7095 break;
7096 default:
7097 abort ();
7098 }
7099
7100 def_builtin (d->mask, d->name, type, d->code);
7101 }
7102}
7103
7104static void
863d938c 7105rs6000_common_init_builtins (void)
a3170dc6
AH
7106{
7107 struct builtin_description *d;
7108 size_t i;
7109
7110 tree v4sf_ftype_v4sf_v4sf_v16qi
7111 = build_function_type_list (V4SF_type_node,
7112 V4SF_type_node, V4SF_type_node,
7113 V16QI_type_node, NULL_TREE);
7114 tree v4si_ftype_v4si_v4si_v16qi
7115 = build_function_type_list (V4SI_type_node,
7116 V4SI_type_node, V4SI_type_node,
7117 V16QI_type_node, NULL_TREE);
7118 tree v8hi_ftype_v8hi_v8hi_v16qi
7119 = build_function_type_list (V8HI_type_node,
7120 V8HI_type_node, V8HI_type_node,
7121 V16QI_type_node, NULL_TREE);
7122 tree v16qi_ftype_v16qi_v16qi_v16qi
7123 = build_function_type_list (V16QI_type_node,
7124 V16QI_type_node, V16QI_type_node,
7125 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7126 tree v4si_ftype_int
7127 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7128 tree v8hi_ftype_int
7129 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7130 tree v16qi_ftype_int
7131 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7132 tree v8hi_ftype_v16qi
7133 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7134 tree v4sf_ftype_v4sf
7135 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7136
7137 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7138 = build_function_type_list (opaque_V2SI_type_node,
7139 opaque_V2SI_type_node,
7140 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7141
7142 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7143 = build_function_type_list (opaque_V2SF_type_node,
7144 opaque_V2SF_type_node,
7145 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7146
7147 tree v2si_ftype_int_int
2abe3e28 7148 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7149 integer_type_node, integer_type_node,
7150 NULL_TREE);
7151
7152 tree v2si_ftype_v2si
2abe3e28
AH
7153 = build_function_type_list (opaque_V2SI_type_node,
7154 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7155
7156 tree v2sf_ftype_v2sf
2abe3e28
AH
7157 = build_function_type_list (opaque_V2SF_type_node,
7158 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7159
7160 tree v2sf_ftype_v2si
2abe3e28
AH
7161 = build_function_type_list (opaque_V2SF_type_node,
7162 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7163
7164 tree v2si_ftype_v2sf
2abe3e28
AH
7165 = build_function_type_list (opaque_V2SI_type_node,
7166 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7167
7168 tree v2si_ftype_v2si_char
2abe3e28
AH
7169 = build_function_type_list (opaque_V2SI_type_node,
7170 opaque_V2SI_type_node,
7171 char_type_node, NULL_TREE);
a3170dc6
AH
7172
7173 tree v2si_ftype_int_char
2abe3e28 7174 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7175 integer_type_node, char_type_node, NULL_TREE);
7176
7177 tree v2si_ftype_char
2abe3e28
AH
7178 = build_function_type_list (opaque_V2SI_type_node,
7179 char_type_node, NULL_TREE);
a3170dc6
AH
7180
7181 tree int_ftype_int_int
7182 = build_function_type_list (integer_type_node,
7183 integer_type_node, integer_type_node,
7184 NULL_TREE);
95385cbb 7185
0ac081f6 7186 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
7187 = build_function_type_list (V4SI_type_node,
7188 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 7189 tree v4sf_ftype_v4si_int
b4de2f7d 7190 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
7191 V4SI_type_node, integer_type_node, NULL_TREE);
7192 tree v4si_ftype_v4sf_int
b4de2f7d 7193 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7194 V4SF_type_node, integer_type_node, NULL_TREE);
7195 tree v4si_ftype_v4si_int
b4de2f7d 7196 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7197 V4SI_type_node, integer_type_node, NULL_TREE);
7198 tree v8hi_ftype_v8hi_int
b4de2f7d 7199 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
7200 V8HI_type_node, integer_type_node, NULL_TREE);
7201 tree v16qi_ftype_v16qi_int
b4de2f7d 7202 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
7203 V16QI_type_node, integer_type_node, NULL_TREE);
7204 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
7205 = build_function_type_list (V16QI_type_node,
7206 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
7207 integer_type_node, NULL_TREE);
7208 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
7209 = build_function_type_list (V8HI_type_node,
7210 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
7211 integer_type_node, NULL_TREE);
7212 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
7213 = build_function_type_list (V4SI_type_node,
7214 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
7215 integer_type_node, NULL_TREE);
7216 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
7217 = build_function_type_list (V4SF_type_node,
7218 V4SF_type_node, V4SF_type_node,
b9e4e5d1 7219 integer_type_node, NULL_TREE);
0ac081f6 7220 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7221 = build_function_type_list (V4SF_type_node,
7222 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7223 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7224 = build_function_type_list (V4SF_type_node,
7225 V4SF_type_node, V4SF_type_node,
7226 V4SI_type_node, NULL_TREE);
2212663f 7227 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7228 = build_function_type_list (V4SF_type_node,
7229 V4SF_type_node, V4SF_type_node,
7230 V4SF_type_node, NULL_TREE);
617e0e1d 7231 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7232 = build_function_type_list (V4SI_type_node,
7233 V4SI_type_node, V4SI_type_node,
7234 V4SI_type_node, NULL_TREE);
0ac081f6 7235 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7236 = build_function_type_list (V8HI_type_node,
7237 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7238 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7239 = build_function_type_list (V8HI_type_node,
7240 V8HI_type_node, V8HI_type_node,
7241 V8HI_type_node, NULL_TREE);
2212663f 7242 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7243 = build_function_type_list (V4SI_type_node,
7244 V8HI_type_node, V8HI_type_node,
7245 V4SI_type_node, NULL_TREE);
2212663f 7246 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7247 = build_function_type_list (V4SI_type_node,
7248 V16QI_type_node, V16QI_type_node,
7249 V4SI_type_node, NULL_TREE);
0ac081f6 7250 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7251 = build_function_type_list (V16QI_type_node,
7252 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7253 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7254 = build_function_type_list (V4SI_type_node,
7255 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7256 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7257 = build_function_type_list (V8HI_type_node,
7258 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7259 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7260 = build_function_type_list (V4SI_type_node,
7261 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7262 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7263 = build_function_type_list (V8HI_type_node,
7264 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7265 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7266 = build_function_type_list (V16QI_type_node,
7267 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7268 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7269 = build_function_type_list (V4SI_type_node,
7270 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7271 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7272 = build_function_type_list (V4SI_type_node,
7273 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7274 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7275 = build_function_type_list (V4SI_type_node,
7276 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7277 tree v4si_ftype_v8hi
7278 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7279 tree int_ftype_v4si_v4si
7280 = build_function_type_list (integer_type_node,
7281 V4SI_type_node, V4SI_type_node, NULL_TREE);
7282 tree int_ftype_v4sf_v4sf
7283 = build_function_type_list (integer_type_node,
7284 V4SF_type_node, V4SF_type_node, NULL_TREE);
7285 tree int_ftype_v16qi_v16qi
7286 = build_function_type_list (integer_type_node,
7287 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7288 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7289 = build_function_type_list (integer_type_node,
7290 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7291
6f317ef3 7292 /* Add the simple ternary operators. */
2212663f 7293 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7294 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7295 {
7296
7297 enum machine_mode mode0, mode1, mode2, mode3;
7298 tree type;
7299
0559cc77 7300 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7301 continue;
7302
7303 mode0 = insn_data[d->icode].operand[0].mode;
7304 mode1 = insn_data[d->icode].operand[1].mode;
7305 mode2 = insn_data[d->icode].operand[2].mode;
7306 mode3 = insn_data[d->icode].operand[3].mode;
7307
7308 /* When all four are of the same mode. */
7309 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7310 {
7311 switch (mode0)
7312 {
617e0e1d
DB
7313 case V4SImode:
7314 type = v4si_ftype_v4si_v4si_v4si;
7315 break;
2212663f
DB
7316 case V4SFmode:
7317 type = v4sf_ftype_v4sf_v4sf_v4sf;
7318 break;
7319 case V8HImode:
7320 type = v8hi_ftype_v8hi_v8hi_v8hi;
7321 break;
7322 case V16QImode:
7323 type = v16qi_ftype_v16qi_v16qi_v16qi;
7324 break;
7325 default:
7326 abort();
7327 }
7328 }
7329 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7330 {
7331 switch (mode0)
7332 {
7333 case V4SImode:
7334 type = v4si_ftype_v4si_v4si_v16qi;
7335 break;
7336 case V4SFmode:
7337 type = v4sf_ftype_v4sf_v4sf_v16qi;
7338 break;
7339 case V8HImode:
7340 type = v8hi_ftype_v8hi_v8hi_v16qi;
7341 break;
7342 case V16QImode:
7343 type = v16qi_ftype_v16qi_v16qi_v16qi;
7344 break;
7345 default:
7346 abort();
7347 }
7348 }
7349 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7350 && mode3 == V4SImode)
24408032 7351 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7352 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7353 && mode3 == V4SImode)
24408032 7354 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7355 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7356 && mode3 == V4SImode)
24408032
AH
7357 type = v4sf_ftype_v4sf_v4sf_v4si;
7358
7359 /* vchar, vchar, vchar, 4 bit literal. */
7360 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7361 && mode3 == QImode)
b9e4e5d1 7362 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
7363
7364 /* vshort, vshort, vshort, 4 bit literal. */
7365 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7366 && mode3 == QImode)
b9e4e5d1 7367 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
7368
7369 /* vint, vint, vint, 4 bit literal. */
7370 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7371 && mode3 == QImode)
b9e4e5d1 7372 type = v4si_ftype_v4si_v4si_int;
24408032
AH
7373
7374 /* vfloat, vfloat, vfloat, 4 bit literal. */
7375 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7376 && mode3 == QImode)
b9e4e5d1 7377 type = v4sf_ftype_v4sf_v4sf_int;
24408032 7378
2212663f
DB
7379 else
7380 abort ();
7381
7382 def_builtin (d->mask, d->name, type, d->code);
7383 }
7384
0ac081f6 7385 /* Add the simple binary operators. */
00b960c7 7386 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7387 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7388 {
7389 enum machine_mode mode0, mode1, mode2;
7390 tree type;
7391
0559cc77 7392 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7393 continue;
7394
7395 mode0 = insn_data[d->icode].operand[0].mode;
7396 mode1 = insn_data[d->icode].operand[1].mode;
7397 mode2 = insn_data[d->icode].operand[2].mode;
7398
7399 /* When all three operands are of the same mode. */
7400 if (mode0 == mode1 && mode1 == mode2)
7401 {
7402 switch (mode0)
7403 {
7404 case V4SFmode:
7405 type = v4sf_ftype_v4sf_v4sf;
7406 break;
7407 case V4SImode:
7408 type = v4si_ftype_v4si_v4si;
7409 break;
7410 case V16QImode:
7411 type = v16qi_ftype_v16qi_v16qi;
7412 break;
7413 case V8HImode:
7414 type = v8hi_ftype_v8hi_v8hi;
7415 break;
a3170dc6
AH
7416 case V2SImode:
7417 type = v2si_ftype_v2si_v2si;
7418 break;
7419 case V2SFmode:
7420 type = v2sf_ftype_v2sf_v2sf;
7421 break;
7422 case SImode:
7423 type = int_ftype_int_int;
7424 break;
0ac081f6
AH
7425 default:
7426 abort ();
7427 }
7428 }
7429
7430 /* A few other combos we really don't want to do manually. */
7431
7432 /* vint, vfloat, vfloat. */
7433 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7434 type = v4si_ftype_v4sf_v4sf;
7435
7436 /* vshort, vchar, vchar. */
7437 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7438 type = v8hi_ftype_v16qi_v16qi;
7439
7440 /* vint, vshort, vshort. */
7441 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7442 type = v4si_ftype_v8hi_v8hi;
7443
7444 /* vshort, vint, vint. */
7445 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7446 type = v8hi_ftype_v4si_v4si;
7447
7448 /* vchar, vshort, vshort. */
7449 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7450 type = v16qi_ftype_v8hi_v8hi;
7451
7452 /* vint, vchar, vint. */
7453 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7454 type = v4si_ftype_v16qi_v4si;
7455
fa066a23
AH
7456 /* vint, vchar, vchar. */
7457 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7458 type = v4si_ftype_v16qi_v16qi;
7459
0ac081f6
AH
7460 /* vint, vshort, vint. */
7461 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7462 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7463
7464 /* vint, vint, 5 bit literal. */
7465 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7466 type = v4si_ftype_v4si_int;
2212663f
DB
7467
7468 /* vshort, vshort, 5 bit literal. */
7469 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 7470 type = v8hi_ftype_v8hi_int;
2212663f
DB
7471
7472 /* vchar, vchar, 5 bit literal. */
7473 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 7474 type = v16qi_ftype_v16qi_int;
0ac081f6 7475
617e0e1d
DB
7476 /* vfloat, vint, 5 bit literal. */
7477 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7478 type = v4sf_ftype_v4si_int;
617e0e1d
DB
7479
7480 /* vint, vfloat, 5 bit literal. */
7481 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 7482 type = v4si_ftype_v4sf_int;
617e0e1d 7483
a3170dc6
AH
7484 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7485 type = v2si_ftype_int_int;
7486
7487 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7488 type = v2si_ftype_v2si_char;
7489
7490 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7491 type = v2si_ftype_int_char;
7492
0ac081f6
AH
7493 /* int, x, x. */
7494 else if (mode0 == SImode)
7495 {
7496 switch (mode1)
7497 {
7498 case V4SImode:
7499 type = int_ftype_v4si_v4si;
7500 break;
7501 case V4SFmode:
7502 type = int_ftype_v4sf_v4sf;
7503 break;
7504 case V16QImode:
7505 type = int_ftype_v16qi_v16qi;
7506 break;
7507 case V8HImode:
7508 type = int_ftype_v8hi_v8hi;
7509 break;
7510 default:
7511 abort ();
7512 }
7513 }
7514
7515 else
7516 abort ();
7517
2212663f
DB
7518 def_builtin (d->mask, d->name, type, d->code);
7519 }
24408032 7520
2212663f
DB
7521 /* Add the simple unary operators. */
7522 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7523 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7524 {
7525 enum machine_mode mode0, mode1;
7526 tree type;
7527
0559cc77 7528 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7529 continue;
7530
7531 mode0 = insn_data[d->icode].operand[0].mode;
7532 mode1 = insn_data[d->icode].operand[1].mode;
7533
7534 if (mode0 == V4SImode && mode1 == QImode)
b9e4e5d1 7535 type = v4si_ftype_int;
2212663f 7536 else if (mode0 == V8HImode && mode1 == QImode)
b9e4e5d1 7537 type = v8hi_ftype_int;
2212663f 7538 else if (mode0 == V16QImode && mode1 == QImode)
b9e4e5d1 7539 type = v16qi_ftype_int;
617e0e1d
DB
7540 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7541 type = v4sf_ftype_v4sf;
20e26713
AH
7542 else if (mode0 == V8HImode && mode1 == V16QImode)
7543 type = v8hi_ftype_v16qi;
7544 else if (mode0 == V4SImode && mode1 == V8HImode)
7545 type = v4si_ftype_v8hi;
a3170dc6
AH
7546 else if (mode0 == V2SImode && mode1 == V2SImode)
7547 type = v2si_ftype_v2si;
7548 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7549 type = v2sf_ftype_v2sf;
7550 else if (mode0 == V2SFmode && mode1 == V2SImode)
7551 type = v2sf_ftype_v2si;
7552 else if (mode0 == V2SImode && mode1 == V2SFmode)
7553 type = v2si_ftype_v2sf;
7554 else if (mode0 == V2SImode && mode1 == QImode)
7555 type = v2si_ftype_char;
2212663f
DB
7556 else
7557 abort ();
7558
0ac081f6
AH
7559 def_builtin (d->mask, d->name, type, d->code);
7560 }
7561}
7562
c15c90bb
ZW
7563static void
7564rs6000_init_libfuncs (void)
7565{
7566 if (!TARGET_HARD_FLOAT)
7567 return;
7568
c9034561 7569 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7570 {
c9034561 7571 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7572 {
c9034561 7573 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7574 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7575 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7576 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7577 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7578 }
7579
c9034561 7580 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7581 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7582 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7583 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7584 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7585 }
c9034561 7586 else
c15c90bb 7587 {
c9034561 7588 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7589
7590 set_optab_libfunc (add_optab, TFmode, "_q_add");
7591 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7592 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7593 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7594 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7595 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7596 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7597
c9034561
ZW
7598 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7599 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7600 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7601 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7602 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7603 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7604
85363ca0
ZW
7605 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7606 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7607 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7608 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7609 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7610 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7611 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7612 }
7613}
35aff10b 7614\f
7e69e155
MM
7615/* Expand a block move operation, and return 1 if successful. Return 0
7616 if we should let the compiler generate normal code.
7617
7618 operands[0] is the destination
7619 operands[1] is the source
7620 operands[2] is the length
7621 operands[3] is the alignment */
7622
3933e0e1
MM
7623#define MAX_MOVE_REG 4
7624
7e69e155 7625int
a2369ed3 7626expand_block_move (rtx operands[])
7e69e155 7627{
b6c9286a
MM
7628 rtx orig_dest = operands[0];
7629 rtx orig_src = operands[1];
7e69e155 7630 rtx bytes_rtx = operands[2];
7e69e155 7631 rtx align_rtx = operands[3];
3933e0e1 7632 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7633 int align;
3933e0e1
MM
7634 int bytes;
7635 int offset;
7e69e155 7636 int move_bytes;
cabfd258
GK
7637 rtx stores[MAX_MOVE_REG];
7638 int num_reg = 0;
7e69e155 7639
3933e0e1 7640 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7641 if (! constp)
3933e0e1
MM
7642 return 0;
7643
5ee95df6
FS
7644 /* If this is not a fixed size alignment, abort */
7645 if (GET_CODE (align_rtx) != CONST_INT)
7646 abort ();
7647 align = INTVAL (align_rtx);
7648
7e69e155 7649 /* Anything to move? */
3933e0e1
MM
7650 bytes = INTVAL (bytes_rtx);
7651 if (bytes <= 0)
7e69e155
MM
7652 return 1;
7653
ea9982a8 7654 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7655 reg_parm_stack_space. */
ea9982a8 7656 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7657 return 0;
7658
cabfd258 7659 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7660 {
cabfd258 7661 union {
a2369ed3
DJ
7662 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7663 rtx (*mov) (rtx, rtx);
cabfd258
GK
7664 } gen_func;
7665 enum machine_mode mode = BLKmode;
7666 rtx src, dest;
7667
7668 if (TARGET_STRING
7669 && bytes > 24 /* move up to 32 bytes at a time */
7670 && ! fixed_regs[5]
7671 && ! fixed_regs[6]
7672 && ! fixed_regs[7]
7673 && ! fixed_regs[8]
7674 && ! fixed_regs[9]
7675 && ! fixed_regs[10]
7676 && ! fixed_regs[11]
7677 && ! fixed_regs[12])
7e69e155 7678 {
cabfd258
GK
7679 move_bytes = (bytes > 32) ? 32 : bytes;
7680 gen_func.movstrsi = gen_movstrsi_8reg;
7681 }
7682 else if (TARGET_STRING
7683 && bytes > 16 /* move up to 24 bytes at a time */
7684 && ! fixed_regs[5]
7685 && ! fixed_regs[6]
7686 && ! fixed_regs[7]
7687 && ! fixed_regs[8]
7688 && ! fixed_regs[9]
7689 && ! fixed_regs[10])
7690 {
7691 move_bytes = (bytes > 24) ? 24 : bytes;
7692 gen_func.movstrsi = gen_movstrsi_6reg;
7693 }
7694 else if (TARGET_STRING
7695 && bytes > 8 /* move up to 16 bytes at a time */
7696 && ! fixed_regs[5]
7697 && ! fixed_regs[6]
7698 && ! fixed_regs[7]
7699 && ! fixed_regs[8])
7700 {
7701 move_bytes = (bytes > 16) ? 16 : bytes;
7702 gen_func.movstrsi = gen_movstrsi_4reg;
7703 }
7704 else if (bytes >= 8 && TARGET_POWERPC64
7705 /* 64-bit loads and stores require word-aligned
7706 displacements. */
7707 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7708 {
7709 move_bytes = 8;
7710 mode = DImode;
7711 gen_func.mov = gen_movdi;
7712 }
7713 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7714 { /* move up to 8 bytes at a time */
7715 move_bytes = (bytes > 8) ? 8 : bytes;
7716 gen_func.movstrsi = gen_movstrsi_2reg;
7717 }
7718 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7719 { /* move 4 bytes */
7720 move_bytes = 4;
7721 mode = SImode;
7722 gen_func.mov = gen_movsi;
7723 }
7724 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7725 { /* move 2 bytes */
7726 move_bytes = 2;
7727 mode = HImode;
7728 gen_func.mov = gen_movhi;
7729 }
7730 else if (TARGET_STRING && bytes > 1)
7731 { /* move up to 4 bytes at a time */
7732 move_bytes = (bytes > 4) ? 4 : bytes;
7733 gen_func.movstrsi = gen_movstrsi_1reg;
7734 }
7735 else /* move 1 byte at a time */
7736 {
7737 move_bytes = 1;
7738 mode = QImode;
7739 gen_func.mov = gen_movqi;
7740 }
7741
7742 src = adjust_address (orig_src, mode, offset);
7743 dest = adjust_address (orig_dest, mode, offset);
7744
7745 if (mode != BLKmode)
7746 {
7747 rtx tmp_reg = gen_reg_rtx (mode);
7748
7749 emit_insn ((*gen_func.mov) (tmp_reg, src));
7750 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7751 }
3933e0e1 7752
cabfd258
GK
7753 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7754 {
7755 int i;
7756 for (i = 0; i < num_reg; i++)
7757 emit_insn (stores[i]);
7758 num_reg = 0;
7759 }
35aff10b 7760
cabfd258 7761 if (mode == BLKmode)
7e69e155 7762 {
cabfd258
GK
7763 /* Move the address into scratch registers. The movstrsi
7764 patterns require zero offset. */
7765 if (!REG_P (XEXP (src, 0)))
b6c9286a 7766 {
cabfd258
GK
7767 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7768 src = replace_equiv_address (src, src_reg);
b6c9286a 7769 }
cabfd258
GK
7770 set_mem_size (src, GEN_INT (move_bytes));
7771
7772 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7773 {
cabfd258
GK
7774 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7775 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7776 }
cabfd258
GK
7777 set_mem_size (dest, GEN_INT (move_bytes));
7778
7779 emit_insn ((*gen_func.movstrsi) (dest, src,
7780 GEN_INT (move_bytes & 31),
7781 align_rtx));
7e69e155 7782 }
7e69e155
MM
7783 }
7784
7785 return 1;
7786}
7787
9878760c
RK
7788\f
7789/* Return 1 if OP is a load multiple operation. It is known to be a
7790 PARALLEL and the first section will be tested. */
7791
7792int
a2369ed3 7793load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7794{
7795 int count = XVECLEN (op, 0);
e2c953b6 7796 unsigned int dest_regno;
9878760c
RK
7797 rtx src_addr;
7798 int i;
7799
7800 /* Perform a quick check so we don't blow up below. */
7801 if (count <= 1
7802 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7803 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7804 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7805 return 0;
7806
7807 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7808 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7809
7810 for (i = 1; i < count; i++)
7811 {
7812 rtx elt = XVECEXP (op, 0, i);
7813
7814 if (GET_CODE (elt) != SET
7815 || GET_CODE (SET_DEST (elt)) != REG
7816 || GET_MODE (SET_DEST (elt)) != SImode
7817 || REGNO (SET_DEST (elt)) != dest_regno + i
7818 || GET_CODE (SET_SRC (elt)) != MEM
7819 || GET_MODE (SET_SRC (elt)) != SImode
7820 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7821 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7822 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7823 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7824 return 0;
7825 }
7826
7827 return 1;
7828}
7829
7830/* Similar, but tests for store multiple. Here, the second vector element
7831 is a CLOBBER. It will be tested later. */
7832
7833int
a2369ed3 7834store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7835{
7836 int count = XVECLEN (op, 0) - 1;
e2c953b6 7837 unsigned int src_regno;
9878760c
RK
7838 rtx dest_addr;
7839 int i;
7840
7841 /* Perform a quick check so we don't blow up below. */
7842 if (count <= 1
7843 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7844 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7845 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7846 return 0;
7847
7848 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7849 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7850
7851 for (i = 1; i < count; i++)
7852 {
7853 rtx elt = XVECEXP (op, 0, i + 1);
7854
7855 if (GET_CODE (elt) != SET
7856 || GET_CODE (SET_SRC (elt)) != REG
7857 || GET_MODE (SET_SRC (elt)) != SImode
7858 || REGNO (SET_SRC (elt)) != src_regno + i
7859 || GET_CODE (SET_DEST (elt)) != MEM
7860 || GET_MODE (SET_DEST (elt)) != SImode
7861 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7862 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7863 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7864 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7865 return 0;
7866 }
7867
7868 return 1;
7869}
9ebbca7d 7870
9caa3eb2
DE
7871/* Return a string to perform a load_multiple operation.
7872 operands[0] is the vector.
7873 operands[1] is the source address.
7874 operands[2] is the first destination register. */
7875
7876const char *
a2369ed3 7877rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7878{
7879 /* We have to handle the case where the pseudo used to contain the address
7880 is assigned to one of the output registers. */
7881 int i, j;
7882 int words = XVECLEN (operands[0], 0);
7883 rtx xop[10];
7884
7885 if (XVECLEN (operands[0], 0) == 1)
7886 return "{l|lwz} %2,0(%1)";
7887
7888 for (i = 0; i < words; i++)
7889 if (refers_to_regno_p (REGNO (operands[2]) + i,
7890 REGNO (operands[2]) + i + 1, operands[1], 0))
7891 {
7892 if (i == words-1)
7893 {
7894 xop[0] = GEN_INT (4 * (words-1));
7895 xop[1] = operands[1];
7896 xop[2] = operands[2];
7897 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7898 return "";
7899 }
7900 else if (i == 0)
7901 {
7902 xop[0] = GEN_INT (4 * (words-1));
7903 xop[1] = operands[1];
7904 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7905 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);
7906 return "";
7907 }
7908 else
7909 {
7910 for (j = 0; j < words; j++)
7911 if (j != i)
7912 {
7913 xop[0] = GEN_INT (j * 4);
7914 xop[1] = operands[1];
7915 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7916 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7917 }
7918 xop[0] = GEN_INT (i * 4);
7919 xop[1] = operands[1];
7920 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7921 return "";
7922 }
7923 }
7924
7925 return "{lsi|lswi} %2,%1,%N0";
7926}
7927
00b960c7
AH
7928/* Return 1 for a parallel vrsave operation. */
7929
7930int
a2369ed3 7931vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
7932{
7933 int count = XVECLEN (op, 0);
7934 unsigned int dest_regno, src_regno;
7935 int i;
7936
7937 if (count <= 1
7938 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7939 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7940 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7941 return 0;
7942
7943 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7944 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7945
7946 if (dest_regno != VRSAVE_REGNO
7947 && src_regno != VRSAVE_REGNO)
7948 return 0;
7949
7950 for (i = 1; i < count; i++)
7951 {
7952 rtx elt = XVECEXP (op, 0, i);
7953
9aa86737
AH
7954 if (GET_CODE (elt) != CLOBBER
7955 && GET_CODE (elt) != SET)
00b960c7
AH
7956 return 0;
7957 }
7958
7959 return 1;
7960}
7961
2c4a9cff
DE
7962/* Return 1 for an PARALLEL suitable for mfcr. */
7963
7964int
a2369ed3 7965mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
7966{
7967 int count = XVECLEN (op, 0);
7968 int i;
7969
7970 /* Perform a quick check so we don't blow up below. */
7971 if (count < 1
7972 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7973 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7974 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
7975 return 0;
7976
7977 for (i = 0; i < count; i++)
7978 {
7979 rtx exp = XVECEXP (op, 0, i);
7980 rtx unspec;
7981 int maskval;
7982 rtx src_reg;
7983
7984 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
7985
7986 if (GET_CODE (src_reg) != REG
7987 || GET_MODE (src_reg) != CCmode
7988 || ! CR_REGNO_P (REGNO (src_reg)))
7989 return 0;
7990
7991 if (GET_CODE (exp) != SET
7992 || GET_CODE (SET_DEST (exp)) != REG
7993 || GET_MODE (SET_DEST (exp)) != SImode
7994 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
7995 return 0;
7996 unspec = SET_SRC (exp);
7997 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
7998
7999 if (GET_CODE (unspec) != UNSPEC
8000 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8001 || XVECLEN (unspec, 0) != 2
8002 || XVECEXP (unspec, 0, 0) != src_reg
8003 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8004 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8005 return 0;
8006 }
8007 return 1;
8008}
8009
a4f6c312 8010/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8011
8012int
a2369ed3 8013mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8014{
8015 int count = XVECLEN (op, 0);
8016 int i;
9ebbca7d
GK
8017 rtx src_reg;
8018
8019 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8020 if (count < 1
8021 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8022 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8023 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8024 return 0;
e35b9579 8025 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
8026
8027 if (GET_CODE (src_reg) != REG
8028 || GET_MODE (src_reg) != SImode
8029 || ! INT_REGNO_P (REGNO (src_reg)))
8030 return 0;
8031
e35b9579 8032 for (i = 0; i < count; i++)
9ebbca7d
GK
8033 {
8034 rtx exp = XVECEXP (op, 0, i);
8035 rtx unspec;
8036 int maskval;
8037
8038 if (GET_CODE (exp) != SET
8039 || GET_CODE (SET_DEST (exp)) != REG
8040 || GET_MODE (SET_DEST (exp)) != CCmode
8041 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8042 return 0;
8043 unspec = SET_SRC (exp);
8044 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
8045
8046 if (GET_CODE (unspec) != UNSPEC
615158e2 8047 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8048 || XVECLEN (unspec, 0) != 2
8049 || XVECEXP (unspec, 0, 0) != src_reg
8050 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8051 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8052 return 0;
8053 }
e35b9579 8054 return 1;
9ebbca7d
GK
8055}
8056
a4f6c312 8057/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8058
8059int
a2369ed3 8060lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8061{
8062 int count = XVECLEN (op, 0);
e2c953b6 8063 unsigned int dest_regno;
9ebbca7d 8064 rtx src_addr;
e2c953b6 8065 unsigned int base_regno;
9ebbca7d
GK
8066 HOST_WIDE_INT offset;
8067 int i;
8068
8069 /* Perform a quick check so we don't blow up below. */
8070 if (count <= 1
8071 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8072 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8073 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8074 return 0;
8075
8076 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8077 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8078
8079 if (dest_regno > 31
e2c953b6 8080 || count != 32 - (int) dest_regno)
9ebbca7d
GK
8081 return 0;
8082
4d588c14 8083 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
8084 {
8085 offset = 0;
8086 base_regno = REGNO (src_addr);
8087 if (base_regno == 0)
8088 return 0;
8089 }
4d588c14 8090 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
8091 {
8092 offset = INTVAL (XEXP (src_addr, 1));
8093 base_regno = REGNO (XEXP (src_addr, 0));
8094 }
8095 else
8096 return 0;
8097
8098 for (i = 0; i < count; i++)
8099 {
8100 rtx elt = XVECEXP (op, 0, i);
8101 rtx newaddr;
8102 rtx addr_reg;
8103 HOST_WIDE_INT newoffset;
8104
8105 if (GET_CODE (elt) != SET
8106 || GET_CODE (SET_DEST (elt)) != REG
8107 || GET_MODE (SET_DEST (elt)) != SImode
8108 || REGNO (SET_DEST (elt)) != dest_regno + i
8109 || GET_CODE (SET_SRC (elt)) != MEM
8110 || GET_MODE (SET_SRC (elt)) != SImode)
8111 return 0;
8112 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 8113 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8114 {
8115 newoffset = 0;
8116 addr_reg = newaddr;
8117 }
4d588c14 8118 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8119 {
8120 addr_reg = XEXP (newaddr, 0);
8121 newoffset = INTVAL (XEXP (newaddr, 1));
8122 }
8123 else
8124 return 0;
8125 if (REGNO (addr_reg) != base_regno
8126 || newoffset != offset + 4 * i)
8127 return 0;
8128 }
8129
8130 return 1;
8131}
8132
a4f6c312 8133/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
8134
8135int
a2369ed3 8136stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8137{
8138 int count = XVECLEN (op, 0);
e2c953b6 8139 unsigned int src_regno;
9ebbca7d 8140 rtx dest_addr;
e2c953b6 8141 unsigned int base_regno;
9ebbca7d
GK
8142 HOST_WIDE_INT offset;
8143 int i;
8144
8145 /* Perform a quick check so we don't blow up below. */
8146 if (count <= 1
8147 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8148 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8149 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8150 return 0;
8151
8152 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8153 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8154
8155 if (src_regno > 31
e2c953b6 8156 || count != 32 - (int) src_regno)
9ebbca7d
GK
8157 return 0;
8158
4d588c14 8159 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
8160 {
8161 offset = 0;
8162 base_regno = REGNO (dest_addr);
8163 if (base_regno == 0)
8164 return 0;
8165 }
4d588c14 8166 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
8167 {
8168 offset = INTVAL (XEXP (dest_addr, 1));
8169 base_regno = REGNO (XEXP (dest_addr, 0));
8170 }
8171 else
8172 return 0;
8173
8174 for (i = 0; i < count; i++)
8175 {
8176 rtx elt = XVECEXP (op, 0, i);
8177 rtx newaddr;
8178 rtx addr_reg;
8179 HOST_WIDE_INT newoffset;
8180
8181 if (GET_CODE (elt) != SET
8182 || GET_CODE (SET_SRC (elt)) != REG
8183 || GET_MODE (SET_SRC (elt)) != SImode
8184 || REGNO (SET_SRC (elt)) != src_regno + i
8185 || GET_CODE (SET_DEST (elt)) != MEM
8186 || GET_MODE (SET_DEST (elt)) != SImode)
8187 return 0;
8188 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 8189 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8190 {
8191 newoffset = 0;
8192 addr_reg = newaddr;
8193 }
4d588c14 8194 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8195 {
8196 addr_reg = XEXP (newaddr, 0);
8197 newoffset = INTVAL (XEXP (newaddr, 1));
8198 }
8199 else
8200 return 0;
8201 if (REGNO (addr_reg) != base_regno
8202 || newoffset != offset + 4 * i)
8203 return 0;
8204 }
8205
8206 return 1;
8207}
9878760c 8208\f
a4f6c312
SS
8209/* A validation routine: say whether CODE, a condition code, and MODE
8210 match. The other alternatives either don't make sense or should
8211 never be generated. */
39a10a29 8212
39a10a29 8213static void
a2369ed3 8214validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 8215{
ec8e098d
PB
8216 if ((GET_RTX_CLASS (code) != RTX_COMPARE
8217 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
8218 || GET_MODE_CLASS (mode) != MODE_CC)
8219 abort ();
8220
8221 /* These don't make sense. */
8222 if ((code == GT || code == LT || code == GE || code == LE)
8223 && mode == CCUNSmode)
8224 abort ();
8225
8226 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8227 && mode != CCUNSmode)
8228 abort ();
8229
8230 if (mode != CCFPmode
8231 && (code == ORDERED || code == UNORDERED
8232 || code == UNEQ || code == LTGT
8233 || code == UNGT || code == UNLT
8234 || code == UNGE || code == UNLE))
a4f6c312 8235 abort ();
39a10a29 8236
de6c5979 8237 /* These should never be generated except for
bc9ec0e0 8238 flag_finite_math_only. */
39a10a29 8239 if (mode == CCFPmode
ad72b533 8240 && ! flag_finite_math_only
39a10a29
GK
8241 && (code == LE || code == GE
8242 || code == UNEQ || code == LTGT
8243 || code == UNGT || code == UNLT))
8244 abort ();
8245
8246 /* These are invalid; the information is not there. */
8247 if (mode == CCEQmode
8248 && code != EQ && code != NE)
8249 abort ();
8250}
8251
9878760c
RK
8252/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8253 We only check the opcode against the mode of the CC value here. */
8254
8255int
a2369ed3 8256branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8257{
8258 enum rtx_code code = GET_CODE (op);
8259 enum machine_mode cc_mode;
8260
ec8e098d 8261 if (!COMPARISON_P (op))
9878760c
RK
8262 return 0;
8263
8264 cc_mode = GET_MODE (XEXP (op, 0));
8265 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8266 return 0;
8267
39a10a29 8268 validate_condition_mode (code, cc_mode);
9878760c 8269
39a10a29
GK
8270 return 1;
8271}
8272
8273/* Return 1 if OP is a comparison operation that is valid for a branch
8274 insn and which is true if the corresponding bit in the CC register
8275 is set. */
8276
8277int
a2369ed3 8278branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8279{
8280 enum rtx_code code;
8281
8daf2e65 8282 if (! branch_comparison_operator (op, mode))
9878760c
RK
8283 return 0;
8284
39a10a29
GK
8285 code = GET_CODE (op);
8286 return (code == EQ || code == LT || code == GT
993f19a8 8287 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
8288 || code == LTU || code == GTU
8289 || code == UNORDERED);
9878760c
RK
8290}
8291
b7053a3f
GK
8292/* Return 1 if OP is a comparison operation that is valid for an scc
8293 insn: it must be a positive comparison. */
9878760c
RK
8294
8295int
a2369ed3 8296scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8297{
b7053a3f 8298 return branch_positive_comparison_operator (op, mode);
9878760c 8299}
e0cd0770
JC
8300
8301int
a2369ed3 8302trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8303{
8304 if (mode != VOIDmode && mode != GET_MODE (op))
8305 return 0;
ec8e098d 8306 return COMPARISON_P (op);
e0cd0770 8307}
dfbdccdb
GK
8308
8309int
a2369ed3 8310boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8311{
8312 enum rtx_code code = GET_CODE (op);
8313 return (code == AND || code == IOR || code == XOR);
8314}
1d328b19
GK
8315
8316int
a2369ed3 8317boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8318{
8319 enum rtx_code code = GET_CODE (op);
8320 return (code == IOR || code == XOR);
8321}
50a0b056
GK
8322
8323int
a2369ed3 8324min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8325{
8326 enum rtx_code code = GET_CODE (op);
8327 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8328}
9878760c
RK
8329\f
8330/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8331 mask required to convert the result of a rotate insn into a shift
b1765bde 8332 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8333
8334int
a2369ed3 8335includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8336{
e2c953b6
DE
8337 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8338
8339 shift_mask <<= INTVAL (shiftop);
9878760c 8340
b1765bde 8341 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8342}
8343
8344/* Similar, but for right shift. */
8345
8346int
a2369ed3 8347includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8348{
a7653a2c 8349 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8350
8351 shift_mask >>= INTVAL (shiftop);
8352
b1765bde 8353 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8354}
8355
c5059423
AM
8356/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8357 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8358 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8359
8360int
a2369ed3 8361includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8362{
c5059423
AM
8363 if (GET_CODE (andop) == CONST_INT)
8364 {
02071907 8365 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8366
c5059423 8367 c = INTVAL (andop);
02071907 8368 if (c == 0 || c == ~0)
c5059423 8369 return 0;
e2c953b6 8370
02071907 8371 shift_mask = ~0;
c5059423
AM
8372 shift_mask <<= INTVAL (shiftop);
8373
b6d08ca1 8374 /* Find the least significant one bit. */
c5059423
AM
8375 lsb = c & -c;
8376
8377 /* It must coincide with the LSB of the shift mask. */
8378 if (-lsb != shift_mask)
8379 return 0;
e2c953b6 8380
c5059423
AM
8381 /* Invert to look for the next transition (if any). */
8382 c = ~c;
8383
8384 /* Remove the low group of ones (originally low group of zeros). */
8385 c &= -lsb;
8386
8387 /* Again find the lsb, and check we have all 1's above. */
8388 lsb = c & -c;
8389 return c == -lsb;
8390 }
8391 else if (GET_CODE (andop) == CONST_DOUBLE
8392 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8393 {
02071907
AM
8394 HOST_WIDE_INT low, high, lsb;
8395 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8396
8397 low = CONST_DOUBLE_LOW (andop);
8398 if (HOST_BITS_PER_WIDE_INT < 64)
8399 high = CONST_DOUBLE_HIGH (andop);
8400
8401 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8402 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8403 return 0;
8404
8405 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8406 {
02071907 8407 shift_mask_high = ~0;
c5059423
AM
8408 if (INTVAL (shiftop) > 32)
8409 shift_mask_high <<= INTVAL (shiftop) - 32;
8410
8411 lsb = high & -high;
8412
8413 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8414 return 0;
8415
8416 high = ~high;
8417 high &= -lsb;
8418
8419 lsb = high & -high;
8420 return high == -lsb;
8421 }
8422
02071907 8423 shift_mask_low = ~0;
c5059423
AM
8424 shift_mask_low <<= INTVAL (shiftop);
8425
8426 lsb = low & -low;
8427
8428 if (-lsb != shift_mask_low)
8429 return 0;
8430
8431 if (HOST_BITS_PER_WIDE_INT < 64)
8432 high = ~high;
8433 low = ~low;
8434 low &= -lsb;
8435
8436 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8437 {
8438 lsb = high & -high;
8439 return high == -lsb;
8440 }
8441
8442 lsb = low & -low;
8443 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8444 }
8445 else
8446 return 0;
8447}
e2c953b6 8448
c5059423
AM
8449/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8450 to perform a left shift. It must have SHIFTOP or more least
c1207243 8451 significant 0's, with the remainder of the word 1's. */
e2c953b6 8452
c5059423 8453int
a2369ed3 8454includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8455{
e2c953b6 8456 if (GET_CODE (andop) == CONST_INT)
c5059423 8457 {
02071907 8458 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8459
02071907 8460 shift_mask = ~0;
c5059423
AM
8461 shift_mask <<= INTVAL (shiftop);
8462 c = INTVAL (andop);
8463
c1207243 8464 /* Find the least significant one bit. */
c5059423
AM
8465 lsb = c & -c;
8466
8467 /* It must be covered by the shift mask.
a4f6c312 8468 This test also rejects c == 0. */
c5059423
AM
8469 if ((lsb & shift_mask) == 0)
8470 return 0;
8471
8472 /* Check we have all 1's above the transition, and reject all 1's. */
8473 return c == -lsb && lsb != 1;
8474 }
8475 else if (GET_CODE (andop) == CONST_DOUBLE
8476 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8477 {
02071907 8478 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8479
8480 low = CONST_DOUBLE_LOW (andop);
8481
8482 if (HOST_BITS_PER_WIDE_INT < 64)
8483 {
02071907 8484 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8485
8486 high = CONST_DOUBLE_HIGH (andop);
8487
8488 if (low == 0)
8489 {
02071907 8490 shift_mask_high = ~0;
c5059423
AM
8491 if (INTVAL (shiftop) > 32)
8492 shift_mask_high <<= INTVAL (shiftop) - 32;
8493
8494 lsb = high & -high;
8495
8496 if ((lsb & shift_mask_high) == 0)
8497 return 0;
8498
8499 return high == -lsb;
8500 }
8501 if (high != ~0)
8502 return 0;
8503 }
8504
02071907 8505 shift_mask_low = ~0;
c5059423
AM
8506 shift_mask_low <<= INTVAL (shiftop);
8507
8508 lsb = low & -low;
8509
8510 if ((lsb & shift_mask_low) == 0)
8511 return 0;
8512
8513 return low == -lsb && lsb != 1;
8514 }
e2c953b6 8515 else
c5059423 8516 return 0;
9878760c 8517}
35068b43
RK
8518
8519/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
8520 for lfq and stfq insns.
8521
8522 Note reg1 and reg2 *must* be hard registers. To be sure we will
8523 abort if we are passed pseudo registers. */
8524
8525int
a2369ed3 8526registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8527{
8528 /* We might have been passed a SUBREG. */
8529 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8530 return 0;
8531
8532 return (REGNO (reg1) == REGNO (reg2) - 1);
8533}
8534
a4f6c312
SS
8535/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8536 addr1 and addr2 must be in consecutive memory locations
8537 (addr2 == addr1 + 8). */
35068b43
RK
8538
8539int
a2369ed3 8540addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 8541{
e2c953b6 8542 unsigned int reg1;
35068b43
RK
8543 int offset1;
8544
8545 /* Extract an offset (if used) from the first addr. */
8546 if (GET_CODE (addr1) == PLUS)
8547 {
8548 /* If not a REG, return zero. */
8549 if (GET_CODE (XEXP (addr1, 0)) != REG)
8550 return 0;
8551 else
8552 {
8553 reg1 = REGNO (XEXP (addr1, 0));
8554 /* The offset must be constant! */
8555 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8556 return 0;
8557 offset1 = INTVAL (XEXP (addr1, 1));
8558 }
8559 }
8560 else if (GET_CODE (addr1) != REG)
8561 return 0;
8562 else
8563 {
8564 reg1 = REGNO (addr1);
8565 /* This was a simple (mem (reg)) expression. Offset is 0. */
8566 offset1 = 0;
8567 }
8568
a2369ed3 8569 /* Make sure the second address is a (mem (plus (reg) (const_int)))
0f6937fe
AM
8570 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8571 register as addr1. */
984e25ac 8572 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 8573 return 1;
35068b43
RK
8574 if (GET_CODE (addr2) != PLUS)
8575 return 0;
8576
8577 if (GET_CODE (XEXP (addr2, 0)) != REG
8578 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8579 return 0;
8580
8581 if (reg1 != REGNO (XEXP (addr2, 0)))
8582 return 0;
8583
8584 /* The offset for the second addr must be 8 more than the first addr. */
8585 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8586 return 0;
8587
8588 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8589 instructions. */
8590 return 1;
8591}
9878760c
RK
8592\f
8593/* Return the register class of a scratch register needed to copy IN into
8594 or out of a register in CLASS in MODE. If it can be done directly,
8595 NO_REGS is returned. */
8596
8597enum reg_class
a2369ed3 8598secondary_reload_class (enum reg_class class,
a9baceb1
GK
8599 enum machine_mode mode ATTRIBUTE_UNUSED,
8600 rtx in)
9878760c 8601{
5accd822 8602 int regno;
9878760c 8603
ab82a49f
AP
8604 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8605#if TARGET_MACHO
8606 && MACHOPIC_INDIRECT
8607#endif
8608 ))
46fad5b7
DJ
8609 {
8610 /* We cannot copy a symbolic operand directly into anything
8611 other than BASE_REGS for TARGET_ELF. So indicate that a
8612 register from BASE_REGS is needed as an intermediate
8613 register.
8614
8615 On Darwin, pic addresses require a load from memory, which
8616 needs a base register. */
8617 if (class != BASE_REGS
8618 && (GET_CODE (in) == SYMBOL_REF
8619 || GET_CODE (in) == HIGH
8620 || GET_CODE (in) == LABEL_REF
8621 || GET_CODE (in) == CONST))
8622 return BASE_REGS;
8623 }
e7b7998a 8624
5accd822
DE
8625 if (GET_CODE (in) == REG)
8626 {
8627 regno = REGNO (in);
8628 if (regno >= FIRST_PSEUDO_REGISTER)
8629 {
8630 regno = true_regnum (in);
8631 if (regno >= FIRST_PSEUDO_REGISTER)
8632 regno = -1;
8633 }
8634 }
8635 else if (GET_CODE (in) == SUBREG)
8636 {
8637 regno = true_regnum (in);
8638 if (regno >= FIRST_PSEUDO_REGISTER)
8639 regno = -1;
8640 }
8641 else
8642 regno = -1;
8643
9878760c
RK
8644 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8645 into anything. */
8646 if (class == GENERAL_REGS || class == BASE_REGS
8647 || (regno >= 0 && INT_REGNO_P (regno)))
8648 return NO_REGS;
8649
8650 /* Constants, memory, and FP registers can go into FP registers. */
8651 if ((regno == -1 || FP_REGNO_P (regno))
8652 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8653 return NO_REGS;
8654
0ac081f6
AH
8655 /* Memory, and AltiVec registers can go into AltiVec registers. */
8656 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8657 && class == ALTIVEC_REGS)
8658 return NO_REGS;
8659
9878760c
RK
8660 /* We can copy among the CR registers. */
8661 if ((class == CR_REGS || class == CR0_REGS)
8662 && regno >= 0 && CR_REGNO_P (regno))
8663 return NO_REGS;
8664
8665 /* Otherwise, we need GENERAL_REGS. */
8666 return GENERAL_REGS;
8667}
8668\f
8669/* Given a comparison operation, return the bit number in CCR to test. We
8670 know this is a valid comparison.
8671
8672 SCC_P is 1 if this is for an scc. That means that %D will have been
8673 used instead of %C, so the bits will be in different places.
8674
b4ac57ab 8675 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8676
8677int
a2369ed3 8678ccr_bit (rtx op, int scc_p)
9878760c
RK
8679{
8680 enum rtx_code code = GET_CODE (op);
8681 enum machine_mode cc_mode;
8682 int cc_regnum;
8683 int base_bit;
9ebbca7d 8684 rtx reg;
9878760c 8685
ec8e098d 8686 if (!COMPARISON_P (op))
9878760c
RK
8687 return -1;
8688
9ebbca7d
GK
8689 reg = XEXP (op, 0);
8690
8691 if (GET_CODE (reg) != REG
8692 || ! CR_REGNO_P (REGNO (reg)))
8693 abort ();
8694
8695 cc_mode = GET_MODE (reg);
8696 cc_regnum = REGNO (reg);
8697 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8698
39a10a29 8699 validate_condition_mode (code, cc_mode);
c5defebb 8700
b7053a3f
GK
8701 /* When generating a sCOND operation, only positive conditions are
8702 allowed. */
8703 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8704 && code != GTU && code != LTU)
8705 abort ();
8706
9878760c
RK
8707 switch (code)
8708 {
8709 case NE:
993f19a8
AH
8710 if (TARGET_E500 && !TARGET_FPRS
8711 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8712 return base_bit + 1;
9878760c
RK
8713 return scc_p ? base_bit + 3 : base_bit + 2;
8714 case EQ:
993f19a8
AH
8715 if (TARGET_E500 && !TARGET_FPRS
8716 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8717 return base_bit + 1;
9878760c 8718 return base_bit + 2;
1c882ea4 8719 case GT: case GTU: case UNLE:
9878760c 8720 return base_bit + 1;
1c882ea4 8721 case LT: case LTU: case UNGE:
9878760c 8722 return base_bit;
1c882ea4
GK
8723 case ORDERED: case UNORDERED:
8724 return base_bit + 3;
9878760c
RK
8725
8726 case GE: case GEU:
39a10a29 8727 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8728 unordered position. So test that bit. For integer, this is ! LT
8729 unless this is an scc insn. */
39a10a29 8730 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8731
8732 case LE: case LEU:
39a10a29 8733 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8734
9878760c
RK
8735 default:
8736 abort ();
8737 }
8738}
1ff7789b 8739\f
8d30c4ee 8740/* Return the GOT register. */
1ff7789b
MM
8741
8742struct rtx_def *
a2369ed3 8743rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 8744{
a4f6c312
SS
8745 /* The second flow pass currently (June 1999) can't update
8746 regs_ever_live without disturbing other parts of the compiler, so
8747 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8748 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8749 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8750
8d30c4ee 8751 current_function_uses_pic_offset_table = 1;
3cb999d8 8752
1ff7789b
MM
8753 return pic_offset_table_rtx;
8754}
a7df97e6 8755\f
e2500fed
GK
8756/* Function to init struct machine_function.
8757 This will be called, via a pointer variable,
8758 from push_function_context. */
a7df97e6 8759
e2500fed 8760static struct machine_function *
863d938c 8761rs6000_init_machine_status (void)
a7df97e6 8762{
e2500fed 8763 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8764}
9878760c 8765\f
0ba1b2ff
AM
8766/* These macros test for integers and extract the low-order bits. */
8767#define INT_P(X) \
8768((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8769 && GET_MODE (X) == VOIDmode)
8770
8771#define INT_LOWPART(X) \
8772 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8773
8774int
a2369ed3 8775extract_MB (rtx op)
0ba1b2ff
AM
8776{
8777 int i;
8778 unsigned long val = INT_LOWPART (op);
8779
8780 /* If the high bit is zero, the value is the first 1 bit we find
8781 from the left. */
8782 if ((val & 0x80000000) == 0)
8783 {
8784 if ((val & 0xffffffff) == 0)
8785 abort ();
8786
8787 i = 1;
8788 while (((val <<= 1) & 0x80000000) == 0)
8789 ++i;
8790 return i;
8791 }
8792
8793 /* If the high bit is set and the low bit is not, or the mask is all
8794 1's, the value is zero. */
8795 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8796 return 0;
8797
8798 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8799 from the right. */
8800 i = 31;
8801 while (((val >>= 1) & 1) != 0)
8802 --i;
8803
8804 return i;
8805}
8806
8807int
a2369ed3 8808extract_ME (rtx op)
0ba1b2ff
AM
8809{
8810 int i;
8811 unsigned long val = INT_LOWPART (op);
8812
8813 /* If the low bit is zero, the value is the first 1 bit we find from
8814 the right. */
8815 if ((val & 1) == 0)
8816 {
8817 if ((val & 0xffffffff) == 0)
8818 abort ();
8819
8820 i = 30;
8821 while (((val >>= 1) & 1) == 0)
8822 --i;
8823
8824 return i;
8825 }
8826
8827 /* If the low bit is set and the high bit is not, or the mask is all
8828 1's, the value is 31. */
8829 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8830 return 31;
8831
8832 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8833 from the left. */
8834 i = 0;
8835 while (((val <<= 1) & 0x80000000) != 0)
8836 ++i;
8837
8838 return i;
8839}
8840
c4501e62
JJ
8841/* Locate some local-dynamic symbol still in use by this function
8842 so that we can print its name in some tls_ld pattern. */
8843
8844static const char *
863d938c 8845rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8846{
8847 rtx insn;
8848
8849 if (cfun->machine->some_ld_name)
8850 return cfun->machine->some_ld_name;
8851
8852 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8853 if (INSN_P (insn)
8854 && for_each_rtx (&PATTERN (insn),
8855 rs6000_get_some_local_dynamic_name_1, 0))
8856 return cfun->machine->some_ld_name;
8857
8858 abort ();
8859}
8860
8861/* Helper function for rs6000_get_some_local_dynamic_name. */
8862
8863static int
a2369ed3 8864rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8865{
8866 rtx x = *px;
8867
8868 if (GET_CODE (x) == SYMBOL_REF)
8869 {
8870 const char *str = XSTR (x, 0);
8871 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8872 {
8873 cfun->machine->some_ld_name = str;
8874 return 1;
8875 }
8876 }
8877
8878 return 0;
8879}
8880
9878760c
RK
8881/* Print an operand. Recognize special options, documented below. */
8882
38c1f2d7 8883#if TARGET_ELF
d9407988 8884#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8885#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8886#else
8887#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8888#define SMALL_DATA_REG 0
ba5e43aa
MM
8889#endif
8890
9878760c 8891void
a2369ed3 8892print_operand (FILE *file, rtx x, int code)
9878760c
RK
8893{
8894 int i;
a260abc9 8895 HOST_WIDE_INT val;
0ba1b2ff 8896 unsigned HOST_WIDE_INT uval;
9878760c
RK
8897
8898 switch (code)
8899 {
a8b3aeda 8900 case '.':
a85d226b
RK
8901 /* Write out an instruction after the call which may be replaced
8902 with glue code by the loader. This depends on the AIX version. */
8903 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8904 return;
8905
81eace42
GK
8906 /* %a is output_address. */
8907
9854d9ed
RK
8908 case 'A':
8909 /* If X is a constant integer whose low-order 5 bits are zero,
8910 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8911 in the AIX assembler where "sri" with a zero shift count
20e26713 8912 writes a trash instruction. */
9854d9ed 8913 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8914 putc ('l', file);
9854d9ed 8915 else
76229ac8 8916 putc ('r', file);
9854d9ed
RK
8917 return;
8918
8919 case 'b':
e2c953b6
DE
8920 /* If constant, low-order 16 bits of constant, unsigned.
8921 Otherwise, write normally. */
8922 if (INT_P (x))
8923 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8924 else
8925 print_operand (file, x, 0);
cad12a8d
RK
8926 return;
8927
a260abc9
DE
8928 case 'B':
8929 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8930 for 64-bit mask direction. */
296b8152 8931 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8932 return;
a260abc9 8933
81eace42
GK
8934 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8935 output_operand. */
8936
9854d9ed 8937 case 'E':
39a10a29 8938 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8939 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8940 output_operand_lossage ("invalid %%E value");
78fbdbf7 8941 else
39a10a29 8942 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8943 return;
9854d9ed
RK
8944
8945 case 'f':
8946 /* X is a CR register. Print the shift count needed to move it
8947 to the high-order four bits. */
8948 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8949 output_operand_lossage ("invalid %%f value");
8950 else
9ebbca7d 8951 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8952 return;
8953
8954 case 'F':
8955 /* Similar, but print the count for the rotate in the opposite
8956 direction. */
8957 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8958 output_operand_lossage ("invalid %%F value");
8959 else
9ebbca7d 8960 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8961 return;
8962
8963 case 'G':
8964 /* X is a constant integer. If it is negative, print "m",
43aa4e05 8965 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
8966 if (GET_CODE (x) != CONST_INT)
8967 output_operand_lossage ("invalid %%G value");
8968 else if (INTVAL (x) >= 0)
76229ac8 8969 putc ('z', file);
9854d9ed 8970 else
76229ac8 8971 putc ('m', file);
9854d9ed 8972 return;
e2c953b6 8973
9878760c 8974 case 'h':
a4f6c312
SS
8975 /* If constant, output low-order five bits. Otherwise, write
8976 normally. */
9878760c 8977 if (INT_P (x))
5f59ecb7 8978 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
8979 else
8980 print_operand (file, x, 0);
8981 return;
8982
64305719 8983 case 'H':
a4f6c312
SS
8984 /* If constant, output low-order six bits. Otherwise, write
8985 normally. */
64305719 8986 if (INT_P (x))
5f59ecb7 8987 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
8988 else
8989 print_operand (file, x, 0);
8990 return;
8991
9854d9ed
RK
8992 case 'I':
8993 /* Print `i' if this is a constant, else nothing. */
9878760c 8994 if (INT_P (x))
76229ac8 8995 putc ('i', file);
9878760c
RK
8996 return;
8997
9854d9ed
RK
8998 case 'j':
8999 /* Write the bit number in CCR for jump. */
9000 i = ccr_bit (x, 0);
9001 if (i == -1)
9002 output_operand_lossage ("invalid %%j code");
9878760c 9003 else
9854d9ed 9004 fprintf (file, "%d", i);
9878760c
RK
9005 return;
9006
9854d9ed
RK
9007 case 'J':
9008 /* Similar, but add one for shift count in rlinm for scc and pass
9009 scc flag to `ccr_bit'. */
9010 i = ccr_bit (x, 1);
9011 if (i == -1)
9012 output_operand_lossage ("invalid %%J code");
9013 else
a0466a68
RK
9014 /* If we want bit 31, write a shift count of zero, not 32. */
9015 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
9016 return;
9017
9854d9ed
RK
9018 case 'k':
9019 /* X must be a constant. Write the 1's complement of the
9020 constant. */
9878760c 9021 if (! INT_P (x))
9854d9ed 9022 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
9023 else
9024 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
9025 return;
9026
81eace42 9027 case 'K':
9ebbca7d
GK
9028 /* X must be a symbolic constant on ELF. Write an
9029 expression suitable for an 'addi' that adds in the low 16
9030 bits of the MEM. */
9031 if (GET_CODE (x) != CONST)
9032 {
9033 print_operand_address (file, x);
9034 fputs ("@l", file);
9035 }
9036 else
9037 {
9038 if (GET_CODE (XEXP (x, 0)) != PLUS
9039 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
9040 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
9041 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 9042 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
9043 print_operand_address (file, XEXP (XEXP (x, 0), 0));
9044 fputs ("@l", file);
ed8d2920
MM
9045 /* For GNU as, there must be a non-alphanumeric character
9046 between 'l' and the number. The '-' is added by
9047 print_operand() already. */
9048 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
9049 fputs ("+", file);
9ebbca7d
GK
9050 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
9051 }
81eace42
GK
9052 return;
9053
9054 /* %l is output_asm_label. */
9ebbca7d 9055
9854d9ed
RK
9056 case 'L':
9057 /* Write second word of DImode or DFmode reference. Works on register
9058 or non-indexed memory only. */
9059 if (GET_CODE (x) == REG)
5ebfb2ba 9060 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
9061 else if (GET_CODE (x) == MEM)
9062 {
9063 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 9064 we have already done it, we can just use an offset of word. */
9854d9ed
RK
9065 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9066 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
9067 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
9068 UNITS_PER_WORD));
9854d9ed 9069 else
d7624dc0
RK
9070 output_address (XEXP (adjust_address_nv (x, SImode,
9071 UNITS_PER_WORD),
9072 0));
ed8908e7 9073
ba5e43aa 9074 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9075 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9076 reg_names[SMALL_DATA_REG]);
9854d9ed 9077 }
9878760c 9078 return;
9854d9ed 9079
9878760c
RK
9080 case 'm':
9081 /* MB value for a mask operand. */
b1765bde 9082 if (! mask_operand (x, SImode))
9878760c
RK
9083 output_operand_lossage ("invalid %%m value");
9084
0ba1b2ff 9085 fprintf (file, "%d", extract_MB (x));
9878760c
RK
9086 return;
9087
9088 case 'M':
9089 /* ME value for a mask operand. */
b1765bde 9090 if (! mask_operand (x, SImode))
a260abc9 9091 output_operand_lossage ("invalid %%M value");
9878760c 9092
0ba1b2ff 9093 fprintf (file, "%d", extract_ME (x));
9878760c
RK
9094 return;
9095
81eace42
GK
9096 /* %n outputs the negative of its operand. */
9097
9878760c
RK
9098 case 'N':
9099 /* Write the number of elements in the vector times 4. */
9100 if (GET_CODE (x) != PARALLEL)
9101 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
9102 else
9103 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
9104 return;
9105
9106 case 'O':
9107 /* Similar, but subtract 1 first. */
9108 if (GET_CODE (x) != PARALLEL)
1427100a 9109 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
9110 else
9111 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
9112 return;
9113
9854d9ed
RK
9114 case 'p':
9115 /* X is a CONST_INT that is a power of two. Output the logarithm. */
9116 if (! INT_P (x)
2bfcf297 9117 || INT_LOWPART (x) < 0
9854d9ed
RK
9118 || (i = exact_log2 (INT_LOWPART (x))) < 0)
9119 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
9120 else
9121 fprintf (file, "%d", i);
9854d9ed
RK
9122 return;
9123
9878760c
RK
9124 case 'P':
9125 /* The operand must be an indirect memory reference. The result
8bb418a3 9126 is the register name. */
9878760c
RK
9127 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
9128 || REGNO (XEXP (x, 0)) >= 32)
9129 output_operand_lossage ("invalid %%P value");
e2c953b6 9130 else
8bb418a3 9131 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
9132 return;
9133
dfbdccdb
GK
9134 case 'q':
9135 /* This outputs the logical code corresponding to a boolean
9136 expression. The expression may have one or both operands
39a10a29
GK
9137 negated (if one, only the first one). For condition register
9138 logical operations, it will also treat the negated
9139 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 9140 {
63bc1d05 9141 const char *const *t = 0;
dfbdccdb
GK
9142 const char *s;
9143 enum rtx_code code = GET_CODE (x);
9144 static const char * const tbl[3][3] = {
9145 { "and", "andc", "nor" },
9146 { "or", "orc", "nand" },
9147 { "xor", "eqv", "xor" } };
9148
9149 if (code == AND)
9150 t = tbl[0];
9151 else if (code == IOR)
9152 t = tbl[1];
9153 else if (code == XOR)
9154 t = tbl[2];
9155 else
9156 output_operand_lossage ("invalid %%q value");
9157
9158 if (GET_CODE (XEXP (x, 0)) != NOT)
9159 s = t[0];
9160 else
9161 {
9162 if (GET_CODE (XEXP (x, 1)) == NOT)
9163 s = t[2];
9164 else
9165 s = t[1];
9166 }
9167
9168 fputs (s, file);
9169 }
9170 return;
9171
2c4a9cff
DE
9172 case 'Q':
9173 if (TARGET_MFCRF)
3b6ce0af 9174 fputc (',', file);
5efb1046 9175 /* FALLTHRU */
2c4a9cff
DE
9176 else
9177 return;
9178
9854d9ed
RK
9179 case 'R':
9180 /* X is a CR register. Print the mask for `mtcrf'. */
9181 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9182 output_operand_lossage ("invalid %%R value");
9183 else
9ebbca7d 9184 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 9185 return;
9854d9ed
RK
9186
9187 case 's':
9188 /* Low 5 bits of 32 - value */
9189 if (! INT_P (x))
9190 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
9191 else
9192 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 9193 return;
9854d9ed 9194
a260abc9 9195 case 'S':
0ba1b2ff 9196 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
9197 CONST_INT 32-bit mask is considered sign-extended so any
9198 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 9199 if (! mask64_operand (x, DImode))
a260abc9
DE
9200 output_operand_lossage ("invalid %%S value");
9201
0ba1b2ff 9202 uval = INT_LOWPART (x);
a260abc9 9203
0ba1b2ff 9204 if (uval & 1) /* Clear Left */
a260abc9 9205 {
f099d360
GK
9206#if HOST_BITS_PER_WIDE_INT > 64
9207 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9208#endif
0ba1b2ff 9209 i = 64;
a260abc9 9210 }
0ba1b2ff 9211 else /* Clear Right */
a260abc9 9212 {
0ba1b2ff 9213 uval = ~uval;
f099d360
GK
9214#if HOST_BITS_PER_WIDE_INT > 64
9215 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9216#endif
0ba1b2ff 9217 i = 63;
a260abc9 9218 }
0ba1b2ff
AM
9219 while (uval != 0)
9220 --i, uval >>= 1;
9221 if (i < 0)
9222 abort ();
9223 fprintf (file, "%d", i);
9224 return;
a260abc9 9225
a3170dc6
AH
9226 case 't':
9227 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9228 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9229 abort ();
9230
9231 /* Bit 3 is OV bit. */
9232 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9233
9234 /* If we want bit 31, write a shift count of zero, not 32. */
9235 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9236 return;
9237
cccf3bdc
DE
9238 case 'T':
9239 /* Print the symbolic name of a branch target register. */
9240 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9241 && REGNO (x) != COUNT_REGISTER_REGNUM))
9242 output_operand_lossage ("invalid %%T value");
e2c953b6 9243 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9244 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9245 else
9246 fputs ("ctr", file);
9247 return;
9248
9854d9ed 9249 case 'u':
802a0058 9250 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9251 if (! INT_P (x))
9252 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9253 else
9254 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9255 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9256 return;
9257
802a0058
MM
9258 case 'v':
9259 /* High-order 16 bits of constant for use in signed operand. */
9260 if (! INT_P (x))
9261 output_operand_lossage ("invalid %%v value");
e2c953b6 9262 else
134c32f6
DE
9263 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9264 (INT_LOWPART (x) >> 16) & 0xffff);
9265 return;
802a0058 9266
9854d9ed
RK
9267 case 'U':
9268 /* Print `u' if this has an auto-increment or auto-decrement. */
9269 if (GET_CODE (x) == MEM
9270 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9271 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9272 putc ('u', file);
9854d9ed 9273 return;
9878760c 9274
e0cd0770
JC
9275 case 'V':
9276 /* Print the trap code for this operand. */
9277 switch (GET_CODE (x))
9278 {
9279 case EQ:
9280 fputs ("eq", file); /* 4 */
9281 break;
9282 case NE:
9283 fputs ("ne", file); /* 24 */
9284 break;
9285 case LT:
9286 fputs ("lt", file); /* 16 */
9287 break;
9288 case LE:
9289 fputs ("le", file); /* 20 */
9290 break;
9291 case GT:
9292 fputs ("gt", file); /* 8 */
9293 break;
9294 case GE:
9295 fputs ("ge", file); /* 12 */
9296 break;
9297 case LTU:
9298 fputs ("llt", file); /* 2 */
9299 break;
9300 case LEU:
9301 fputs ("lle", file); /* 6 */
9302 break;
9303 case GTU:
9304 fputs ("lgt", file); /* 1 */
9305 break;
9306 case GEU:
9307 fputs ("lge", file); /* 5 */
9308 break;
9309 default:
9310 abort ();
9311 }
9312 break;
9313
9854d9ed
RK
9314 case 'w':
9315 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9316 normally. */
9317 if (INT_P (x))
5f59ecb7
DE
9318 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9319 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9320 else
9321 print_operand (file, x, 0);
9878760c
RK
9322 return;
9323
9854d9ed 9324 case 'W':
e2c953b6 9325 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9326 val = (GET_CODE (x) == CONST_INT
9327 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9328
9329 if (val < 0)
9330 i = -1;
9854d9ed 9331 else
e2c953b6
DE
9332 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9333 if ((val <<= 1) < 0)
9334 break;
9335
9336#if HOST_BITS_PER_WIDE_INT == 32
9337 if (GET_CODE (x) == CONST_INT && i >= 0)
9338 i += 32; /* zero-extend high-part was all 0's */
9339 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9340 {
9341 val = CONST_DOUBLE_LOW (x);
9342
9343 if (val == 0)
a4f6c312 9344 abort ();
e2c953b6
DE
9345 else if (val < 0)
9346 --i;
9347 else
9348 for ( ; i < 64; i++)
9349 if ((val <<= 1) < 0)
9350 break;
9351 }
9352#endif
9353
9354 fprintf (file, "%d", i + 1);
9854d9ed 9355 return;
9878760c 9356
9854d9ed
RK
9357 case 'X':
9358 if (GET_CODE (x) == MEM
4d588c14 9359 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9360 putc ('x', file);
9854d9ed 9361 return;
9878760c 9362
9854d9ed
RK
9363 case 'Y':
9364 /* Like 'L', for third word of TImode */
9365 if (GET_CODE (x) == REG)
5ebfb2ba 9366 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9367 else if (GET_CODE (x) == MEM)
9878760c 9368 {
9854d9ed
RK
9369 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9370 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9371 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9372 else
d7624dc0 9373 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9374 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9375 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9376 reg_names[SMALL_DATA_REG]);
9878760c
RK
9377 }
9378 return;
9854d9ed 9379
9878760c 9380 case 'z':
b4ac57ab
RS
9381 /* X is a SYMBOL_REF. Write out the name preceded by a
9382 period and without any trailing data in brackets. Used for function
4d30c363
MM
9383 names. If we are configured for System V (or the embedded ABI) on
9384 the PowerPC, do not emit the period, since those systems do not use
9385 TOCs and the like. */
9878760c
RK
9386 if (GET_CODE (x) != SYMBOL_REF)
9387 abort ();
9388
b6c9286a
MM
9389 if (XSTR (x, 0)[0] != '.')
9390 {
9391 switch (DEFAULT_ABI)
9392 {
9393 default:
9394 abort ();
9395
9396 case ABI_AIX:
9397 putc ('.', file);
9398 break;
9399
9400 case ABI_V4:
ee890fe2 9401 case ABI_DARWIN:
b6c9286a 9402 break;
b6c9286a
MM
9403 }
9404 }
9739c90c
JJ
9405 if (TARGET_AIX)
9406 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9407 else
9408 assemble_name (file, XSTR (x, 0));
9878760c
RK
9409 return;
9410
9854d9ed
RK
9411 case 'Z':
9412 /* Like 'L', for last word of TImode. */
9413 if (GET_CODE (x) == REG)
5ebfb2ba 9414 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9415 else if (GET_CODE (x) == MEM)
9416 {
9417 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9418 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9419 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9420 else
d7624dc0 9421 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9422 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9423 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9424 reg_names[SMALL_DATA_REG]);
9854d9ed 9425 }
5c23c401 9426 return;
0ac081f6 9427
a3170dc6 9428 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9429 case 'y':
9430 {
9431 rtx tmp;
9432
9433 if (GET_CODE (x) != MEM)
9434 abort ();
9435
9436 tmp = XEXP (x, 0);
9437
993f19a8 9438 if (TARGET_E500)
a3170dc6
AH
9439 {
9440 /* Handle [reg]. */
9441 if (GET_CODE (tmp) == REG)
9442 {
9443 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9444 break;
9445 }
9446 /* Handle [reg+UIMM]. */
9447 else if (GET_CODE (tmp) == PLUS &&
9448 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9449 {
9450 int x;
9451
9452 if (GET_CODE (XEXP (tmp, 0)) != REG)
9453 abort ();
9454
9455 x = INTVAL (XEXP (tmp, 1));
9456 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9457 break;
9458 }
9459
9460 /* Fall through. Must be [reg+reg]. */
9461 }
0ac081f6 9462 if (GET_CODE (tmp) == REG)
c62f2db5 9463 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9464 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9465 {
9466 if (REGNO (XEXP (tmp, 0)) == 0)
9467 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9468 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9469 else
9470 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9471 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9472 }
9473 else
9474 abort ();
9475 break;
9476 }
9854d9ed 9477
9878760c
RK
9478 case 0:
9479 if (GET_CODE (x) == REG)
9480 fprintf (file, "%s", reg_names[REGNO (x)]);
9481 else if (GET_CODE (x) == MEM)
9482 {
9483 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9484 know the width from the mode. */
9485 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9486 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9487 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9488 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9489 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9490 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9491 else
a54d04b7 9492 output_address (XEXP (x, 0));
9878760c
RK
9493 }
9494 else
a54d04b7 9495 output_addr_const (file, x);
a85d226b 9496 return;
9878760c 9497
c4501e62
JJ
9498 case '&':
9499 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9500 return;
9501
9878760c
RK
9502 default:
9503 output_operand_lossage ("invalid %%xn code");
9504 }
9505}
9506\f
9507/* Print the address of an operand. */
9508
9509void
a2369ed3 9510print_operand_address (FILE *file, rtx x)
9878760c
RK
9511{
9512 if (GET_CODE (x) == REG)
4697a36c 9513 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9514 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9515 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9516 {
9517 output_addr_const (file, x);
ba5e43aa 9518 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9519 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9520 reg_names[SMALL_DATA_REG]);
9ebbca7d 9521 else if (TARGET_TOC)
a4f6c312 9522 abort ();
9878760c
RK
9523 }
9524 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9525 {
9526 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9527 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9528 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9529 else
4697a36c
MM
9530 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9531 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9532 }
9533 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9534 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9535 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9536#if TARGET_ELF
9537 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9538 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9539 {
9540 output_addr_const (file, XEXP (x, 1));
9541 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9542 }
c859cda6
DJ
9543#endif
9544#if TARGET_MACHO
9545 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9546 && CONSTANT_P (XEXP (x, 1)))
9547 {
9548 fprintf (file, "lo16(");
9549 output_addr_const (file, XEXP (x, 1));
9550 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9551 }
3cb999d8 9552#endif
4d588c14 9553 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9554 {
2bfcf297 9555 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9556 {
2bfcf297
DB
9557 rtx contains_minus = XEXP (x, 1);
9558 rtx minus, symref;
9559 const char *name;
9ebbca7d
GK
9560
9561 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9562 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9563 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9564 contains_minus = XEXP (contains_minus, 0);
9565
2bfcf297
DB
9566 minus = XEXP (contains_minus, 0);
9567 symref = XEXP (minus, 0);
9568 XEXP (contains_minus, 0) = symref;
9569 if (TARGET_ELF)
9570 {
9571 char *newname;
9572
9573 name = XSTR (symref, 0);
9574 newname = alloca (strlen (name) + sizeof ("@toc"));
9575 strcpy (newname, name);
9576 strcat (newname, "@toc");
9577 XSTR (symref, 0) = newname;
9578 }
9579 output_addr_const (file, XEXP (x, 1));
9580 if (TARGET_ELF)
9581 XSTR (symref, 0) = name;
9ebbca7d
GK
9582 XEXP (contains_minus, 0) = minus;
9583 }
9584 else
9585 output_addr_const (file, XEXP (x, 1));
9586
9587 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9588 }
9878760c
RK
9589 else
9590 abort ();
9591}
9592\f
88cad84b 9593/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9594 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9595 is defined. It also needs to handle DI-mode objects on 64-bit
9596 targets. */
9597
9598static bool
a2369ed3 9599rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9600{
9601#ifdef RELOCATABLE_NEEDS_FIXUP
9602 /* Special handling for SI values. */
9603 if (size == 4 && aligned_p)
9604 {
a2369ed3 9605 extern int in_toc_section (void);
301d03af
RS
9606 static int recurse = 0;
9607
9608 /* For -mrelocatable, we mark all addresses that need to be fixed up
9609 in the .fixup section. */
9610 if (TARGET_RELOCATABLE
9611 && !in_toc_section ()
9612 && !in_text_section ()
9613 && !recurse
9614 && GET_CODE (x) != CONST_INT
9615 && GET_CODE (x) != CONST_DOUBLE
9616 && CONSTANT_P (x))
9617 {
9618 char buf[256];
9619
9620 recurse = 1;
9621 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9622 fixuplabelno++;
9623 ASM_OUTPUT_LABEL (asm_out_file, buf);
9624 fprintf (asm_out_file, "\t.long\t(");
9625 output_addr_const (asm_out_file, x);
9626 fprintf (asm_out_file, ")@fixup\n");
9627 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9628 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9629 fprintf (asm_out_file, "\t.long\t");
9630 assemble_name (asm_out_file, buf);
9631 fprintf (asm_out_file, "\n\t.previous\n");
9632 recurse = 0;
9633 return true;
9634 }
9635 /* Remove initial .'s to turn a -mcall-aixdesc function
9636 address into the address of the descriptor, not the function
9637 itself. */
9638 else if (GET_CODE (x) == SYMBOL_REF
9639 && XSTR (x, 0)[0] == '.'
9640 && DEFAULT_ABI == ABI_AIX)
9641 {
9642 const char *name = XSTR (x, 0);
9643 while (*name == '.')
9644 name++;
9645
9646 fprintf (asm_out_file, "\t.long\t%s\n", name);
9647 return true;
9648 }
9649 }
9650#endif /* RELOCATABLE_NEEDS_FIXUP */
9651 return default_assemble_integer (x, size, aligned_p);
9652}
93638d7a
AM
9653
9654#ifdef HAVE_GAS_HIDDEN
9655/* Emit an assembler directive to set symbol visibility for DECL to
9656 VISIBILITY_TYPE. */
9657
5add3202 9658static void
a2369ed3 9659rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9660{
93638d7a
AM
9661 /* Functions need to have their entry point symbol visibility set as
9662 well as their descriptor symbol visibility. */
9663 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9664 {
25fdb4dc
RH
9665 static const char * const visibility_types[] = {
9666 NULL, "internal", "hidden", "protected"
9667 };
9668
9669 const char *name, *type;
93638d7a
AM
9670
9671 name = ((* targetm.strip_name_encoding)
9672 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9673 type = visibility_types[vis];
93638d7a 9674
25fdb4dc
RH
9675 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9676 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9677 }
25fdb4dc
RH
9678 else
9679 default_assemble_visibility (decl, vis);
93638d7a
AM
9680}
9681#endif
301d03af 9682\f
39a10a29 9683enum rtx_code
a2369ed3 9684rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9685{
9686 /* Reversal of FP compares takes care -- an ordered compare
9687 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9688 if (mode == CCFPmode
9689 && (!flag_finite_math_only
9690 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9691 || code == UNEQ || code == LTGT))
bab6226b 9692 return reverse_condition_maybe_unordered (code);
39a10a29 9693 else
bab6226b 9694 return reverse_condition (code);
39a10a29
GK
9695}
9696
39a10a29
GK
9697/* Generate a compare for CODE. Return a brand-new rtx that
9698 represents the result of the compare. */
a4f6c312 9699
39a10a29 9700static rtx
a2369ed3 9701rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
9702{
9703 enum machine_mode comp_mode;
9704 rtx compare_result;
9705
9706 if (rs6000_compare_fp_p)
9707 comp_mode = CCFPmode;
9708 else if (code == GTU || code == LTU
9709 || code == GEU || code == LEU)
9710 comp_mode = CCUNSmode;
9711 else
9712 comp_mode = CCmode;
9713
9714 /* First, the compare. */
9715 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9716
9717 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9718 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9719 && rs6000_compare_fp_p)
a3170dc6
AH
9720 {
9721 rtx cmp, or1, or2, or_result, compare_result2;
9722
9723 switch (code)
9724 {
9725 case EQ:
9726 case UNEQ:
9727 case NE:
9728 case LTGT:
bc9ec0e0 9729 cmp = flag_finite_math_only
a3170dc6
AH
9730 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9731 rs6000_compare_op1)
9732 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9733 rs6000_compare_op1);
9734 break;
9735 case GT:
9736 case GTU:
9737 case UNGT:
9738 case UNGE:
9739 case GE:
9740 case GEU:
bc9ec0e0 9741 cmp = flag_finite_math_only
a3170dc6
AH
9742 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9743 rs6000_compare_op1)
9744 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9745 rs6000_compare_op1);
9746 break;
9747 case LT:
9748 case LTU:
9749 case UNLT:
9750 case UNLE:
9751 case LE:
9752 case LEU:
bc9ec0e0 9753 cmp = flag_finite_math_only
a3170dc6
AH
9754 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9755 rs6000_compare_op1)
9756 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9757 rs6000_compare_op1);
9758 break;
9759 default:
9760 abort ();
9761 }
9762
9763 /* Synthesize LE and GE from LT/GT || EQ. */
9764 if (code == LE || code == GE || code == LEU || code == GEU)
9765 {
9766 /* Synthesize GE/LE frome GT/LT || EQ. */
9767
9768 emit_insn (cmp);
9769
9770 switch (code)
9771 {
9772 case LE: code = LT; break;
9773 case GE: code = GT; break;
9774 case LEU: code = LT; break;
9775 case GEU: code = GT; break;
9776 default: abort ();
9777 }
9778
9779 or1 = gen_reg_rtx (SImode);
9780 or2 = gen_reg_rtx (SImode);
9781 or_result = gen_reg_rtx (CCEQmode);
9782 compare_result2 = gen_reg_rtx (CCFPmode);
9783
9784 /* Do the EQ. */
bc9ec0e0 9785 cmp = flag_finite_math_only
a3170dc6
AH
9786 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9787 rs6000_compare_op1)
9788 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9789 rs6000_compare_op1);
9790 emit_insn (cmp);
9791
9792 /* The MC8540 FP compare instructions set the CR bits
9793 differently than other PPC compare instructions. For
9794 that matter, there is no generic test instruction, but a
9795 testgt, testlt, and testeq. For a true condition, bit 2
9796 is set (x1xx) in the CR. Following the traditional CR
9797 values:
9798
9799 LT GT EQ OV
9800 bit3 bit2 bit1 bit0
9801
9802 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9803 look in the GT bits for the branch instructions.
a3170dc6
AH
9804 However, we must be careful to emit correct RTL in
9805 the meantime, so optimizations don't get confused. */
9806
f1c25d3b
KH
9807 or1 = gen_rtx_NE (SImode, compare_result, const0_rtx);
9808 or2 = gen_rtx_NE (SImode, compare_result2, const0_rtx);
a3170dc6
AH
9809
9810 /* OR them together. */
9811 cmp = gen_rtx_SET (VOIDmode, or_result,
9812 gen_rtx_COMPARE (CCEQmode,
9813 gen_rtx_IOR (SImode, or1, or2),
9814 const_true_rtx));
9815 compare_result = or_result;
9816 code = EQ;
9817 }
9818 else
9819 {
9820 /* We only care about 1 bit (x1xx), so map everything to NE to
9821 maintain rtl sanity. We'll get to the right bit (x1xx) at
9822 code output time. */
9823 if (code == NE || code == LTGT)
9824 /* Do the inverse here because we have no cmpne
9825 instruction. We use the cmpeq instruction and expect
9826 to get a 0 instead. */
9827 code = EQ;
9828 else
9829 code = NE;
9830 }
9831
9832 emit_insn (cmp);
9833 }
9834 else
9835 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9836 gen_rtx_COMPARE (comp_mode,
9837 rs6000_compare_op0,
9838 rs6000_compare_op1)));
39a10a29 9839
ca5adc63 9840 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9841 under flag_finite_math_only we don't bother. */
39a10a29 9842 if (rs6000_compare_fp_p
bc9ec0e0 9843 && ! flag_finite_math_only
993f19a8 9844 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9845 && (code == LE || code == GE
9846 || code == UNEQ || code == LTGT
9847 || code == UNGT || code == UNLT))
9848 {
9849 enum rtx_code or1, or2;
9850 rtx or1_rtx, or2_rtx, compare2_rtx;
9851 rtx or_result = gen_reg_rtx (CCEQmode);
9852
9853 switch (code)
9854 {
9855 case LE: or1 = LT; or2 = EQ; break;
9856 case GE: or1 = GT; or2 = EQ; break;
9857 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9858 case LTGT: or1 = LT; or2 = GT; break;
9859 case UNGT: or1 = UNORDERED; or2 = GT; break;
9860 case UNLT: or1 = UNORDERED; or2 = LT; break;
9861 default: abort ();
9862 }
9863 validate_condition_mode (or1, comp_mode);
9864 validate_condition_mode (or2, comp_mode);
1c563bed
KH
9865 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
9866 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
9867 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9868 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9869 const_true_rtx);
9870 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9871
9872 compare_result = or_result;
9873 code = EQ;
9874 }
9875
9876 validate_condition_mode (code, GET_MODE (compare_result));
9877
1c563bed 9878 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
9879}
9880
9881
9882/* Emit the RTL for an sCOND pattern. */
9883
9884void
a2369ed3 9885rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9886{
9887 rtx condition_rtx;
9888 enum machine_mode op_mode;
b7053a3f 9889 enum rtx_code cond_code;
39a10a29
GK
9890
9891 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9892 cond_code = GET_CODE (condition_rtx);
9893
9894 if (cond_code == NE
9895 || cond_code == GE || cond_code == LE
9896 || cond_code == GEU || cond_code == LEU
9897 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9898 {
9899 rtx not_result = gen_reg_rtx (CCEQmode);
9900 rtx not_op, rev_cond_rtx;
9901 enum machine_mode cc_mode;
9902
9903 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9904
1c563bed 9905 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 9906 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
9907 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9908 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9909 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9910 }
39a10a29
GK
9911
9912 op_mode = GET_MODE (rs6000_compare_op0);
9913 if (op_mode == VOIDmode)
9914 op_mode = GET_MODE (rs6000_compare_op1);
9915
9916 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9917 {
9918 PUT_MODE (condition_rtx, DImode);
9919 convert_move (result, condition_rtx, 0);
9920 }
9921 else
9922 {
9923 PUT_MODE (condition_rtx, SImode);
9924 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9925 }
9926}
9927
39a10a29
GK
9928/* Emit a branch of kind CODE to location LOC. */
9929
9930void
a2369ed3 9931rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
9932{
9933 rtx condition_rtx, loc_ref;
9934
9935 condition_rtx = rs6000_generate_compare (code);
9936 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9937 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9938 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9939 loc_ref, pc_rtx)));
9940}
9941
12a4e8c5
GK
9942/* Return the string to output a conditional branch to LABEL, which is
9943 the operand number of the label, or -1 if the branch is really a
9944 conditional return.
9945
9946 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9947 condition code register and its mode specifies what kind of
9948 comparison we made.
9949
a0ab749a 9950 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9951
9952 INSN is the insn. */
9953
9954char *
a2369ed3 9955output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
9956{
9957 static char string[64];
9958 enum rtx_code code = GET_CODE (op);
9959 rtx cc_reg = XEXP (op, 0);
9960 enum machine_mode mode = GET_MODE (cc_reg);
9961 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 9962 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
9963 int really_reversed = reversed ^ need_longbranch;
9964 char *s = string;
9965 const char *ccode;
9966 const char *pred;
9967 rtx note;
9968
39a10a29
GK
9969 validate_condition_mode (code, mode);
9970
9971 /* Work out which way this really branches. We could use
9972 reverse_condition_maybe_unordered here always but this
9973 makes the resulting assembler clearer. */
12a4e8c5 9974 if (really_reversed)
de40e1df
DJ
9975 {
9976 /* Reversal of FP compares takes care -- an ordered compare
9977 becomes an unordered compare and vice versa. */
9978 if (mode == CCFPmode)
9979 code = reverse_condition_maybe_unordered (code);
9980 else
9981 code = reverse_condition (code);
9982 }
12a4e8c5 9983
993f19a8 9984 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
9985 {
9986 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
9987 to the GT bit. */
9988 if (code == EQ)
9989 /* Opposite of GT. */
9990 code = UNLE;
9991 else if (code == NE)
9992 code = GT;
9993 else
9994 abort ();
9995 }
9996
39a10a29 9997 switch (code)
12a4e8c5
GK
9998 {
9999 /* Not all of these are actually distinct opcodes, but
10000 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10001 case NE: case LTGT:
10002 ccode = "ne"; break;
10003 case EQ: case UNEQ:
10004 ccode = "eq"; break;
10005 case GE: case GEU:
10006 ccode = "ge"; break;
10007 case GT: case GTU: case UNGT:
10008 ccode = "gt"; break;
10009 case LE: case LEU:
10010 ccode = "le"; break;
10011 case LT: case LTU: case UNLT:
10012 ccode = "lt"; break;
12a4e8c5
GK
10013 case UNORDERED: ccode = "un"; break;
10014 case ORDERED: ccode = "nu"; break;
10015 case UNGE: ccode = "nl"; break;
10016 case UNLE: ccode = "ng"; break;
10017 default:
a4f6c312 10018 abort ();
12a4e8c5
GK
10019 }
10020
94a54f47
GK
10021 /* Maybe we have a guess as to how likely the branch is.
10022 The old mnemonics don't have a way to specify this information. */
f4857b9b 10023 pred = "";
12a4e8c5
GK
10024 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10025 if (note != NULL_RTX)
10026 {
10027 /* PROB is the difference from 50%. */
10028 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
10029 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
10030
10031 /* Only hint for highly probable/improbable branches on newer
10032 cpus as static prediction overrides processor dynamic
10033 prediction. For older cpus we may as well always hint, but
10034 assume not taken for branches that are very close to 50% as a
10035 mispredicted taken branch is more expensive than a
10036 mispredicted not-taken branch. */
10037 if (always_hint
10038 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
10039 {
10040 if (abs (prob) > REG_BR_PROB_BASE / 20
10041 && ((prob > 0) ^ need_longbranch))
7f3d8013 10042 pred = "+";
f4857b9b
AM
10043 else
10044 pred = "-";
10045 }
12a4e8c5 10046 }
12a4e8c5
GK
10047
10048 if (label == NULL)
94a54f47 10049 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 10050 else
94a54f47 10051 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 10052
37c67319 10053 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 10054 Assume they'd only be the first character.... */
37c67319
GK
10055 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
10056 *s++ = '%';
94a54f47 10057 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
10058
10059 if (label != NULL)
10060 {
10061 /* If the branch distance was too far, we may have to use an
10062 unconditional branch to go the distance. */
10063 if (need_longbranch)
44518ddd 10064 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
10065 else
10066 s += sprintf (s, ",%s", label);
10067 }
10068
10069 return string;
10070}
50a0b056
GK
10071
10072/* Emit a conditional move: move TRUE_COND to DEST if OP of the
10073 operands of the last comparison is nonzero/true, FALSE_COND if it
10074 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 10075
50a0b056 10076int
a2369ed3 10077rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
10078{
10079 enum rtx_code code = GET_CODE (op);
10080 rtx op0 = rs6000_compare_op0;
10081 rtx op1 = rs6000_compare_op1;
10082 REAL_VALUE_TYPE c1;
3148ad6d
DJ
10083 enum machine_mode compare_mode = GET_MODE (op0);
10084 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
10085 rtx temp;
10086
a3c9585f 10087 /* These modes should always match. */
a3170dc6
AH
10088 if (GET_MODE (op1) != compare_mode
10089 /* In the isel case however, we can use a compare immediate, so
10090 op1 may be a small constant. */
10091 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 10092 return 0;
178c3eff 10093 if (GET_MODE (true_cond) != result_mode)
3148ad6d 10094 return 0;
178c3eff 10095 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
10096 return 0;
10097
50a0b056 10098 /* First, work out if the hardware can do this at all, or
a3c9585f 10099 if it's too slow.... */
50a0b056 10100 if (! rs6000_compare_fp_p)
a3170dc6
AH
10101 {
10102 if (TARGET_ISEL)
10103 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
10104 return 0;
10105 }
50a0b056
GK
10106
10107 /* Eliminate half of the comparisons by switching operands, this
10108 makes the remaining code simpler. */
10109 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 10110 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
10111 {
10112 code = reverse_condition_maybe_unordered (code);
10113 temp = true_cond;
10114 true_cond = false_cond;
10115 false_cond = temp;
10116 }
10117
10118 /* UNEQ and LTGT take four instructions for a comparison with zero,
10119 it'll probably be faster to use a branch here too. */
bc9ec0e0 10120 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
10121 return 0;
10122
10123 if (GET_CODE (op1) == CONST_DOUBLE)
10124 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
10125
b6d08ca1 10126 /* We're going to try to implement comparisons by performing
50a0b056
GK
10127 a subtract, then comparing against zero. Unfortunately,
10128 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 10129 know that the operand is finite and the comparison
50a0b056 10130 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 10131 if (HONOR_INFINITIES (compare_mode)
50a0b056 10132 && code != GT && code != UNGE
045572c7 10133 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
10134 /* Constructs of the form (a OP b ? a : b) are safe. */
10135 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
10136 || (! rtx_equal_p (op0, true_cond)
10137 && ! rtx_equal_p (op1, true_cond))))
10138 return 0;
10139 /* At this point we know we can use fsel. */
10140
10141 /* Reduce the comparison to a comparison against zero. */
3148ad6d 10142 temp = gen_reg_rtx (compare_mode);
50a0b056 10143 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10144 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 10145 op0 = temp;
3148ad6d 10146 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
10147
10148 /* If we don't care about NaNs we can reduce some of the comparisons
10149 down to faster ones. */
bc9ec0e0 10150 if (! HONOR_NANS (compare_mode))
50a0b056
GK
10151 switch (code)
10152 {
10153 case GT:
10154 code = LE;
10155 temp = true_cond;
10156 true_cond = false_cond;
10157 false_cond = temp;
10158 break;
10159 case UNGE:
10160 code = GE;
10161 break;
10162 case UNEQ:
10163 code = EQ;
10164 break;
10165 default:
10166 break;
10167 }
10168
10169 /* Now, reduce everything down to a GE. */
10170 switch (code)
10171 {
10172 case GE:
10173 break;
10174
10175 case LE:
3148ad6d
DJ
10176 temp = gen_reg_rtx (compare_mode);
10177 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10178 op0 = temp;
10179 break;
10180
10181 case ORDERED:
3148ad6d
DJ
10182 temp = gen_reg_rtx (compare_mode);
10183 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
10184 op0 = temp;
10185 break;
10186
10187 case EQ:
3148ad6d 10188 temp = gen_reg_rtx (compare_mode);
50a0b056 10189 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
10190 gen_rtx_NEG (compare_mode,
10191 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
10192 op0 = temp;
10193 break;
10194
10195 case UNGE:
bc9ec0e0 10196 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 10197 temp = gen_reg_rtx (result_mode);
50a0b056 10198 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10199 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10200 gen_rtx_GE (VOIDmode,
10201 op0, op1),
10202 true_cond, false_cond)));
bc9ec0e0
GK
10203 false_cond = true_cond;
10204 true_cond = temp;
50a0b056 10205
3148ad6d
DJ
10206 temp = gen_reg_rtx (compare_mode);
10207 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10208 op0 = temp;
10209 break;
10210
10211 case GT:
bc9ec0e0 10212 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10213 temp = gen_reg_rtx (result_mode);
50a0b056 10214 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10215 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10216 gen_rtx_GE (VOIDmode,
10217 op0, op1),
10218 true_cond, false_cond)));
bc9ec0e0
GK
10219 true_cond = false_cond;
10220 false_cond = temp;
50a0b056 10221
3148ad6d
DJ
10222 temp = gen_reg_rtx (compare_mode);
10223 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10224 op0 = temp;
10225 break;
10226
10227 default:
10228 abort ();
10229 }
10230
10231 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10232 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10233 gen_rtx_GE (VOIDmode,
10234 op0, op1),
10235 true_cond, false_cond)));
10236 return 1;
10237}
10238
a3170dc6
AH
10239/* Same as above, but for ints (isel). */
10240
10241static int
a2369ed3 10242rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10243{
10244 rtx condition_rtx, cr;
10245
10246 /* All isel implementations thus far are 32-bits. */
10247 if (GET_MODE (rs6000_compare_op0) != SImode)
10248 return 0;
10249
10250 /* We still have to do the compare, because isel doesn't do a
10251 compare, it just looks at the CRx bits set by a previous compare
10252 instruction. */
10253 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10254 cr = XEXP (condition_rtx, 0);
10255
10256 if (GET_MODE (cr) == CCmode)
10257 emit_insn (gen_isel_signed (dest, condition_rtx,
10258 true_cond, false_cond, cr));
10259 else
10260 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10261 true_cond, false_cond, cr));
10262
10263 return 1;
10264}
10265
10266const char *
a2369ed3 10267output_isel (rtx *operands)
a3170dc6
AH
10268{
10269 enum rtx_code code;
10270
10271 code = GET_CODE (operands[1]);
10272 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10273 {
10274 PUT_CODE (operands[1], reverse_condition (code));
10275 return "isel %0,%3,%2,%j1";
10276 }
10277 else
10278 return "isel %0,%2,%3,%j1";
10279}
10280
50a0b056 10281void
a2369ed3 10282rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10283{
10284 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10285 enum rtx_code c;
50a0b056 10286 rtx target;
5dc8d536
AH
10287
10288 if (code == SMAX || code == SMIN)
10289 c = GE;
10290 else
10291 c = GEU;
10292
50a0b056 10293 if (code == SMAX || code == UMAX)
5dc8d536 10294 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10295 op0, op1, mode, 0);
10296 else
5dc8d536 10297 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10298 op1, op0, mode, 0);
10299 if (target == NULL_RTX)
10300 abort ();
10301 if (target != dest)
10302 emit_move_insn (dest, target);
10303}
46c07df8 10304
a9baceb1
GK
10305/* Emit instructions to move SRC to DST. Called by splitters for
10306 multi-register moves. It will emit at most one instruction for
10307 each register that is accessed; that is, it won't emit li/lis pairs
10308 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10309 register. */
46c07df8 10310
46c07df8 10311void
a9baceb1 10312rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10313{
a9baceb1
GK
10314 /* The register number of the first register being moved. */
10315 int reg;
10316 /* The mode that is to be moved. */
10317 enum machine_mode mode;
10318 /* The mode that the move is being done in, and its size. */
10319 enum machine_mode reg_mode;
10320 int reg_mode_size;
10321 /* The number of registers that will be moved. */
10322 int nregs;
10323
10324 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10325 mode = GET_MODE (dst);
10326 nregs = HARD_REGNO_NREGS (reg, mode);
10327 if (FP_REGNO_P (reg))
10328 reg_mode = DFmode;
10329 else if (ALTIVEC_REGNO_P (reg))
10330 reg_mode = V16QImode;
10331 else
10332 reg_mode = word_mode;
10333 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10334
a9baceb1
GK
10335 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10336 abort ();
10337
10338 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10339 {
10340 /* Move register range backwards, if we might have destructive
10341 overlap. */
10342 int i;
10343 for (i = nregs - 1; i >= 0; i--)
10344 emit_insn (gen_rtx_SET (VOIDmode,
10345 simplify_gen_subreg (reg_mode, dst, mode,
10346 i * reg_mode_size),
10347 simplify_gen_subreg (reg_mode, src, mode,
10348 i * reg_mode_size)));
10349 }
46c07df8
HP
10350 else
10351 {
a9baceb1
GK
10352 int i;
10353 int j = -1;
10354 bool used_update = false;
46c07df8 10355
a9baceb1 10356 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10357 {
10358 rtx breg;
3a1f863f 10359
a9baceb1
GK
10360 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10361 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10362 {
10363 rtx delta_rtx;
a9baceb1
GK
10364 breg = XEXP (XEXP (src, 0), 0);
10365 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10366 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10367 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10368 emit_insn (TARGET_32BIT
10369 ? gen_addsi3 (breg, breg, delta_rtx)
10370 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10371 src = gen_rtx_MEM (mode, breg);
10372 }
10373
10374 /* We have now address involving an base register only.
10375 If we use one of the registers to address memory,
10376 we have change that register last. */
10377
10378 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10379 ? XEXP (XEXP (src, 0), 0)
10380 : XEXP (src, 0));
10381
10382 if (!REG_P (breg))
10383 abort();
10384
10385 if (REGNO (breg) >= REGNO (dst)
10386 && REGNO (breg) < REGNO (dst) + nregs)
10387 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10388 }
10389
a9baceb1 10390 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10391 {
10392 rtx breg;
10393
a9baceb1
GK
10394 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10395 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10396 {
10397 rtx delta_rtx;
a9baceb1
GK
10398 breg = XEXP (XEXP (dst, 0), 0);
10399 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10400 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10401 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10402
10403 /* We have to update the breg before doing the store.
10404 Use store with update, if available. */
10405
10406 if (TARGET_UPDATE)
10407 {
a9baceb1
GK
10408 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10409 emit_insn (TARGET_32BIT
10410 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10411 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10412 used_update = true;
3a1f863f
DE
10413 }
10414 else
a9baceb1
GK
10415 emit_insn (TARGET_32BIT
10416 ? gen_addsi3 (breg, breg, delta_rtx)
10417 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10418 dst = gen_rtx_MEM (mode, breg);
10419 }
10420 }
10421
46c07df8 10422 for (i = 0; i < nregs; i++)
3a1f863f
DE
10423 {
10424 /* Calculate index to next subword. */
10425 ++j;
10426 if (j == nregs)
10427 j = 0;
46c07df8 10428
a9baceb1
GK
10429 /* If compiler already emited move of first word by
10430 store with update, no need to do anything. */
3a1f863f 10431 if (j == 0 && used_update)
a9baceb1
GK
10432 continue;
10433
10434 emit_insn (gen_rtx_SET (VOIDmode,
10435 simplify_gen_subreg (reg_mode, dst, mode,
10436 j * reg_mode_size),
10437 simplify_gen_subreg (reg_mode, src, mode,
10438 j * reg_mode_size)));
3a1f863f 10439 }
46c07df8
HP
10440 }
10441}
10442
12a4e8c5 10443\f
a4f6c312
SS
10444/* This page contains routines that are used to determine what the
10445 function prologue and epilogue code will do and write them out. */
9878760c 10446
a4f6c312
SS
10447/* Return the first fixed-point register that is required to be
10448 saved. 32 if none. */
9878760c
RK
10449
10450int
863d938c 10451first_reg_to_save (void)
9878760c
RK
10452{
10453 int first_reg;
10454
10455 /* Find lowest numbered live register. */
10456 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10457 if (regs_ever_live[first_reg]
10458 && (! call_used_regs[first_reg]
1db02437 10459 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10460 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10461 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10462 break;
10463
ee890fe2 10464#if TARGET_MACHO
93638d7a
AM
10465 if (flag_pic
10466 && current_function_uses_pic_offset_table
10467 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10468 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10469#endif
10470
9878760c
RK
10471 return first_reg;
10472}
10473
10474/* Similar, for FP regs. */
10475
10476int
863d938c 10477first_fp_reg_to_save (void)
9878760c
RK
10478{
10479 int first_reg;
10480
10481 /* Find lowest numbered live register. */
10482 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10483 if (regs_ever_live[first_reg])
10484 break;
10485
10486 return first_reg;
10487}
00b960c7
AH
10488
10489/* Similar, for AltiVec regs. */
10490
10491static int
863d938c 10492first_altivec_reg_to_save (void)
00b960c7
AH
10493{
10494 int i;
10495
10496 /* Stack frame remains as is unless we are in AltiVec ABI. */
10497 if (! TARGET_ALTIVEC_ABI)
10498 return LAST_ALTIVEC_REGNO + 1;
10499
10500 /* Find lowest numbered live register. */
10501 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10502 if (regs_ever_live[i])
10503 break;
10504
10505 return i;
10506}
10507
10508/* Return a 32-bit mask of the AltiVec registers we need to set in
10509 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10510 the 32-bit word is 0. */
10511
10512static unsigned int
863d938c 10513compute_vrsave_mask (void)
00b960c7
AH
10514{
10515 unsigned int i, mask = 0;
10516
10517 /* First, find out if we use _any_ altivec registers. */
10518 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10519 if (regs_ever_live[i])
10520 mask |= ALTIVEC_REG_BIT (i);
10521
10522 if (mask == 0)
10523 return mask;
10524
00b960c7
AH
10525 /* Next, remove the argument registers from the set. These must
10526 be in the VRSAVE mask set by the caller, so we don't need to add
10527 them in again. More importantly, the mask we compute here is
10528 used to generate CLOBBERs in the set_vrsave insn, and we do not
10529 wish the argument registers to die. */
a6cf80f2 10530 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10531 mask &= ~ALTIVEC_REG_BIT (i);
10532
10533 /* Similarly, remove the return value from the set. */
10534 {
10535 bool yes = false;
10536 diddle_return_value (is_altivec_return_reg, &yes);
10537 if (yes)
10538 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10539 }
10540
10541 return mask;
10542}
10543
10544static void
a2369ed3 10545is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10546{
10547 bool *yes = (bool *) xyes;
10548 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10549 *yes = true;
10550}
10551
4697a36c
MM
10552\f
10553/* Calculate the stack information for the current function. This is
10554 complicated by having two separate calling sequences, the AIX calling
10555 sequence and the V.4 calling sequence.
10556
592696dd 10557 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10558 32-bit 64-bit
4697a36c 10559 SP----> +---------------------------------------+
a260abc9 10560 | back chain to caller | 0 0
4697a36c 10561 +---------------------------------------+
a260abc9 10562 | saved CR | 4 8 (8-11)
4697a36c 10563 +---------------------------------------+
a260abc9 10564 | saved LR | 8 16
4697a36c 10565 +---------------------------------------+
a260abc9 10566 | reserved for compilers | 12 24
4697a36c 10567 +---------------------------------------+
a260abc9 10568 | reserved for binders | 16 32
4697a36c 10569 +---------------------------------------+
a260abc9 10570 | saved TOC pointer | 20 40
4697a36c 10571 +---------------------------------------+
a260abc9 10572 | Parameter save area (P) | 24 48
4697a36c 10573 +---------------------------------------+
a260abc9 10574 | Alloca space (A) | 24+P etc.
802a0058 10575 +---------------------------------------+
a7df97e6 10576 | Local variable space (L) | 24+P+A
4697a36c 10577 +---------------------------------------+
a7df97e6 10578 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10579 +---------------------------------------+
00b960c7
AH
10580 | Save area for AltiVec registers (W) | 24+P+A+L+X
10581 +---------------------------------------+
10582 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10583 +---------------------------------------+
10584 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10585 +---------------------------------------+
00b960c7
AH
10586 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10587 +---------------------------------------+
10588 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10589 +---------------------------------------+
10590 old SP->| back chain to caller's caller |
10591 +---------------------------------------+
10592
5376a30c
KR
10593 The required alignment for AIX configurations is two words (i.e., 8
10594 or 16 bytes).
10595
10596
4697a36c
MM
10597 V.4 stack frames look like:
10598
10599 SP----> +---------------------------------------+
10600 | back chain to caller | 0
10601 +---------------------------------------+
5eb387b8 10602 | caller's saved LR | 4
4697a36c
MM
10603 +---------------------------------------+
10604 | Parameter save area (P) | 8
10605 +---------------------------------------+
a7df97e6
MM
10606 | Alloca space (A) | 8+P
10607 +---------------------------------------+
10608 | Varargs save area (V) | 8+P+A
10609 +---------------------------------------+
10610 | Local variable space (L) | 8+P+A+V
10611 +---------------------------------------+
10612 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10613 +---------------------------------------+
00b960c7
AH
10614 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10615 +---------------------------------------+
10616 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10617 +---------------------------------------+
10618 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10619 +---------------------------------------+
a3170dc6
AH
10620 | SPE: area for 64-bit GP registers |
10621 +---------------------------------------+
10622 | SPE alignment padding |
10623 +---------------------------------------+
00b960c7 10624 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10625 +---------------------------------------+
00b960c7 10626 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10627 +---------------------------------------+
00b960c7 10628 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10629 +---------------------------------------+
10630 old SP->| back chain to caller's caller |
10631 +---------------------------------------+
b6c9286a 10632
5376a30c
KR
10633 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10634 given. (But note below and in sysv4.h that we require only 8 and
10635 may round up the size of our stack frame anyways. The historical
10636 reason is early versions of powerpc-linux which didn't properly
10637 align the stack at program startup. A happy side-effect is that
10638 -mno-eabi libraries can be used with -meabi programs.)
10639
50d440bc 10640 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10641 the stack alignment requirements may differ. If -mno-eabi is not
10642 given, the required stack alignment is 8 bytes; if -mno-eabi is
10643 given, the required alignment is 16 bytes. (But see V.4 comment
10644 above.) */
4697a36c 10645
61b2fbe7
MM
10646#ifndef ABI_STACK_BOUNDARY
10647#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10648#endif
10649
d1d0c603 10650static rs6000_stack_t *
863d938c 10651rs6000_stack_info (void)
4697a36c
MM
10652{
10653 static rs6000_stack_t info, zero_info;
10654 rs6000_stack_t *info_ptr = &info;
9ebbca7d 10655 int reg_size = TARGET_POWERPC64 ? 8 : 4;
83720594 10656 int ehrd_size;
d1d0c603 10657 HOST_WIDE_INT total_raw_size;
4697a36c 10658
a4f6c312 10659 /* Zero all fields portably. */
4697a36c
MM
10660 info = zero_info;
10661
c19de7aa
AH
10662 if (TARGET_SPE)
10663 {
10664 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10665 if (cfun->machine->insn_chain_scanned_p == 0)
10666 {
10667 cfun->machine->insn_chain_scanned_p = 1;
10668 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10669 }
c19de7aa
AH
10670 }
10671
a4f6c312 10672 /* Select which calling sequence. */
178274da 10673 info_ptr->abi = DEFAULT_ABI;
9878760c 10674
a4f6c312 10675 /* Calculate which registers need to be saved & save area size. */
4697a36c 10676 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10677 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10678 even if it currently looks like we won't. */
2bfcf297 10679 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10680 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10681 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10682 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10683 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10684 else
10685 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10686
a3170dc6
AH
10687 /* For the SPE, we have an additional upper 32-bits on each GPR.
10688 Ideally we should save the entire 64-bits only when the upper
10689 half is used in SIMD instructions. Since we only record
10690 registers live (not the size they are used in), this proves
10691 difficult because we'd have to traverse the instruction chain at
10692 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10693 so we opt to save the GPRs in 64-bits always if but one register
10694 gets used in 64-bits. Otherwise, all the registers in the frame
10695 get saved in 32-bits.
a3170dc6 10696
c19de7aa 10697 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10698 traditional GP save area will be empty. */
c19de7aa 10699 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10700 info_ptr->gp_size = 0;
10701
4697a36c
MM
10702 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10703 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10704
00b960c7
AH
10705 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10706 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10707 - info_ptr->first_altivec_reg_save);
10708
592696dd 10709 /* Does this function call anything? */
71f123ca
FS
10710 info_ptr->calls_p = (! current_function_is_leaf
10711 || cfun->machine->ra_needs_full_frame);
b6c9286a 10712
a4f6c312 10713 /* Determine if we need to save the link register. */
71f123ca 10714 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10715 || (DEFAULT_ABI == ABI_AIX
10716 && current_function_profile
10717 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10718#ifdef TARGET_RELOCATABLE
10719 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10720#endif
10721 || (info_ptr->first_fp_reg_save != 64
10722 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10723 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10724 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10725 || (DEFAULT_ABI == ABI_DARWIN
10726 && flag_pic
10727 && current_function_uses_pic_offset_table)
4697a36c
MM
10728 || info_ptr->calls_p)
10729 {
10730 info_ptr->lr_save_p = 1;
9ebbca7d 10731 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10732 }
10733
9ebbca7d
GK
10734 /* Determine if we need to save the condition code registers. */
10735 if (regs_ever_live[CR2_REGNO]
10736 || regs_ever_live[CR3_REGNO]
10737 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10738 {
10739 info_ptr->cr_save_p = 1;
178274da 10740 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10741 info_ptr->cr_size = reg_size;
10742 }
10743
83720594
RH
10744 /* If the current function calls __builtin_eh_return, then we need
10745 to allocate stack space for registers that will hold data for
10746 the exception handler. */
10747 if (current_function_calls_eh_return)
10748 {
10749 unsigned int i;
10750 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10751 continue;
a3170dc6
AH
10752
10753 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10754 ehrd_size = i * (TARGET_SPE_ABI
10755 && info_ptr->spe_64bit_regs_used != 0
10756 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10757 }
10758 else
10759 ehrd_size = 0;
10760
592696dd 10761 /* Determine various sizes. */
4697a36c
MM
10762 info_ptr->reg_size = reg_size;
10763 info_ptr->fixed_size = RS6000_SAVE_AREA;
10764 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10765 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
10766 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
10767 8);
00b960c7 10768
c19de7aa 10769 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10770 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10771 else
10772 info_ptr->spe_gp_size = 0;
10773
4d774ff8
HP
10774 if (TARGET_ALTIVEC_ABI)
10775 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 10776 else
4d774ff8
HP
10777 info_ptr->vrsave_mask = 0;
10778
10779 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
10780 info_ptr->vrsave_size = 4;
10781 else
10782 info_ptr->vrsave_size = 0;
b6c9286a 10783
592696dd 10784 /* Calculate the offsets. */
178274da 10785 switch (DEFAULT_ABI)
4697a36c 10786 {
b6c9286a 10787 case ABI_NONE:
24d304eb 10788 default:
b6c9286a
MM
10789 abort ();
10790
10791 case ABI_AIX:
ee890fe2 10792 case ABI_DARWIN:
b6c9286a
MM
10793 info_ptr->fp_save_offset = - info_ptr->fp_size;
10794 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10795
10796 if (TARGET_ALTIVEC_ABI)
10797 {
10798 info_ptr->vrsave_save_offset
10799 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10800
10801 /* Align stack so vector save area is on a quadword boundary. */
10802 if (info_ptr->altivec_size != 0)
10803 info_ptr->altivec_padding_size
10804 = 16 - (-info_ptr->vrsave_save_offset % 16);
10805 else
10806 info_ptr->altivec_padding_size = 0;
10807
10808 info_ptr->altivec_save_offset
10809 = info_ptr->vrsave_save_offset
10810 - info_ptr->altivec_padding_size
10811 - info_ptr->altivec_size;
10812
10813 /* Adjust for AltiVec case. */
10814 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10815 }
10816 else
10817 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10818 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10819 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10820 break;
10821
10822 case ABI_V4:
b6c9286a
MM
10823 info_ptr->fp_save_offset = - info_ptr->fp_size;
10824 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10825 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10826
c19de7aa 10827 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10828 {
10829 /* Align stack so SPE GPR save area is aligned on a
10830 double-word boundary. */
10831 if (info_ptr->spe_gp_size != 0)
10832 info_ptr->spe_padding_size
10833 = 8 - (-info_ptr->cr_save_offset % 8);
10834 else
10835 info_ptr->spe_padding_size = 0;
10836
10837 info_ptr->spe_gp_save_offset
10838 = info_ptr->cr_save_offset
10839 - info_ptr->spe_padding_size
10840 - info_ptr->spe_gp_size;
10841
10842 /* Adjust for SPE case. */
10843 info_ptr->toc_save_offset
10844 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10845 }
10846 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10847 {
10848 info_ptr->vrsave_save_offset
10849 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10850
10851 /* Align stack so vector save area is on a quadword boundary. */
10852 if (info_ptr->altivec_size != 0)
10853 info_ptr->altivec_padding_size
10854 = 16 - (-info_ptr->vrsave_save_offset % 16);
10855 else
10856 info_ptr->altivec_padding_size = 0;
10857
10858 info_ptr->altivec_save_offset
10859 = info_ptr->vrsave_save_offset
10860 - info_ptr->altivec_padding_size
10861 - info_ptr->altivec_size;
10862
10863 /* Adjust for AltiVec case. */
10864 info_ptr->toc_save_offset
10865 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10866 }
10867 else
10868 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10869 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10870 info_ptr->lr_save_offset = reg_size;
10871 break;
4697a36c
MM
10872 }
10873
00b960c7
AH
10874 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10875 + info_ptr->gp_size
10876 + info_ptr->altivec_size
10877 + info_ptr->altivec_padding_size
a3170dc6
AH
10878 + info_ptr->spe_gp_size
10879 + info_ptr->spe_padding_size
00b960c7
AH
10880 + ehrd_size
10881 + info_ptr->cr_size
10882 + info_ptr->lr_size
10883 + info_ptr->vrsave_size
10884 + info_ptr->toc_size,
10885 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10886 ? 16 : 8);
10887
ff381587
MM
10888 total_raw_size = (info_ptr->vars_size
10889 + info_ptr->parm_size
ff381587
MM
10890 + info_ptr->save_size
10891 + info_ptr->varargs_size
10892 + info_ptr->fixed_size);
10893
a4f6c312
SS
10894 info_ptr->total_size =
10895 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10896
10897 /* Determine if we need to allocate any stack frame:
10898
a4f6c312
SS
10899 For AIX we need to push the stack if a frame pointer is needed
10900 (because the stack might be dynamically adjusted), if we are
10901 debugging, if we make calls, or if the sum of fp_save, gp_save,
10902 and local variables are more than the space needed to save all
10903 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10904 + 18*8 = 288 (GPR13 reserved).
ff381587 10905
a4f6c312
SS
10906 For V.4 we don't have the stack cushion that AIX uses, but assume
10907 that the debugger can handle stackless frames. */
ff381587
MM
10908
10909 if (info_ptr->calls_p)
10910 info_ptr->push_p = 1;
10911
178274da 10912 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10913 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10914
178274da
AM
10915 else if (frame_pointer_needed)
10916 info_ptr->push_p = 1;
10917
10918 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10919 info_ptr->push_p = 1;
10920
ff381587 10921 else
178274da
AM
10922 info_ptr->push_p
10923 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10924
a4f6c312 10925 /* Zero offsets if we're not saving those registers. */
8dda1a21 10926 if (info_ptr->fp_size == 0)
4697a36c
MM
10927 info_ptr->fp_save_offset = 0;
10928
8dda1a21 10929 if (info_ptr->gp_size == 0)
4697a36c
MM
10930 info_ptr->gp_save_offset = 0;
10931
00b960c7
AH
10932 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10933 info_ptr->altivec_save_offset = 0;
10934
10935 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10936 info_ptr->vrsave_save_offset = 0;
10937
c19de7aa
AH
10938 if (! TARGET_SPE_ABI
10939 || info_ptr->spe_64bit_regs_used == 0
10940 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10941 info_ptr->spe_gp_save_offset = 0;
10942
c81fc13e 10943 if (! info_ptr->lr_save_p)
4697a36c
MM
10944 info_ptr->lr_save_offset = 0;
10945
c81fc13e 10946 if (! info_ptr->cr_save_p)
4697a36c
MM
10947 info_ptr->cr_save_offset = 0;
10948
c81fc13e 10949 if (! info_ptr->toc_save_p)
b6c9286a
MM
10950 info_ptr->toc_save_offset = 0;
10951
4697a36c
MM
10952 return info_ptr;
10953}
10954
c19de7aa
AH
10955/* Return true if the current function uses any GPRs in 64-bit SIMD
10956 mode. */
10957
10958static bool
863d938c 10959spe_func_has_64bit_regs_p (void)
c19de7aa
AH
10960{
10961 rtx insns, insn;
10962
10963 /* Functions that save and restore all the call-saved registers will
10964 need to save/restore the registers in 64-bits. */
10965 if (current_function_calls_eh_return
10966 || current_function_calls_setjmp
10967 || current_function_has_nonlocal_goto)
10968 return true;
10969
10970 insns = get_insns ();
10971
10972 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
10973 {
10974 if (INSN_P (insn))
10975 {
10976 rtx i;
10977
10978 i = PATTERN (insn);
10979 if (GET_CODE (i) == SET
10980 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
10981 return true;
10982 }
10983 }
10984
10985 return false;
10986}
10987
d1d0c603 10988static void
a2369ed3 10989debug_stack_info (rs6000_stack_t *info)
9878760c 10990{
d330fd93 10991 const char *abi_string;
24d304eb 10992
c81fc13e 10993 if (! info)
4697a36c
MM
10994 info = rs6000_stack_info ();
10995
10996 fprintf (stderr, "\nStack information for function %s:\n",
10997 ((current_function_decl && DECL_NAME (current_function_decl))
10998 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
10999 : "<unknown>"));
11000
24d304eb
RK
11001 switch (info->abi)
11002 {
b6c9286a
MM
11003 default: abi_string = "Unknown"; break;
11004 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 11005 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 11006 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 11007 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
11008 }
11009
11010 fprintf (stderr, "\tABI = %5s\n", abi_string);
11011
00b960c7
AH
11012 if (TARGET_ALTIVEC_ABI)
11013 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
11014
a3170dc6
AH
11015 if (TARGET_SPE_ABI)
11016 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
11017
4697a36c
MM
11018 if (info->first_gp_reg_save != 32)
11019 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
11020
11021 if (info->first_fp_reg_save != 64)
11022 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 11023
00b960c7
AH
11024 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
11025 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
11026 info->first_altivec_reg_save);
11027
4697a36c
MM
11028 if (info->lr_save_p)
11029 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 11030
4697a36c
MM
11031 if (info->cr_save_p)
11032 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
11033
b6c9286a
MM
11034 if (info->toc_save_p)
11035 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
11036
00b960c7
AH
11037 if (info->vrsave_mask)
11038 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
11039
4697a36c
MM
11040 if (info->push_p)
11041 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
11042
11043 if (info->calls_p)
11044 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
11045
4697a36c
MM
11046 if (info->gp_save_offset)
11047 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
11048
11049 if (info->fp_save_offset)
11050 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
11051
00b960c7
AH
11052 if (info->altivec_save_offset)
11053 fprintf (stderr, "\taltivec_save_offset = %5d\n",
11054 info->altivec_save_offset);
11055
a3170dc6
AH
11056 if (info->spe_gp_save_offset)
11057 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
11058 info->spe_gp_save_offset);
11059
00b960c7
AH
11060 if (info->vrsave_save_offset)
11061 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
11062 info->vrsave_save_offset);
11063
4697a36c
MM
11064 if (info->lr_save_offset)
11065 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
11066
11067 if (info->cr_save_offset)
11068 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
11069
b6c9286a
MM
11070 if (info->toc_save_offset)
11071 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
11072
4697a36c
MM
11073 if (info->varargs_save_offset)
11074 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
11075
11076 if (info->total_size)
d1d0c603
JJ
11077 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11078 info->total_size);
4697a36c
MM
11079
11080 if (info->varargs_size)
11081 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
11082
11083 if (info->vars_size)
d1d0c603
JJ
11084 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11085 info->vars_size);
4697a36c
MM
11086
11087 if (info->parm_size)
11088 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
11089
11090 if (info->fixed_size)
11091 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
11092
11093 if (info->gp_size)
11094 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
11095
a3170dc6
AH
11096 if (info->spe_gp_size)
11097 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
11098
4697a36c
MM
11099 if (info->fp_size)
11100 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
11101
00b960c7
AH
11102 if (info->altivec_size)
11103 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
11104
11105 if (info->vrsave_size)
11106 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
11107
11108 if (info->altivec_padding_size)
11109 fprintf (stderr, "\taltivec_padding_size= %5d\n",
11110 info->altivec_padding_size);
11111
a3170dc6
AH
11112 if (info->spe_padding_size)
11113 fprintf (stderr, "\tspe_padding_size = %5d\n",
11114 info->spe_padding_size);
11115
a4f6c312 11116 if (info->lr_size)
ed947a96 11117 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 11118
4697a36c
MM
11119 if (info->cr_size)
11120 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
11121
a4f6c312 11122 if (info->toc_size)
b6c9286a
MM
11123 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
11124
4697a36c
MM
11125 if (info->save_size)
11126 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
11127
11128 if (info->reg_size != 4)
11129 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
11130
11131 fprintf (stderr, "\n");
9878760c 11132}
71f123ca
FS
11133
11134rtx
a2369ed3 11135rs6000_return_addr (int count, rtx frame)
71f123ca 11136{
a4f6c312
SS
11137 /* Currently we don't optimize very well between prolog and body
11138 code and for PIC code the code can be actually quite bad, so
11139 don't try to be too clever here. */
f1384257 11140 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
11141 {
11142 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
11143
11144 return
11145 gen_rtx_MEM
11146 (Pmode,
11147 memory_address
11148 (Pmode,
11149 plus_constant (copy_to_reg
11150 (gen_rtx_MEM (Pmode,
11151 memory_address (Pmode, frame))),
11152 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
11153 }
11154
8c29550d 11155 cfun->machine->ra_need_lr = 1;
9e2f7ec7 11156 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
11157}
11158
5e1bf043
DJ
11159/* Say whether a function is a candidate for sibcall handling or not.
11160 We do not allow indirect calls to be optimized into sibling calls.
11161 Also, we can't do it if there are any vector parameters; there's
11162 nowhere to put the VRsave code so it works; note that functions with
11163 vector parameters are required to have a prototype, so the argument
11164 type info must be available here. (The tail recursion case can work
11165 with vector parameters, but there's no way to distinguish here.) */
4977bab6 11166static bool
a2369ed3 11167rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
11168{
11169 tree type;
4977bab6 11170 if (decl)
5e1bf043
DJ
11171 {
11172 if (TARGET_ALTIVEC_VRSAVE)
11173 {
4977bab6 11174 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
11175 type; type = TREE_CHAIN (type))
11176 {
c15b529f 11177 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 11178 return false;
5e1bf043
DJ
11179 }
11180 }
11181 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 11182 || (*targetm.binds_local_p) (decl))
2bcc50d0 11183 {
4977bab6 11184 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
11185
11186 if (!lookup_attribute ("longcall", attr_list)
11187 || lookup_attribute ("shortcall", attr_list))
4977bab6 11188 return true;
2bcc50d0 11189 }
5e1bf043 11190 }
4977bab6 11191 return false;
5e1bf043
DJ
11192}
11193
71f123ca 11194static int
863d938c 11195rs6000_ra_ever_killed (void)
71f123ca
FS
11196{
11197 rtx top;
5e1bf043
DJ
11198 rtx reg;
11199 rtx insn;
71f123ca 11200
dd292d0a 11201 if (current_function_is_thunk)
71f123ca 11202 return 0;
eb0424da 11203
36f7e964
AH
11204 /* regs_ever_live has LR marked as used if any sibcalls are present,
11205 but this should not force saving and restoring in the
11206 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11207 clobbers LR, so that is inappropriate. */
36f7e964 11208
5e1bf043
DJ
11209 /* Also, the prologue can generate a store into LR that
11210 doesn't really count, like this:
36f7e964 11211
5e1bf043
DJ
11212 move LR->R0
11213 bcl to set PIC register
11214 move LR->R31
11215 move R0->LR
36f7e964
AH
11216
11217 When we're called from the epilogue, we need to avoid counting
11218 this as a store. */
5e1bf043 11219
71f123ca
FS
11220 push_topmost_sequence ();
11221 top = get_insns ();
11222 pop_topmost_sequence ();
5e1bf043 11223 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11224
5e1bf043
DJ
11225 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11226 {
11227 if (INSN_P (insn))
11228 {
11229 if (FIND_REG_INC_NOTE (insn, reg))
11230 return 1;
11231 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11232 && !SIBLING_CALL_P (insn))
5e1bf043 11233 return 1;
36f7e964
AH
11234 else if (set_of (reg, insn) != NULL_RTX
11235 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11236 return 1;
11237 }
11238 }
11239 return 0;
71f123ca 11240}
4697a36c 11241\f
8cd8f856
GK
11242/* Add a REG_MAYBE_DEAD note to the insn. */
11243static void
a2369ed3 11244rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11245{
11246 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11247 const0_rtx,
11248 REG_NOTES (insn));
11249}
11250
9ebbca7d 11251/* Emit instructions needed to load the TOC register.
c7ca610e 11252 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11253 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11254
11255void
a2369ed3 11256rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11257{
027fbf43 11258 rtx dest, insn;
1db02437 11259 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11260
20b71b17
AM
11261 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11262 {
11263 rtx temp = (fromprolog
11264 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11265 : gen_reg_rtx (Pmode));
027fbf43
JJ
11266 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11267 if (fromprolog)
11268 rs6000_maybe_dead (insn);
11269 insn = emit_move_insn (dest, temp);
11270 if (fromprolog)
11271 rs6000_maybe_dead (insn);
20b71b17
AM
11272 }
11273 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11274 {
11275 char buf[30];
11276 rtx tempLR = (fromprolog
11277 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11278 : gen_reg_rtx (Pmode));
11279 rtx temp0 = (fromprolog
11280 ? gen_rtx_REG (Pmode, 0)
11281 : gen_reg_rtx (Pmode));
11282 rtx symF;
11283
11284 /* possibly create the toc section */
11285 if (! toc_initialized)
38c1f2d7 11286 {
20b71b17
AM
11287 toc_section ();
11288 function_section (current_function_decl);
38c1f2d7 11289 }
9ebbca7d 11290
20b71b17
AM
11291 if (fromprolog)
11292 {
11293 rtx symL;
38c1f2d7 11294
20b71b17
AM
11295 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11296 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11297
20b71b17
AM
11298 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11299 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11300
11301 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11302 symF)));
11303 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11304 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11305 symL,
11306 symF)));
9ebbca7d
GK
11307 }
11308 else
20b71b17
AM
11309 {
11310 rtx tocsym;
11311 static int reload_toc_labelno = 0;
11312
11313 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11314
11315 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11316 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11317
027fbf43
JJ
11318 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11319 emit_move_insn (dest, tempLR);
11320 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11321 }
027fbf43
JJ
11322 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11323 if (fromprolog)
11324 rs6000_maybe_dead (insn);
9ebbca7d 11325 }
20b71b17
AM
11326 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11327 {
11328 /* This is for AIX code running in non-PIC ELF32. */
11329 char buf[30];
11330 rtx realsym;
11331 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11332 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11333
027fbf43
JJ
11334 insn = emit_insn (gen_elf_high (dest, realsym));
11335 if (fromprolog)
11336 rs6000_maybe_dead (insn);
11337 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11338 if (fromprolog)
11339 rs6000_maybe_dead (insn);
20b71b17
AM
11340 }
11341 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11342 {
11343 if (TARGET_32BIT)
027fbf43 11344 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11345 else
027fbf43
JJ
11346 insn = emit_insn (gen_load_toc_aix_di (dest));
11347 if (fromprolog)
11348 rs6000_maybe_dead (insn);
9ebbca7d 11349 }
20b71b17
AM
11350 else
11351 abort ();
9ebbca7d
GK
11352}
11353
d1d0c603
JJ
11354/* Emit instructions to restore the link register after determining where
11355 its value has been stored. */
11356
11357void
11358rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11359{
11360 rs6000_stack_t *info = rs6000_stack_info ();
11361 rtx operands[2];
11362
11363 operands[0] = source;
11364 operands[1] = scratch;
11365
11366 if (info->lr_save_p)
11367 {
11368 rtx frame_rtx = stack_pointer_rtx;
11369 HOST_WIDE_INT sp_offset = 0;
11370 rtx tmp;
11371
11372 if (frame_pointer_needed
11373 || current_function_calls_alloca
11374 || info->total_size > 32767)
11375 {
11376 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11377 frame_rtx = operands[1];
11378 }
11379 else if (info->push_p)
11380 sp_offset = info->total_size;
11381
11382 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11383 tmp = gen_rtx_MEM (Pmode, tmp);
11384 emit_move_insn (tmp, operands[0]);
11385 }
11386 else
11387 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11388}
11389
f103e34d
GK
11390static GTY(()) int set = -1;
11391
9ebbca7d 11392int
863d938c 11393get_TOC_alias_set (void)
9ebbca7d 11394{
f103e34d
GK
11395 if (set == -1)
11396 set = new_alias_set ();
11397 return set;
9ebbca7d
GK
11398}
11399
c1207243 11400/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11401 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11402 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11403#if TARGET_ELF
3c9eb5f4 11404static int
38f391a5 11405uses_TOC (void)
9ebbca7d 11406{
c4501e62 11407 rtx insn;
38c1f2d7 11408
c4501e62
JJ
11409 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11410 if (INSN_P (insn))
11411 {
11412 rtx pat = PATTERN (insn);
11413 int i;
9ebbca7d 11414
c4501e62
JJ
11415 if (GET_CODE (pat) == PARALLEL)
11416 for (i = 0; i < XVECLEN (pat, 0); i++)
11417 {
11418 rtx sub = XVECEXP (pat, 0, i);
11419 if (GET_CODE (sub) == USE)
11420 {
11421 sub = XEXP (sub, 0);
11422 if (GET_CODE (sub) == UNSPEC
11423 && XINT (sub, 1) == UNSPEC_TOC)
11424 return 1;
11425 }
11426 }
11427 }
11428 return 0;
9ebbca7d 11429}
c954844a 11430#endif
38c1f2d7 11431
9ebbca7d 11432rtx
a2369ed3 11433create_TOC_reference (rtx symbol)
9ebbca7d 11434{
a8a05998
ZW
11435 return gen_rtx_PLUS (Pmode,
11436 gen_rtx_REG (Pmode, TOC_REGISTER),
11437 gen_rtx_CONST (Pmode,
11438 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11439 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11440}
38c1f2d7 11441
fc4767bb
JJ
11442/* If _Unwind_* has been called from within the same module,
11443 toc register is not guaranteed to be saved to 40(1) on function
11444 entry. Save it there in that case. */
c7ca610e 11445
9ebbca7d 11446void
863d938c 11447rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11448{
11449 rtx mem;
11450 rtx stack_top = gen_reg_rtx (Pmode);
11451 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11452 rtx opcode = gen_reg_rtx (SImode);
11453 rtx tocompare = gen_reg_rtx (SImode);
11454 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11455
11456 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11457 emit_move_insn (stack_top, mem);
11458
fc4767bb
JJ
11459 mem = gen_rtx_MEM (Pmode,
11460 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11461 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11462 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11463 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11464 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11465 : 0xE8410028, SImode));
9ebbca7d 11466
fc4767bb 11467 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11468 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11469 no_toc_save_needed);
9ebbca7d 11470
fc4767bb
JJ
11471 mem = gen_rtx_MEM (Pmode,
11472 gen_rtx_PLUS (Pmode, stack_top,
11473 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11474 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11475 emit_label (no_toc_save_needed);
9ebbca7d 11476}
38c1f2d7 11477\f
ba4828e0
RK
11478/* This ties together stack memory (MEM with an alias set of
11479 rs6000_sr_alias_set) and the change to the stack pointer. */
11480
9ebbca7d 11481static void
863d938c 11482rs6000_emit_stack_tie (void)
9ebbca7d 11483{
ba4828e0
RK
11484 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11485
11486 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11487 emit_insn (gen_stack_tie (mem));
11488}
38c1f2d7 11489
9ebbca7d
GK
11490/* Emit the correct code for allocating stack space, as insns.
11491 If COPY_R12, make sure a copy of the old frame is left in r12.
11492 The generated code may use hard register 0 as a temporary. */
11493
11494static void
a2369ed3 11495rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11496{
9ebbca7d
GK
11497 rtx insn;
11498 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11499 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11500 rtx todec = GEN_INT (-size);
a157febd
GK
11501
11502 if (current_function_limit_stack)
11503 {
11504 if (REG_P (stack_limit_rtx)
11505 && REGNO (stack_limit_rtx) > 1
11506 && REGNO (stack_limit_rtx) <= 31)
11507 {
5b71a4e7 11508 emit_insn (TARGET_32BIT
9ebbca7d
GK
11509 ? gen_addsi3 (tmp_reg,
11510 stack_limit_rtx,
11511 GEN_INT (size))
11512 : gen_adddi3 (tmp_reg,
11513 stack_limit_rtx,
11514 GEN_INT (size)));
5b71a4e7 11515
9ebbca7d
GK
11516 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11517 const0_rtx));
a157febd
GK
11518 }
11519 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11520 && TARGET_32BIT
f607bc57 11521 && DEFAULT_ABI == ABI_V4)
a157febd 11522 {
9ebbca7d
GK
11523 rtx toload = gen_rtx_CONST (VOIDmode,
11524 gen_rtx_PLUS (Pmode,
11525 stack_limit_rtx,
11526 GEN_INT (size)));
5b71a4e7 11527
9ebbca7d
GK
11528 emit_insn (gen_elf_high (tmp_reg, toload));
11529 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11530 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11531 const0_rtx));
a157febd
GK
11532 }
11533 else
11534 warning ("stack limit expression is not supported");
11535 }
11536
9ebbca7d
GK
11537 if (copy_r12 || ! TARGET_UPDATE)
11538 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11539
38c1f2d7
MM
11540 if (TARGET_UPDATE)
11541 {
9ebbca7d 11542 if (size > 32767)
38c1f2d7 11543 {
9ebbca7d
GK
11544 /* Need a note here so that try_split doesn't get confused. */
11545 if (get_last_insn() == NULL_RTX)
2e040219 11546 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11547 insn = emit_move_insn (tmp_reg, todec);
11548 try_split (PATTERN (insn), insn, 0);
11549 todec = tmp_reg;
38c1f2d7 11550 }
5b71a4e7
DE
11551
11552 insn = emit_insn (TARGET_32BIT
11553 ? gen_movsi_update (stack_reg, stack_reg,
11554 todec, stack_reg)
11555 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11556 todec, stack_reg));
38c1f2d7
MM
11557 }
11558 else
11559 {
5b71a4e7
DE
11560 insn = emit_insn (TARGET_32BIT
11561 ? gen_addsi3 (stack_reg, stack_reg, todec)
11562 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11563 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11564 gen_rtx_REG (Pmode, 12));
11565 }
5b71a4e7 11566
9ebbca7d
GK
11567 RTX_FRAME_RELATED_P (insn) = 1;
11568 REG_NOTES (insn) =
11569 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11570 gen_rtx_SET (VOIDmode, stack_reg,
11571 gen_rtx_PLUS (Pmode, stack_reg,
11572 GEN_INT (-size))),
11573 REG_NOTES (insn));
11574}
11575
a4f6c312
SS
11576/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11577 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11578 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11579 deduce these equivalences by itself so it wasn't necessary to hold
11580 its hand so much. */
9ebbca7d
GK
11581
11582static void
a2369ed3
DJ
11583rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11584 rtx reg2, rtx rreg)
9ebbca7d
GK
11585{
11586 rtx real, temp;
11587
e56c4463
JL
11588 /* copy_rtx will not make unique copies of registers, so we need to
11589 ensure we don't have unwanted sharing here. */
11590 if (reg == reg2)
11591 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11592
11593 if (reg == rreg)
11594 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11595
9ebbca7d
GK
11596 real = copy_rtx (PATTERN (insn));
11597
89e7058f
AH
11598 if (reg2 != NULL_RTX)
11599 real = replace_rtx (real, reg2, rreg);
11600
9ebbca7d
GK
11601 real = replace_rtx (real, reg,
11602 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11603 STACK_POINTER_REGNUM),
11604 GEN_INT (val)));
11605
11606 /* We expect that 'real' is either a SET or a PARALLEL containing
11607 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11608 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11609
11610 if (GET_CODE (real) == SET)
11611 {
11612 rtx set = real;
11613
11614 temp = simplify_rtx (SET_SRC (set));
11615 if (temp)
11616 SET_SRC (set) = temp;
11617 temp = simplify_rtx (SET_DEST (set));
11618 if (temp)
11619 SET_DEST (set) = temp;
11620 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11621 {
9ebbca7d
GK
11622 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11623 if (temp)
11624 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11625 }
38c1f2d7 11626 }
9ebbca7d
GK
11627 else if (GET_CODE (real) == PARALLEL)
11628 {
11629 int i;
11630 for (i = 0; i < XVECLEN (real, 0); i++)
11631 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11632 {
11633 rtx set = XVECEXP (real, 0, i);
11634
11635 temp = simplify_rtx (SET_SRC (set));
11636 if (temp)
11637 SET_SRC (set) = temp;
11638 temp = simplify_rtx (SET_DEST (set));
11639 if (temp)
11640 SET_DEST (set) = temp;
11641 if (GET_CODE (SET_DEST (set)) == MEM)
11642 {
11643 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11644 if (temp)
11645 XEXP (SET_DEST (set), 0) = temp;
11646 }
11647 RTX_FRAME_RELATED_P (set) = 1;
11648 }
11649 }
11650 else
a4f6c312 11651 abort ();
c19de7aa
AH
11652
11653 if (TARGET_SPE)
11654 real = spe_synthesize_frame_save (real);
11655
9ebbca7d
GK
11656 RTX_FRAME_RELATED_P (insn) = 1;
11657 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11658 real,
11659 REG_NOTES (insn));
38c1f2d7
MM
11660}
11661
c19de7aa
AH
11662/* Given an SPE frame note, return a PARALLEL of SETs with the
11663 original note, plus a synthetic register save. */
11664
11665static rtx
a2369ed3 11666spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11667{
11668 rtx synth, offset, reg, real2;
11669
11670 if (GET_CODE (real) != SET
11671 || GET_MODE (SET_SRC (real)) != V2SImode)
11672 return real;
11673
11674 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11675 frame related note. The parallel contains a set of the register
41f3a930 11676 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11677 This is so we can differentiate between 64-bit and 32-bit saves.
11678 Words cannot describe this nastiness. */
11679
11680 if (GET_CODE (SET_DEST (real)) != MEM
11681 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11682 || GET_CODE (SET_SRC (real)) != REG)
11683 abort ();
11684
11685 /* Transform:
11686 (set (mem (plus (reg x) (const y)))
11687 (reg z))
11688 into:
11689 (set (mem (plus (reg x) (const y+4)))
41f3a930 11690 (reg z+1200))
c19de7aa
AH
11691 */
11692
11693 real2 = copy_rtx (real);
11694 PUT_MODE (SET_DEST (real2), SImode);
11695 reg = SET_SRC (real2);
11696 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11697 synth = copy_rtx (real2);
11698
11699 if (BYTES_BIG_ENDIAN)
11700 {
11701 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11702 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11703 }
11704
11705 reg = SET_SRC (synth);
41f3a930 11706
c19de7aa 11707 synth = replace_rtx (synth, reg,
41f3a930 11708 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11709
11710 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11711 synth = replace_rtx (synth, offset,
11712 GEN_INT (INTVAL (offset)
11713 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11714
11715 RTX_FRAME_RELATED_P (synth) = 1;
11716 RTX_FRAME_RELATED_P (real2) = 1;
11717 if (BYTES_BIG_ENDIAN)
11718 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11719 else
11720 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11721
11722 return real;
11723}
11724
00b960c7
AH
11725/* Returns an insn that has a vrsave set operation with the
11726 appropriate CLOBBERs. */
11727
11728static rtx
a2369ed3 11729generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
11730{
11731 int nclobs, i;
11732 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11733 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11734
a004eb82
AH
11735 clobs[0]
11736 = gen_rtx_SET (VOIDmode,
11737 vrsave,
11738 gen_rtx_UNSPEC_VOLATILE (SImode,
11739 gen_rtvec (2, reg, vrsave),
11740 30));
00b960c7
AH
11741
11742 nclobs = 1;
11743
9aa86737
AH
11744 /* We need to clobber the registers in the mask so the scheduler
11745 does not move sets to VRSAVE before sets of AltiVec registers.
11746
11747 However, if the function receives nonlocal gotos, reload will set
11748 all call saved registers live. We will end up with:
11749
11750 (set (reg 999) (mem))
11751 (parallel [ (set (reg vrsave) (unspec blah))
11752 (clobber (reg 999))])
11753
11754 The clobber will cause the store into reg 999 to be dead, and
11755 flow will attempt to delete an epilogue insn. In this case, we
11756 need an unspec use/set of the register. */
00b960c7
AH
11757
11758 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11759 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11760 {
11761 if (!epiloguep || call_used_regs [i])
11762 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11763 gen_rtx_REG (V4SImode, i));
11764 else
11765 {
11766 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11767
11768 clobs[nclobs++]
a004eb82
AH
11769 = gen_rtx_SET (VOIDmode,
11770 reg,
11771 gen_rtx_UNSPEC (V4SImode,
11772 gen_rtvec (1, reg), 27));
9aa86737
AH
11773 }
11774 }
00b960c7
AH
11775
11776 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11777
11778 for (i = 0; i < nclobs; ++i)
11779 XVECEXP (insn, 0, i) = clobs[i];
11780
11781 return insn;
11782}
11783
89e7058f
AH
11784/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11785 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11786
11787static void
a2369ed3 11788emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 11789 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
11790{
11791 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11792 rtx replacea, replaceb;
11793
11794 int_rtx = GEN_INT (offset);
11795
11796 /* Some cases that need register indexed addressing. */
11797 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11798 || (TARGET_SPE_ABI
11799 && SPE_VECTOR_MODE (mode)
11800 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11801 {
11802 /* Whomever calls us must make sure r11 is available in the
11803 flow path of instructions in the prologue. */
11804 offset_rtx = gen_rtx_REG (Pmode, 11);
11805 emit_move_insn (offset_rtx, int_rtx);
11806
11807 replacea = offset_rtx;
11808 replaceb = int_rtx;
11809 }
11810 else
11811 {
11812 offset_rtx = int_rtx;
11813 replacea = NULL_RTX;
11814 replaceb = NULL_RTX;
11815 }
11816
11817 reg = gen_rtx_REG (mode, regno);
11818 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11819 mem = gen_rtx_MEM (mode, addr);
11820 set_mem_alias_set (mem, rs6000_sr_alias_set);
11821
11822 insn = emit_move_insn (mem, reg);
11823
11824 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11825}
11826
a3170dc6
AH
11827/* Emit an offset memory reference suitable for a frame store, while
11828 converting to a valid addressing mode. */
11829
11830static rtx
a2369ed3 11831gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11832{
11833 rtx int_rtx, offset_rtx;
11834
11835 int_rtx = GEN_INT (offset);
11836
11837 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11838 {
11839 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11840 emit_move_insn (offset_rtx, int_rtx);
11841 }
11842 else
11843 offset_rtx = int_rtx;
11844
11845 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11846}
11847
9ebbca7d
GK
11848/* Emit function prologue as insns. */
11849
9878760c 11850void
863d938c 11851rs6000_emit_prologue (void)
9878760c 11852{
4697a36c 11853 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a
FJ
11854 enum machine_mode reg_mode = Pmode;
11855 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
11856 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11857 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11858 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 11859 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
11860 rtx insn;
11861 int saving_FPRs_inline;
11862 int using_store_multiple;
11863 HOST_WIDE_INT sp_offset = 0;
11864
c19de7aa 11865 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11866 {
11867 reg_mode = V2SImode;
11868 reg_size = 8;
11869 }
11870
9ebbca7d 11871 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11872 && (!TARGET_SPE_ABI
11873 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11874 && info->first_gp_reg_save < 31);
11875 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11876 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11877 || current_function_calls_eh_return
8c29550d 11878 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11879
11880 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11881 if (info->push_p
acd0b319
AM
11882 && (DEFAULT_ABI == ABI_V4
11883 || current_function_calls_eh_return))
9ebbca7d
GK
11884 {
11885 if (info->total_size < 32767)
11886 sp_offset = info->total_size;
11887 else
11888 frame_reg_rtx = frame_ptr_rtx;
11889 rs6000_emit_allocate_stack (info->total_size,
11890 (frame_reg_rtx != sp_reg_rtx
11891 && (info->cr_save_p
11892 || info->lr_save_p
11893 || info->first_fp_reg_save < 64
11894 || info->first_gp_reg_save < 32
11895 )));
11896 if (frame_reg_rtx != sp_reg_rtx)
11897 rs6000_emit_stack_tie ();
11898 }
11899
9aa86737
AH
11900 /* Save AltiVec registers if needed. */
11901 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11902 {
11903 int i;
11904
11905 /* There should be a non inline version of this, for when we
11906 are saving lots of vector registers. */
11907 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11908 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11909 {
11910 rtx areg, savereg, mem;
11911 int offset;
11912
11913 offset = info->altivec_save_offset + sp_offset
11914 + 16 * (i - info->first_altivec_reg_save);
11915
11916 savereg = gen_rtx_REG (V4SImode, i);
11917
11918 areg = gen_rtx_REG (Pmode, 0);
11919 emit_move_insn (areg, GEN_INT (offset));
11920
11921 /* AltiVec addressing mode is [reg+reg]. */
11922 mem = gen_rtx_MEM (V4SImode,
11923 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11924
11925 set_mem_alias_set (mem, rs6000_sr_alias_set);
11926
11927 insn = emit_move_insn (mem, savereg);
11928
5c242421
SB
11929 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11930 areg, GEN_INT (offset));
9aa86737
AH
11931 }
11932 }
11933
11934 /* VRSAVE is a bit vector representing which AltiVec registers
11935 are used. The OS uses this to determine which vector
11936 registers to save on a context switch. We need to save
11937 VRSAVE on the stack frame, add whatever AltiVec registers we
11938 used in this function, and do the corresponding magic in the
11939 epilogue. */
11940
4d774ff8
HP
11941 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
11942 && info->vrsave_mask != 0)
9aa86737 11943 {
a004eb82 11944 rtx reg, mem, vrsave;
9aa86737
AH
11945 int offset;
11946
11947 /* Get VRSAVE onto a GPR. */
11948 reg = gen_rtx_REG (SImode, 12);
a004eb82 11949 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11950 if (TARGET_MACHO)
11951 emit_insn (gen_get_vrsave_internal (reg));
11952 else
11953 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11954
11955 /* Save VRSAVE. */
11956 offset = info->vrsave_save_offset + sp_offset;
11957 mem
11958 = gen_rtx_MEM (SImode,
11959 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
11960 set_mem_alias_set (mem, rs6000_sr_alias_set);
11961 insn = emit_move_insn (mem, reg);
11962
11963 /* Include the registers in the mask. */
11964 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
11965
11966 insn = emit_insn (generate_set_vrsave (reg, info, 0));
11967 }
11968
9ebbca7d
GK
11969 /* If we use the link register, get it into r0. */
11970 if (info->lr_save_p)
71f123ca 11971 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
11972 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11973
11974 /* If we need to save CR, put it into r12. */
11975 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
11976 {
11977 cr_save_rtx = gen_rtx_REG (SImode, 12);
11978 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11979 }
11980
a4f6c312
SS
11981 /* Do any required saving of fpr's. If only one or two to save, do
11982 it ourselves. Otherwise, call function. */
9ebbca7d
GK
11983 if (saving_FPRs_inline)
11984 {
11985 int i;
11986 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11987 if ((regs_ever_live[info->first_fp_reg_save+i]
11988 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
11989 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
11990 info->first_fp_reg_save + i,
11991 info->fp_save_offset + sp_offset + 8 * i,
11992 info->total_size);
9ebbca7d
GK
11993 }
11994 else if (info->first_fp_reg_save != 64)
11995 {
11996 int i;
11997 char rname[30];
520a57c8 11998 const char *alloc_rname;
9ebbca7d
GK
11999 rtvec p;
12000 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
12001
12002 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
12003 gen_rtx_REG (Pmode,
12004 LINK_REGISTER_REGNUM));
12005 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
12006 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 12007 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12008 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
12009 gen_rtx_SYMBOL_REF (Pmode,
12010 alloc_rname));
12011 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12012 {
12013 rtx addr, reg, mem;
12014 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
12015 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12016 GEN_INT (info->fp_save_offset
12017 + sp_offset + 8*i));
12018 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12019 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12020
12021 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
12022 }
12023 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12024 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12025 NULL_RTX, NULL_RTX);
12026 }
b6c9286a 12027
9ebbca7d
GK
12028 /* Save GPRs. This is done as a PARALLEL if we are using
12029 the store-multiple instructions. */
12030 if (using_store_multiple)
b6c9286a 12031 {
308c142a 12032 rtvec p;
9ebbca7d
GK
12033 int i;
12034 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
12035 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12036 {
12037 rtx addr, reg, mem;
12038 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12039 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12040 GEN_INT (info->gp_save_offset
12041 + sp_offset
12042 + reg_size * i));
12043 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12044 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12045
12046 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
12047 }
12048 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12049 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12050 NULL_RTX, NULL_RTX);
b6c9286a
MM
12051 }
12052 else
12053 {
9ebbca7d
GK
12054 int i;
12055 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12056 if ((regs_ever_live[info->first_gp_reg_save+i]
12057 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12058 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12059 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12060 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
12061 {
12062 rtx addr, reg, mem;
12063 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12064
c19de7aa 12065 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12066 {
12067 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12068 rtx b;
12069
12070 if (!SPE_CONST_OFFSET_OK (offset))
12071 {
12072 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12073 emit_move_insn (b, GEN_INT (offset));
12074 }
12075 else
12076 b = GEN_INT (offset);
12077
12078 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12079 mem = gen_rtx_MEM (V2SImode, addr);
12080 set_mem_alias_set (mem, rs6000_sr_alias_set);
12081 insn = emit_move_insn (mem, reg);
12082
12083 if (GET_CODE (b) == CONST_INT)
12084 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12085 NULL_RTX, NULL_RTX);
12086 else
12087 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12088 b, GEN_INT (offset));
12089 }
12090 else
12091 {
12092 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12093 GEN_INT (info->gp_save_offset
12094 + sp_offset
12095 + reg_size * i));
12096 mem = gen_rtx_MEM (reg_mode, addr);
12097 set_mem_alias_set (mem, rs6000_sr_alias_set);
12098
12099 insn = emit_move_insn (mem, reg);
12100 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12101 NULL_RTX, NULL_RTX);
12102 }
12103 }
9ebbca7d
GK
12104 }
12105
83720594
RH
12106 /* ??? There's no need to emit actual instructions here, but it's the
12107 easiest way to get the frame unwind information emitted. */
12108 if (current_function_calls_eh_return)
12109 {
78e1b90d
DE
12110 unsigned int i, regno;
12111
fc4767bb
JJ
12112 /* In AIX ABI we need to pretend we save r2 here. */
12113 if (TARGET_AIX)
12114 {
12115 rtx addr, reg, mem;
12116
12117 reg = gen_rtx_REG (reg_mode, 2);
12118 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12119 GEN_INT (sp_offset + 5 * reg_size));
12120 mem = gen_rtx_MEM (reg_mode, addr);
12121 set_mem_alias_set (mem, rs6000_sr_alias_set);
12122
12123 insn = emit_move_insn (mem, reg);
12124 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12125 NULL_RTX, NULL_RTX);
12126 PATTERN (insn) = gen_blockage ();
12127 }
12128
83720594
RH
12129 for (i = 0; ; ++i)
12130 {
83720594
RH
12131 regno = EH_RETURN_DATA_REGNO (i);
12132 if (regno == INVALID_REGNUM)
12133 break;
12134
89e7058f
AH
12135 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
12136 info->ehrd_offset + sp_offset
12137 + reg_size * (int) i,
12138 info->total_size);
83720594
RH
12139 }
12140 }
12141
9ebbca7d
GK
12142 /* Save lr if we used it. */
12143 if (info->lr_save_p)
12144 {
12145 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12146 GEN_INT (info->lr_save_offset + sp_offset));
12147 rtx reg = gen_rtx_REG (Pmode, 0);
12148 rtx mem = gen_rtx_MEM (Pmode, addr);
12149 /* This should not be of rs6000_sr_alias_set, because of
12150 __builtin_return_address. */
12151
12152 insn = emit_move_insn (mem, reg);
12153 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12154 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12155 }
12156
12157 /* Save CR if we use any that must be preserved. */
12158 if (info->cr_save_p)
12159 {
12160 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12161 GEN_INT (info->cr_save_offset + sp_offset));
12162 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12163
12164 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12165
12166 /* If r12 was used to hold the original sp, copy cr into r0 now
12167 that it's free. */
12168 if (REGNO (frame_reg_rtx) == 12)
12169 {
12170 cr_save_rtx = gen_rtx_REG (SImode, 0);
12171 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12172 }
12173 insn = emit_move_insn (mem, cr_save_rtx);
12174
12175 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
12176 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
12177 But that's OK. All we have to do is specify that _one_ condition
12178 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
12179 will then restore all the call-saved registers.
12180 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 12181 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 12182 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
12183 }
12184
12185 /* Update stack and set back pointer unless this is V.4,
12186 for which it was done previously. */
fc4767bb
JJ
12187 if (info->push_p
12188 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
12189 rs6000_emit_allocate_stack (info->total_size, FALSE);
12190
12191 /* Set frame pointer, if needed. */
12192 if (frame_pointer_needed)
12193 {
a3170dc6 12194 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
12195 sp_reg_rtx);
12196 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 12197 }
9878760c 12198
1db02437 12199 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12200 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12201 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12202 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12203 {
12204 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12205 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12206 can use register 0. This allows us to use a plain 'blr' to return
12207 from the procedure more often. */
f1384257
AM
12208 int save_LR_around_toc_setup = (TARGET_ELF
12209 && DEFAULT_ABI != ABI_AIX
12210 && flag_pic
d5fa86ba
GK
12211 && ! info->lr_save_p
12212 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12213 if (save_LR_around_toc_setup)
c4501e62
JJ
12214 {
12215 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12216 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12217 rs6000_emit_load_toc_table (TRUE);
12218 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12219 }
12220 else
12221 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12222 }
ee890fe2 12223
fcce224d 12224#if TARGET_MACHO
ee890fe2
SS
12225 if (DEFAULT_ABI == ABI_DARWIN
12226 && flag_pic && current_function_uses_pic_offset_table)
12227 {
12228 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12229 const char *picbase = machopic_function_base_name ();
6788f5ca 12230 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12231
f51eee6a 12232 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12233
12234 rs6000_maybe_dead (
1db02437 12235 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12236 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12237 }
fcce224d 12238#endif
9ebbca7d
GK
12239}
12240
9ebbca7d 12241/* Write function prologue. */
a4f6c312 12242
08c148a8 12243static void
a2369ed3
DJ
12244rs6000_output_function_prologue (FILE *file,
12245 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12246{
12247 rs6000_stack_t *info = rs6000_stack_info ();
12248
4697a36c
MM
12249 if (TARGET_DEBUG_STACK)
12250 debug_stack_info (info);
9878760c 12251
a4f6c312
SS
12252 /* Write .extern for any function we will call to save and restore
12253 fp values. */
12254 if (info->first_fp_reg_save < 64
12255 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12256 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12257 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12258 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12259 RESTORE_FP_SUFFIX);
9878760c 12260
c764f757
RK
12261 /* Write .extern for AIX common mode routines, if needed. */
12262 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12263 {
f6709c70
JW
12264 fputs ("\t.extern __mulh\n", file);
12265 fputs ("\t.extern __mull\n", file);
12266 fputs ("\t.extern __divss\n", file);
12267 fputs ("\t.extern __divus\n", file);
12268 fputs ("\t.extern __quoss\n", file);
12269 fputs ("\t.extern __quous\n", file);
c764f757
RK
12270 common_mode_defined = 1;
12271 }
9878760c 12272
9ebbca7d 12273 if (! HAVE_prologue)
979721f8 12274 {
9ebbca7d 12275 start_sequence ();
9dda4cc8 12276
a4f6c312
SS
12277 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12278 the "toplevel" insn chain. */
2e040219 12279 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12280 rs6000_emit_prologue ();
2e040219 12281 emit_note (NOTE_INSN_DELETED);
178c3eff 12282
a3c9585f 12283 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12284 {
12285 rtx insn;
12286 unsigned addr = 0;
12287 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12288 {
12289 INSN_ADDRESSES_NEW (insn, addr);
12290 addr += 4;
12291 }
12292 }
9dda4cc8 12293
9ebbca7d 12294 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12295 debug_rtx_list (get_insns (), 100);
12296 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12297 end_sequence ();
979721f8
MM
12298 }
12299
9ebbca7d
GK
12300 rs6000_pic_labelno++;
12301}
12302
12303/* Emit function epilogue as insns.
9878760c 12304
9ebbca7d
GK
12305 At present, dwarf2out_frame_debug_expr doesn't understand
12306 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12307 anywhere in the epilogue. Most of the insns below would in any case
12308 need special notes to explain where r11 is in relation to the stack. */
9878760c 12309
9ebbca7d 12310void
a2369ed3 12311rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12312{
12313 rs6000_stack_t *info;
12314 int restoring_FPRs_inline;
12315 int using_load_multiple;
12316 int using_mfcr_multiple;
12317 int use_backchain_to_restore_sp;
12318 int sp_offset = 0;
12319 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12320 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a
FJ
12321 enum machine_mode reg_mode = Pmode;
12322 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
12323 int i;
12324
c19de7aa
AH
12325 info = rs6000_stack_info ();
12326
12327 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12328 {
12329 reg_mode = V2SImode;
12330 reg_size = 8;
12331 }
12332
9ebbca7d 12333 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12334 && (!TARGET_SPE_ABI
12335 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12336 && info->first_gp_reg_save < 31);
12337 restoring_FPRs_inline = (sibcall
83720594 12338 || current_function_calls_eh_return
9ebbca7d
GK
12339 || info->first_fp_reg_save == 64
12340 || FP_SAVE_INLINE (info->first_fp_reg_save));
12341 use_backchain_to_restore_sp = (frame_pointer_needed
12342 || current_function_calls_alloca
12343 || info->total_size > 32767);
12344 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12345 || rs6000_cpu == PROCESSOR_PPC603
12346 || rs6000_cpu == PROCESSOR_PPC750
12347 || optimize_size);
12348
12349 /* If we have a frame pointer, a call to alloca, or a large stack
12350 frame, restore the old stack pointer using the backchain. Otherwise,
12351 we know what size to update it with. */
12352 if (use_backchain_to_restore_sp)
bacbde18 12353 {
9ebbca7d
GK
12354 /* Under V.4, don't reset the stack pointer until after we're done
12355 loading the saved registers. */
f607bc57 12356 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12357 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12358
9ebbca7d
GK
12359 emit_move_insn (frame_reg_rtx,
12360 gen_rtx_MEM (Pmode, sp_reg_rtx));
12361
bacbde18 12362 }
9ebbca7d 12363 else if (info->push_p)
85638c0d 12364 {
fc4767bb
JJ
12365 if (DEFAULT_ABI == ABI_V4
12366 || current_function_calls_eh_return)
9ebbca7d
GK
12367 sp_offset = info->total_size;
12368 else
12369 {
12370 emit_insn (TARGET_32BIT
12371 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12372 GEN_INT (info->total_size))
12373 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12374 GEN_INT (info->total_size)));
12375 }
85638c0d 12376 }
9ebbca7d 12377
9aa86737
AH
12378 /* Restore AltiVec registers if needed. */
12379 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12380 {
12381 int i;
12382
12383 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12384 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12385 {
12386 rtx addr, areg, mem;
12387
12388 areg = gen_rtx_REG (Pmode, 0);
12389 emit_move_insn
12390 (areg, GEN_INT (info->altivec_save_offset
12391 + sp_offset
12392 + 16 * (i - info->first_altivec_reg_save)));
12393
12394 /* AltiVec addressing mode is [reg+reg]. */
12395 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12396 mem = gen_rtx_MEM (V4SImode, addr);
12397 set_mem_alias_set (mem, rs6000_sr_alias_set);
12398
12399 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12400 }
12401 }
12402
12403 /* Restore VRSAVE if needed. */
4d774ff8
HP
12404 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE
12405 && info->vrsave_mask != 0)
9aa86737
AH
12406 {
12407 rtx addr, mem, reg;
12408
12409 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12410 GEN_INT (info->vrsave_save_offset + sp_offset));
12411 mem = gen_rtx_MEM (SImode, addr);
12412 set_mem_alias_set (mem, rs6000_sr_alias_set);
12413 reg = gen_rtx_REG (SImode, 12);
12414 emit_move_insn (reg, mem);
12415
12416 emit_insn (generate_set_vrsave (reg, info, 1));
12417 }
12418
9ebbca7d
GK
12419 /* Get the old lr if we saved it. */
12420 if (info->lr_save_p)
b6c9286a 12421 {
a3170dc6
AH
12422 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12423 info->lr_save_offset + sp_offset);
ba4828e0
RK
12424
12425 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12426
9ebbca7d 12427 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12428 }
9ebbca7d
GK
12429
12430 /* Get the old cr if we saved it. */
12431 if (info->cr_save_p)
12432 {
12433 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12434 GEN_INT (info->cr_save_offset + sp_offset));
12435 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12436
12437 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12438
9ebbca7d
GK
12439 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12440 }
12441
12442 /* Set LR here to try to overlap restores below. */
4697a36c 12443 if (info->lr_save_p)
9ebbca7d
GK
12444 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12445 gen_rtx_REG (Pmode, 0));
12446
83720594
RH
12447 /* Load exception handler data registers, if needed. */
12448 if (current_function_calls_eh_return)
12449 {
78e1b90d
DE
12450 unsigned int i, regno;
12451
fc4767bb
JJ
12452 if (TARGET_AIX)
12453 {
12454 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12455 GEN_INT (sp_offset + 5 * reg_size));
12456 rtx mem = gen_rtx_MEM (reg_mode, addr);
12457
12458 set_mem_alias_set (mem, rs6000_sr_alias_set);
12459
12460 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12461 }
12462
83720594
RH
12463 for (i = 0; ; ++i)
12464 {
a3170dc6 12465 rtx mem;
83720594
RH
12466
12467 regno = EH_RETURN_DATA_REGNO (i);
12468 if (regno == INVALID_REGNUM)
12469 break;
12470
a3170dc6
AH
12471 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12472 info->ehrd_offset + sp_offset
12473 + reg_size * (int) i);
ba4828e0 12474 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12475
12476 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12477 }
12478 }
9ebbca7d
GK
12479
12480 /* Restore GPRs. This is done as a PARALLEL if we are using
12481 the load-multiple instructions. */
12482 if (using_load_multiple)
979721f8 12483 {
9ebbca7d
GK
12484 rtvec p;
12485 p = rtvec_alloc (32 - info->first_gp_reg_save);
12486 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12487 {
9ebbca7d
GK
12488 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12489 GEN_INT (info->gp_save_offset
12490 + sp_offset
12491 + reg_size * i));
12492 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12493
12494 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12495
12496 RTVEC_ELT (p, i) =
12497 gen_rtx_SET (VOIDmode,
12498 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12499 mem);
979721f8 12500 }
9ebbca7d 12501 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12502 }
9ebbca7d
GK
12503 else
12504 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12505 if ((regs_ever_live[info->first_gp_reg_save+i]
12506 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12507 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12508 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12509 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12510 {
12511 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12512 GEN_INT (info->gp_save_offset
12513 + sp_offset
12514 + reg_size * i));
12515 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12516
a3170dc6 12517 /* Restore 64-bit quantities for SPE. */
c19de7aa 12518 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12519 {
12520 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12521 rtx b;
12522
12523 if (!SPE_CONST_OFFSET_OK (offset))
12524 {
12525 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12526 emit_move_insn (b, GEN_INT (offset));
12527 }
12528 else
12529 b = GEN_INT (offset);
12530
12531 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12532 mem = gen_rtx_MEM (V2SImode, addr);
12533 }
12534
ba4828e0 12535 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12536
12537 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12538 info->first_gp_reg_save + i), mem);
9ebbca7d 12539 }
9878760c 12540
9ebbca7d
GK
12541 /* Restore fpr's if we need to do it without calling a function. */
12542 if (restoring_FPRs_inline)
12543 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12544 if ((regs_ever_live[info->first_fp_reg_save+i]
12545 && ! call_used_regs[info->first_fp_reg_save+i]))
12546 {
12547 rtx addr, mem;
12548 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12549 GEN_INT (info->fp_save_offset
12550 + sp_offset
a4f6c312 12551 + 8 * i));
9ebbca7d 12552 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12553 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12554
12555 emit_move_insn (gen_rtx_REG (DFmode,
12556 info->first_fp_reg_save + i),
12557 mem);
12558 }
8d30c4ee 12559
9ebbca7d
GK
12560 /* If we saved cr, restore it here. Just those that were used. */
12561 if (info->cr_save_p)
979721f8 12562 {
9ebbca7d 12563 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12564 int count = 0;
9ebbca7d
GK
12565
12566 if (using_mfcr_multiple)
979721f8 12567 {
9ebbca7d
GK
12568 for (i = 0; i < 8; i++)
12569 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12570 count++;
9ebbca7d 12571 if (count == 0)
e35b9579
GK
12572 abort ();
12573 }
12574
12575 if (using_mfcr_multiple && count > 1)
12576 {
12577 rtvec p;
12578 int ndx;
9ebbca7d 12579
e35b9579 12580 p = rtvec_alloc (count);
9ebbca7d 12581
e35b9579 12582 ndx = 0;
9ebbca7d
GK
12583 for (i = 0; i < 8; i++)
12584 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12585 {
12586 rtvec r = rtvec_alloc (2);
12587 RTVEC_ELT (r, 0) = r12_rtx;
12588 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12589 RTVEC_ELT (p, ndx) =
9ebbca7d 12590 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12591 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12592 ndx++;
9ebbca7d
GK
12593 }
12594 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12595 if (ndx != count)
12596 abort ();
979721f8
MM
12597 }
12598 else
9ebbca7d
GK
12599 for (i = 0; i < 8; i++)
12600 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12601 {
9ebbca7d
GK
12602 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12603 CR0_REGNO+i),
12604 r12_rtx));
979721f8 12605 }
979721f8
MM
12606 }
12607
9ebbca7d
GK
12608 /* If this is V.4, unwind the stack pointer after all of the loads
12609 have been done. We need to emit a block here so that sched
12610 doesn't decide to move the sp change before the register restores
12611 (which may not have any obvious dependency on the stack). This
12612 doesn't hurt performance, because there is no scheduling that can
12613 be done after this point. */
fc4767bb
JJ
12614 if (DEFAULT_ABI == ABI_V4
12615 || current_function_calls_eh_return)
b6c9286a 12616 {
9ebbca7d
GK
12617 if (frame_reg_rtx != sp_reg_rtx)
12618 rs6000_emit_stack_tie ();
b6c9286a 12619
9ebbca7d 12620 if (use_backchain_to_restore_sp)
b6c9286a 12621 {
9ebbca7d 12622 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12623 }
9ebbca7d 12624 else if (sp_offset != 0)
13f1623b 12625 {
5b71a4e7 12626 emit_insn (TARGET_32BIT
9ebbca7d
GK
12627 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12628 GEN_INT (sp_offset))
12629 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12630 GEN_INT (sp_offset)));
13f1623b 12631 }
9ebbca7d 12632 }
b6c9286a 12633
83720594
RH
12634 if (current_function_calls_eh_return)
12635 {
12636 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12637 emit_insn (TARGET_32BIT
83720594
RH
12638 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12639 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12640 }
12641
9ebbca7d
GK
12642 if (!sibcall)
12643 {
12644 rtvec p;
12645 if (! restoring_FPRs_inline)
12646 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12647 else
12648 p = rtvec_alloc (2);
b6c9286a 12649
e35b9579
GK
12650 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12651 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12652 gen_rtx_REG (Pmode,
12653 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12654
12655 /* If we have to restore more than two FP registers, branch to the
12656 restore function. It will return to our caller. */
12657 if (! restoring_FPRs_inline)
12658 {
12659 int i;
12660 char rname[30];
520a57c8 12661 const char *alloc_rname;
979721f8 12662
9ebbca7d
GK
12663 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12664 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12665 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12666 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12667 gen_rtx_SYMBOL_REF (Pmode,
12668 alloc_rname));
b6c9286a 12669
9ebbca7d
GK
12670 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12671 {
12672 rtx addr, mem;
12673 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12674 GEN_INT (info->fp_save_offset + 8*i));
12675 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12676 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12677
12678 RTVEC_ELT (p, i+3) =
12679 gen_rtx_SET (VOIDmode,
12680 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12681 mem);
b6c9286a
MM
12682 }
12683 }
9ebbca7d
GK
12684
12685 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12686 }
9878760c
RK
12687}
12688
12689/* Write function epilogue. */
12690
08c148a8 12691static void
a2369ed3
DJ
12692rs6000_output_function_epilogue (FILE *file,
12693 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 12694{
4697a36c 12695 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12696
9ebbca7d 12697 if (! HAVE_epilogue)
9878760c 12698 {
9ebbca7d
GK
12699 rtx insn = get_last_insn ();
12700 /* If the last insn was a BARRIER, we don't have to write anything except
12701 the trace table. */
12702 if (GET_CODE (insn) == NOTE)
12703 insn = prev_nonnote_insn (insn);
12704 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12705 {
9ebbca7d
GK
12706 /* This is slightly ugly, but at least we don't have two
12707 copies of the epilogue-emitting code. */
12708 start_sequence ();
12709
12710 /* A NOTE_INSN_DELETED is supposed to be at the start
12711 and end of the "toplevel" insn chain. */
2e040219 12712 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12713 rs6000_emit_epilogue (FALSE);
2e040219 12714 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12715
a3c9585f 12716 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12717 {
12718 rtx insn;
12719 unsigned addr = 0;
12720 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12721 {
12722 INSN_ADDRESSES_NEW (insn, addr);
12723 addr += 4;
12724 }
12725 }
12726
9ebbca7d 12727 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12728 debug_rtx_list (get_insns (), 100);
12729 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12730 end_sequence ();
4697a36c 12731 }
9878760c 12732 }
b4ac57ab 12733
efdba735
SH
12734#if TARGET_MACHO
12735 macho_branch_islands ();
0e5da0be
GK
12736 /* Mach-O doesn't support labels at the end of objects, so if
12737 it looks like we might want one, insert a NOP. */
12738 {
12739 rtx insn = get_last_insn ();
12740 while (insn
12741 && NOTE_P (insn)
12742 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
12743 insn = PREV_INSN (insn);
12744 if (insn
12745 && (LABEL_P (insn)
12746 || (NOTE_P (insn)
12747 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
12748 fputs ("\tnop\n", file);
12749 }
12750#endif
12751
9b30bae2 12752 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12753 on its format.
12754
12755 We don't output a traceback table if -finhibit-size-directive was
12756 used. The documentation for -finhibit-size-directive reads
12757 ``don't output a @code{.size} assembler directive, or anything
12758 else that would cause trouble if the function is split in the
12759 middle, and the two halves are placed at locations far apart in
12760 memory.'' The traceback table has this property, since it
12761 includes the offset from the start of the function to the
4d30c363
MM
12762 traceback table itself.
12763
12764 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12765 different traceback table. */
57ac7be9
AM
12766 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12767 && rs6000_traceback != traceback_none)
9b30bae2 12768 {
69c75916 12769 const char *fname = NULL;
3ac88239 12770 const char *language_string = lang_hooks.name;
6041bf2f 12771 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12772 int i;
57ac7be9
AM
12773 int optional_tbtab;
12774
12775 if (rs6000_traceback == traceback_full)
12776 optional_tbtab = 1;
12777 else if (rs6000_traceback == traceback_part)
12778 optional_tbtab = 0;
12779 else
12780 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12781
69c75916
AM
12782 if (optional_tbtab)
12783 {
12784 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12785 while (*fname == '.') /* V.4 encodes . in the name */
12786 fname++;
12787
12788 /* Need label immediately before tbtab, so we can compute
12789 its offset from the function start. */
12790 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12791 ASM_OUTPUT_LABEL (file, fname);
12792 }
314fc5a9
ILT
12793
12794 /* The .tbtab pseudo-op can only be used for the first eight
12795 expressions, since it can't handle the possibly variable
12796 length fields that follow. However, if you omit the optional
12797 fields, the assembler outputs zeros for all optional fields
12798 anyways, giving each variable length field is minimum length
12799 (as defined in sys/debug.h). Thus we can not use the .tbtab
12800 pseudo-op at all. */
12801
12802 /* An all-zero word flags the start of the tbtab, for debuggers
12803 that have to find it by searching forward from the entry
12804 point or from the current pc. */
19d2d16f 12805 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12806
12807 /* Tbtab format type. Use format type 0. */
19d2d16f 12808 fputs ("\t.byte 0,", file);
314fc5a9 12809
5fc921c1
DE
12810 /* Language type. Unfortunately, there does not seem to be any
12811 official way to discover the language being compiled, so we
12812 use language_string.
12813 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
12814 Java is 13. Objective-C is 14. */
12815 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
12816 i = 0;
12817 else if (! strcmp (language_string, "GNU F77"))
12818 i = 1;
8b83775b 12819 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 12820 i = 2;
5fc921c1
DE
12821 else if (! strcmp (language_string, "GNU Ada"))
12822 i = 3;
314fc5a9
ILT
12823 else if (! strcmp (language_string, "GNU C++"))
12824 i = 9;
9517ead8
AG
12825 else if (! strcmp (language_string, "GNU Java"))
12826 i = 13;
5fc921c1
DE
12827 else if (! strcmp (language_string, "GNU Objective-C"))
12828 i = 14;
314fc5a9
ILT
12829 else
12830 abort ();
12831 fprintf (file, "%d,", i);
12832
12833 /* 8 single bit fields: global linkage (not set for C extern linkage,
12834 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12835 from start of procedure stored in tbtab, internal function, function
12836 has controlled storage, function has no toc, function uses fp,
12837 function logs/aborts fp operations. */
12838 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12839 fprintf (file, "%d,",
12840 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12841
12842 /* 6 bitfields: function is interrupt handler, name present in
12843 proc table, function calls alloca, on condition directives
12844 (controls stack walks, 3 bits), saves condition reg, saves
12845 link reg. */
12846 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12847 set up as a frame pointer, even when there is no alloca call. */
12848 fprintf (file, "%d,",
6041bf2f
DE
12849 ((optional_tbtab << 6)
12850 | ((optional_tbtab & frame_pointer_needed) << 5)
12851 | (info->cr_save_p << 1)
12852 | (info->lr_save_p)));
314fc5a9 12853
6041bf2f 12854 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12855 (6 bits). */
12856 fprintf (file, "%d,",
4697a36c 12857 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12858
12859 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12860 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12861
6041bf2f
DE
12862 if (optional_tbtab)
12863 {
12864 /* Compute the parameter info from the function decl argument
12865 list. */
12866 tree decl;
12867 int next_parm_info_bit = 31;
314fc5a9 12868
6041bf2f
DE
12869 for (decl = DECL_ARGUMENTS (current_function_decl);
12870 decl; decl = TREE_CHAIN (decl))
12871 {
12872 rtx parameter = DECL_INCOMING_RTL (decl);
12873 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12874
6041bf2f
DE
12875 if (GET_CODE (parameter) == REG)
12876 {
12877 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12878 {
12879 int bits;
12880
12881 float_parms++;
12882
12883 if (mode == SFmode)
12884 bits = 0x2;
fcce224d 12885 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12886 bits = 0x3;
12887 else
12888 abort ();
12889
12890 /* If only one bit will fit, don't or in this entry. */
12891 if (next_parm_info_bit > 0)
12892 parm_info |= (bits << (next_parm_info_bit - 1));
12893 next_parm_info_bit -= 2;
12894 }
12895 else
12896 {
12897 fixed_parms += ((GET_MODE_SIZE (mode)
12898 + (UNITS_PER_WORD - 1))
12899 / UNITS_PER_WORD);
12900 next_parm_info_bit -= 1;
12901 }
12902 }
12903 }
12904 }
314fc5a9
ILT
12905
12906 /* Number of fixed point parameters. */
12907 /* This is actually the number of words of fixed point parameters; thus
12908 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12909 fprintf (file, "%d,", fixed_parms);
12910
12911 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12912 all on stack. */
12913 /* This is actually the number of fp registers that hold parameters;
12914 and thus the maximum value is 13. */
12915 /* Set parameters on stack bit if parameters are not in their original
12916 registers, regardless of whether they are on the stack? Xlc
12917 seems to set the bit when not optimizing. */
12918 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12919
6041bf2f
DE
12920 if (! optional_tbtab)
12921 return;
12922
314fc5a9
ILT
12923 /* Optional fields follow. Some are variable length. */
12924
12925 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12926 11 double float. */
12927 /* There is an entry for each parameter in a register, in the order that
12928 they occur in the parameter list. Any intervening arguments on the
12929 stack are ignored. If the list overflows a long (max possible length
12930 34 bits) then completely leave off all elements that don't fit. */
12931 /* Only emit this long if there was at least one parameter. */
12932 if (fixed_parms || float_parms)
12933 fprintf (file, "\t.long %d\n", parm_info);
12934
12935 /* Offset from start of code to tb table. */
19d2d16f 12936 fputs ("\t.long ", file);
314fc5a9 12937 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12938#if TARGET_AIX
12939 RS6000_OUTPUT_BASENAME (file, fname);
12940#else
9ebbca7d 12941 assemble_name (file, fname);
54ee9799 12942#endif
19d2d16f 12943 fputs ("-.", file);
54ee9799
DE
12944#if TARGET_AIX
12945 RS6000_OUTPUT_BASENAME (file, fname);
12946#else
9ebbca7d 12947 assemble_name (file, fname);
54ee9799 12948#endif
19d2d16f 12949 putc ('\n', file);
314fc5a9
ILT
12950
12951 /* Interrupt handler mask. */
12952 /* Omit this long, since we never set the interrupt handler bit
12953 above. */
12954
12955 /* Number of CTL (controlled storage) anchors. */
12956 /* Omit this long, since the has_ctl bit is never set above. */
12957
12958 /* Displacement into stack of each CTL anchor. */
12959 /* Omit this list of longs, because there are no CTL anchors. */
12960
12961 /* Length of function name. */
69c75916
AM
12962 if (*fname == '*')
12963 ++fname;
296b8152 12964 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
12965
12966 /* Function name. */
12967 assemble_string (fname, strlen (fname));
12968
12969 /* Register for alloca automatic storage; this is always reg 31.
12970 Only emit this if the alloca bit was set above. */
12971 if (frame_pointer_needed)
19d2d16f 12972 fputs ("\t.byte 31\n", file);
b1765bde
DE
12973
12974 fputs ("\t.align 2\n", file);
9b30bae2 12975 }
9878760c 12976}
17167fd8 12977\f
a4f6c312
SS
12978/* A C compound statement that outputs the assembler code for a thunk
12979 function, used to implement C++ virtual function calls with
12980 multiple inheritance. The thunk acts as a wrapper around a virtual
12981 function, adjusting the implicit object parameter before handing
12982 control off to the real function.
12983
12984 First, emit code to add the integer DELTA to the location that
12985 contains the incoming first argument. Assume that this argument
12986 contains a pointer, and is the one used to pass the `this' pointer
12987 in C++. This is the incoming argument *before* the function
12988 prologue, e.g. `%o0' on a sparc. The addition must preserve the
12989 values of all other incoming arguments.
17167fd8
MM
12990
12991 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
12992 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
12993 not touch the return address. Hence returning from FUNCTION will
12994 return to whoever called the current `thunk'.
17167fd8 12995
a4f6c312
SS
12996 The effect must be as if FUNCTION had been called directly with the
12997 adjusted first argument. This macro is responsible for emitting
12998 all of the code for a thunk function; output_function_prologue()
12999 and output_function_epilogue() are not invoked.
17167fd8 13000
a4f6c312
SS
13001 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
13002 been extracted from it.) It might possibly be useful on some
13003 targets, but probably not.
17167fd8 13004
a4f6c312
SS
13005 If you do not define this macro, the target-independent code in the
13006 C++ frontend will generate a less efficient heavyweight thunk that
13007 calls FUNCTION instead of jumping to it. The generic approach does
13008 not support varargs. */
17167fd8 13009
3961e8fe 13010static void
a2369ed3
DJ
13011rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
13012 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
13013 tree function)
17167fd8 13014{
5b71a4e7 13015 rtx this, insn, funexp;
17167fd8 13016
5b71a4e7 13017 reload_completed = 1;
fe3ad572 13018 epilogue_completed = 1;
5b71a4e7 13019 no_new_pseudos = 1;
56a7189a 13020
5b71a4e7 13021 /* Mark the end of the (empty) prologue. */
2e040219 13022 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 13023
5b71a4e7
DE
13024 /* Find the "this" pointer. If the function returns a structure,
13025 the structure return pointer is in r3. */
61f71b34 13026 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 13027 this = gen_rtx_REG (Pmode, 4);
56a7189a 13028 else
5b71a4e7 13029 this = gen_rtx_REG (Pmode, 3);
17167fd8 13030
5b71a4e7
DE
13031 /* Apply the constant offset, if required. */
13032 if (delta)
13033 {
13034 rtx delta_rtx = GEN_INT (delta);
13035 emit_insn (TARGET_32BIT
13036 ? gen_addsi3 (this, this, delta_rtx)
13037 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
13038 }
13039
5b71a4e7
DE
13040 /* Apply the offset from the vtable, if required. */
13041 if (vcall_offset)
17167fd8 13042 {
5b71a4e7
DE
13043 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
13044 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 13045
5b71a4e7 13046 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
13047 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
13048 {
13049 emit_insn (TARGET_32BIT
13050 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
13051 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
13052 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
13053 }
13054 else
13055 {
13056 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
13057
13058 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
13059 }
5b71a4e7
DE
13060 emit_insn (TARGET_32BIT
13061 ? gen_addsi3 (this, this, tmp)
13062 : gen_adddi3 (this, this, tmp));
17167fd8
MM
13063 }
13064
5b71a4e7
DE
13065 /* Generate a tail call to the target function. */
13066 if (!TREE_USED (function))
13067 {
13068 assemble_external (function);
13069 TREE_USED (function) = 1;
13070 }
13071 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 13072 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
13073
13074#if TARGET_MACHO
ab82a49f 13075 if (MACHOPIC_INDIRECT)
5b71a4e7 13076 funexp = machopic_indirect_call_target (funexp);
ee890fe2 13077#endif
5b71a4e7
DE
13078
13079 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
13080 generate sibcall RTL explicitly to avoid constraint abort. */
13081 insn = emit_call_insn (
13082 gen_rtx_PARALLEL (VOIDmode,
13083 gen_rtvec (4,
13084 gen_rtx_CALL (VOIDmode,
13085 funexp, const0_rtx),
13086 gen_rtx_USE (VOIDmode, const0_rtx),
13087 gen_rtx_USE (VOIDmode,
13088 gen_rtx_REG (SImode,
13089 LINK_REGISTER_REGNUM)),
13090 gen_rtx_RETURN (VOIDmode))));
13091 SIBLING_CALL_P (insn) = 1;
13092 emit_barrier ();
13093
13094 /* Run just enough of rest_of_compilation to get the insns emitted.
13095 There's not really enough bulk here to make other passes such as
13096 instruction scheduling worth while. Note that use_thunk calls
13097 assemble_start_function and assemble_end_function. */
13098 insn = get_insns ();
a2855205 13099 insn_locators_initialize ();
5b71a4e7
DE
13100 shorten_branches (insn);
13101 final_start_function (insn, file, 1);
13102 final (insn, file, 1, 0);
13103 final_end_function ();
13104
13105 reload_completed = 0;
fe3ad572 13106 epilogue_completed = 0;
5b71a4e7 13107 no_new_pseudos = 0;
9ebbca7d 13108}
9ebbca7d
GK
13109\f
13110/* A quick summary of the various types of 'constant-pool tables'
13111 under PowerPC:
13112
13113 Target Flags Name One table per
13114 AIX (none) AIX TOC object file
13115 AIX -mfull-toc AIX TOC object file
13116 AIX -mminimal-toc AIX minimal TOC translation unit
13117 SVR4/EABI (none) SVR4 SDATA object file
13118 SVR4/EABI -fpic SVR4 pic object file
13119 SVR4/EABI -fPIC SVR4 PIC translation unit
13120 SVR4/EABI -mrelocatable EABI TOC function
13121 SVR4/EABI -maix AIX TOC object file
13122 SVR4/EABI -maix -mminimal-toc
13123 AIX minimal TOC translation unit
13124
13125 Name Reg. Set by entries contains:
13126 made by addrs? fp? sum?
13127
13128 AIX TOC 2 crt0 as Y option option
13129 AIX minimal TOC 30 prolog gcc Y Y option
13130 SVR4 SDATA 13 crt0 gcc N Y N
13131 SVR4 pic 30 prolog ld Y not yet N
13132 SVR4 PIC 30 prolog gcc Y option option
13133 EABI TOC 30 prolog gcc Y option option
13134
13135*/
13136
9ebbca7d
GK
13137/* Hash functions for the hash table. */
13138
13139static unsigned
a2369ed3 13140rs6000_hash_constant (rtx k)
9ebbca7d 13141{
46b33600
RH
13142 enum rtx_code code = GET_CODE (k);
13143 enum machine_mode mode = GET_MODE (k);
13144 unsigned result = (code << 3) ^ mode;
13145 const char *format;
13146 int flen, fidx;
9ebbca7d 13147
46b33600
RH
13148 format = GET_RTX_FORMAT (code);
13149 flen = strlen (format);
13150 fidx = 0;
9ebbca7d 13151
46b33600
RH
13152 switch (code)
13153 {
13154 case LABEL_REF:
13155 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
13156
13157 case CONST_DOUBLE:
13158 if (mode != VOIDmode)
13159 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
13160 flen = 2;
13161 break;
13162
13163 case CODE_LABEL:
13164 fidx = 3;
13165 break;
13166
13167 default:
13168 break;
13169 }
9ebbca7d
GK
13170
13171 for (; fidx < flen; fidx++)
13172 switch (format[fidx])
13173 {
13174 case 's':
13175 {
13176 unsigned i, len;
13177 const char *str = XSTR (k, fidx);
13178 len = strlen (str);
13179 result = result * 613 + len;
13180 for (i = 0; i < len; i++)
13181 result = result * 613 + (unsigned) str[i];
17167fd8
MM
13182 break;
13183 }
9ebbca7d
GK
13184 case 'u':
13185 case 'e':
13186 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
13187 break;
13188 case 'i':
13189 case 'n':
13190 result = result * 613 + (unsigned) XINT (k, fidx);
13191 break;
13192 case 'w':
13193 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
13194 result = result * 613 + (unsigned) XWINT (k, fidx);
13195 else
13196 {
13197 size_t i;
13198 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13199 result = result * 613 + (unsigned) (XWINT (k, fidx)
13200 >> CHAR_BIT * i);
13201 }
13202 break;
09501938
DE
13203 case '0':
13204 break;
9ebbca7d 13205 default:
a4f6c312 13206 abort ();
9ebbca7d 13207 }
46b33600 13208
9ebbca7d
GK
13209 return result;
13210}
13211
13212static unsigned
a2369ed3 13213toc_hash_function (const void *hash_entry)
9ebbca7d 13214{
a9098fd0
GK
13215 const struct toc_hash_struct *thc =
13216 (const struct toc_hash_struct *) hash_entry;
13217 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13218}
13219
13220/* Compare H1 and H2 for equivalence. */
13221
13222static int
a2369ed3 13223toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13224{
13225 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13226 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13227
a9098fd0
GK
13228 if (((const struct toc_hash_struct *) h1)->key_mode
13229 != ((const struct toc_hash_struct *) h2)->key_mode)
13230 return 0;
13231
5692c7bc 13232 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13233}
13234
28e510bd
MM
13235/* These are the names given by the C++ front-end to vtables, and
13236 vtable-like objects. Ideally, this logic should not be here;
13237 instead, there should be some programmatic way of inquiring as
13238 to whether or not an object is a vtable. */
13239
13240#define VTABLE_NAME_P(NAME) \
13241 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13242 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13243 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
13244 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13245
13246void
a2369ed3 13247rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13248{
13249 /* Currently C++ toc references to vtables can be emitted before it
13250 is decided whether the vtable is public or private. If this is
13251 the case, then the linker will eventually complain that there is
13252 a reference to an unknown section. Thus, for vtables only,
13253 we emit the TOC reference to reference the symbol and not the
13254 section. */
13255 const char *name = XSTR (x, 0);
54ee9799
DE
13256
13257 if (VTABLE_NAME_P (name))
13258 {
13259 RS6000_OUTPUT_BASENAME (file, name);
13260 }
13261 else
13262 assemble_name (file, name);
28e510bd
MM
13263}
13264
a4f6c312
SS
13265/* Output a TOC entry. We derive the entry name from what is being
13266 written. */
9878760c
RK
13267
13268void
a2369ed3 13269output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13270{
13271 char buf[256];
3cce094d 13272 const char *name = buf;
ec940faa 13273 const char *real_name;
9878760c
RK
13274 rtx base = x;
13275 int offset = 0;
13276
4697a36c
MM
13277 if (TARGET_NO_TOC)
13278 abort ();
13279
9ebbca7d
GK
13280 /* When the linker won't eliminate them, don't output duplicate
13281 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13282 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13283 CODE_LABELs. */
13284 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13285 {
13286 struct toc_hash_struct *h;
13287 void * * found;
13288
17211ab5 13289 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13290 time because GGC is not initialized at that point. */
17211ab5
GK
13291 if (toc_hash_table == NULL)
13292 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13293 toc_hash_eq, NULL);
13294
9ebbca7d
GK
13295 h = ggc_alloc (sizeof (*h));
13296 h->key = x;
a9098fd0 13297 h->key_mode = mode;
9ebbca7d
GK
13298 h->labelno = labelno;
13299
13300 found = htab_find_slot (toc_hash_table, h, 1);
13301 if (*found == NULL)
13302 *found = h;
13303 else /* This is indeed a duplicate.
13304 Set this label equal to that label. */
13305 {
13306 fputs ("\t.set ", file);
13307 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13308 fprintf (file, "%d,", labelno);
13309 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13310 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13311 found)->labelno));
13312 return;
13313 }
13314 }
13315
13316 /* If we're going to put a double constant in the TOC, make sure it's
13317 aligned properly when strict alignment is on. */
ff1720ed
RK
13318 if (GET_CODE (x) == CONST_DOUBLE
13319 && STRICT_ALIGNMENT
a9098fd0 13320 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13321 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13322 ASM_OUTPUT_ALIGN (file, 3);
13323 }
13324
4977bab6 13325 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13326
37c37a57
RK
13327 /* Handle FP constants specially. Note that if we have a minimal
13328 TOC, things we put here aren't actually in the TOC, so we can allow
13329 FP constants. */
fcce224d
DE
13330 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13331 {
13332 REAL_VALUE_TYPE rv;
13333 long k[4];
13334
13335 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13336 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13337
13338 if (TARGET_64BIT)
13339 {
13340 if (TARGET_MINIMAL_TOC)
13341 fputs (DOUBLE_INT_ASM_OP, file);
13342 else
13343 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13344 k[0] & 0xffffffff, k[1] & 0xffffffff,
13345 k[2] & 0xffffffff, k[3] & 0xffffffff);
13346 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13347 k[0] & 0xffffffff, k[1] & 0xffffffff,
13348 k[2] & 0xffffffff, k[3] & 0xffffffff);
13349 return;
13350 }
13351 else
13352 {
13353 if (TARGET_MINIMAL_TOC)
13354 fputs ("\t.long ", file);
13355 else
13356 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13357 k[0] & 0xffffffff, k[1] & 0xffffffff,
13358 k[2] & 0xffffffff, k[3] & 0xffffffff);
13359 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13360 k[0] & 0xffffffff, k[1] & 0xffffffff,
13361 k[2] & 0xffffffff, k[3] & 0xffffffff);
13362 return;
13363 }
13364 }
13365 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13366 {
042259f2
DE
13367 REAL_VALUE_TYPE rv;
13368 long k[2];
0adc764e 13369
042259f2
DE
13370 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13371 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13372
13ded975
DE
13373 if (TARGET_64BIT)
13374 {
13375 if (TARGET_MINIMAL_TOC)
2bfcf297 13376 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13377 else
2f0552b6
AM
13378 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13379 k[0] & 0xffffffff, k[1] & 0xffffffff);
13380 fprintf (file, "0x%lx%08lx\n",
13381 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13382 return;
13383 }
1875cc88 13384 else
13ded975
DE
13385 {
13386 if (TARGET_MINIMAL_TOC)
2bfcf297 13387 fputs ("\t.long ", file);
13ded975 13388 else
2f0552b6
AM
13389 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13390 k[0] & 0xffffffff, k[1] & 0xffffffff);
13391 fprintf (file, "0x%lx,0x%lx\n",
13392 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13393 return;
13394 }
9878760c 13395 }
a9098fd0 13396 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13397 {
042259f2
DE
13398 REAL_VALUE_TYPE rv;
13399 long l;
9878760c 13400
042259f2
DE
13401 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13402 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13403
31bfaa0b
DE
13404 if (TARGET_64BIT)
13405 {
13406 if (TARGET_MINIMAL_TOC)
2bfcf297 13407 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13408 else
2f0552b6
AM
13409 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13410 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13411 return;
13412 }
042259f2 13413 else
31bfaa0b
DE
13414 {
13415 if (TARGET_MINIMAL_TOC)
2bfcf297 13416 fputs ("\t.long ", file);
31bfaa0b 13417 else
2f0552b6
AM
13418 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13419 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13420 return;
13421 }
042259f2 13422 }
f176e826 13423 else if (GET_MODE (x) == VOIDmode
a9098fd0 13424 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13425 {
e2c953b6 13426 unsigned HOST_WIDE_INT low;
042259f2
DE
13427 HOST_WIDE_INT high;
13428
13429 if (GET_CODE (x) == CONST_DOUBLE)
13430 {
13431 low = CONST_DOUBLE_LOW (x);
13432 high = CONST_DOUBLE_HIGH (x);
13433 }
13434 else
13435#if HOST_BITS_PER_WIDE_INT == 32
13436 {
13437 low = INTVAL (x);
0858c623 13438 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13439 }
13440#else
13441 {
0858c623 13442 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13443 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13444 }
13445#endif
9878760c 13446
a9098fd0
GK
13447 /* TOC entries are always Pmode-sized, but since this
13448 is a bigendian machine then if we're putting smaller
13449 integer constants in the TOC we have to pad them.
13450 (This is still a win over putting the constants in
13451 a separate constant pool, because then we'd have
02a4ec28
FS
13452 to have both a TOC entry _and_ the actual constant.)
13453
13454 For a 32-bit target, CONST_INT values are loaded and shifted
13455 entirely within `low' and can be stored in one TOC entry. */
13456
13457 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13458 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13459
13460 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13461 {
13462#if HOST_BITS_PER_WIDE_INT == 32
13463 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13464 POINTER_SIZE, &low, &high, 0);
13465#else
13466 low |= high << 32;
13467 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13468 high = (HOST_WIDE_INT) low >> 32;
13469 low &= 0xffffffff;
13470#endif
13471 }
a9098fd0 13472
13ded975
DE
13473 if (TARGET_64BIT)
13474 {
13475 if (TARGET_MINIMAL_TOC)
2bfcf297 13476 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13477 else
2f0552b6
AM
13478 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13479 (long) high & 0xffffffff, (long) low & 0xffffffff);
13480 fprintf (file, "0x%lx%08lx\n",
13481 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13482 return;
13483 }
1875cc88 13484 else
13ded975 13485 {
02a4ec28
FS
13486 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13487 {
13488 if (TARGET_MINIMAL_TOC)
2bfcf297 13489 fputs ("\t.long ", file);
02a4ec28 13490 else
2bfcf297 13491 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13492 (long) high & 0xffffffff, (long) low & 0xffffffff);
13493 fprintf (file, "0x%lx,0x%lx\n",
13494 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13495 }
13ded975 13496 else
02a4ec28
FS
13497 {
13498 if (TARGET_MINIMAL_TOC)
2bfcf297 13499 fputs ("\t.long ", file);
02a4ec28 13500 else
2f0552b6
AM
13501 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13502 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13503 }
13ded975
DE
13504 return;
13505 }
9878760c
RK
13506 }
13507
13508 if (GET_CODE (x) == CONST)
13509 {
2bfcf297
DB
13510 if (GET_CODE (XEXP (x, 0)) != PLUS)
13511 abort ();
13512
9878760c
RK
13513 base = XEXP (XEXP (x, 0), 0);
13514 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13515 }
13516
13517 if (GET_CODE (base) == SYMBOL_REF)
13518 name = XSTR (base, 0);
13519 else if (GET_CODE (base) == LABEL_REF)
13520 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13521 else if (GET_CODE (base) == CODE_LABEL)
13522 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13523 else
13524 abort ();
13525
772c5265 13526 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13527 if (TARGET_MINIMAL_TOC)
2bfcf297 13528 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13529 else
13530 {
b6c9286a 13531 fprintf (file, "\t.tc %s", real_name);
9878760c 13532
1875cc88
JW
13533 if (offset < 0)
13534 fprintf (file, ".N%d", - offset);
13535 else if (offset)
13536 fprintf (file, ".P%d", offset);
9878760c 13537
19d2d16f 13538 fputs ("[TC],", file);
1875cc88 13539 }
581bc4de
MM
13540
13541 /* Currently C++ toc references to vtables can be emitted before it
13542 is decided whether the vtable is public or private. If this is
13543 the case, then the linker will eventually complain that there is
13544 a TOC reference to an unknown section. Thus, for vtables only,
13545 we emit the TOC reference to reference the symbol and not the
13546 section. */
28e510bd 13547 if (VTABLE_NAME_P (name))
581bc4de 13548 {
54ee9799 13549 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13550 if (offset < 0)
13551 fprintf (file, "%d", offset);
13552 else if (offset > 0)
13553 fprintf (file, "+%d", offset);
13554 }
13555 else
13556 output_addr_const (file, x);
19d2d16f 13557 putc ('\n', file);
9878760c
RK
13558}
13559\f
13560/* Output an assembler pseudo-op to write an ASCII string of N characters
13561 starting at P to FILE.
13562
13563 On the RS/6000, we have to do this using the .byte operation and
13564 write out special characters outside the quoted string.
13565 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13566 so we must artificially break them up early. */
9878760c
RK
13567
13568void
a2369ed3 13569output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13570{
13571 char c;
13572 int i, count_string;
d330fd93
KG
13573 const char *for_string = "\t.byte \"";
13574 const char *for_decimal = "\t.byte ";
13575 const char *to_close = NULL;
9878760c
RK
13576
13577 count_string = 0;
13578 for (i = 0; i < n; i++)
13579 {
13580 c = *p++;
13581 if (c >= ' ' && c < 0177)
13582 {
13583 if (for_string)
13584 fputs (for_string, file);
13585 putc (c, file);
13586
13587 /* Write two quotes to get one. */
13588 if (c == '"')
13589 {
13590 putc (c, file);
13591 ++count_string;
13592 }
13593
13594 for_string = NULL;
13595 for_decimal = "\"\n\t.byte ";
13596 to_close = "\"\n";
13597 ++count_string;
13598
13599 if (count_string >= 512)
13600 {
13601 fputs (to_close, file);
13602
13603 for_string = "\t.byte \"";
13604 for_decimal = "\t.byte ";
13605 to_close = NULL;
13606 count_string = 0;
13607 }
13608 }
13609 else
13610 {
13611 if (for_decimal)
13612 fputs (for_decimal, file);
13613 fprintf (file, "%d", c);
13614
13615 for_string = "\n\t.byte \"";
13616 for_decimal = ", ";
13617 to_close = "\n";
13618 count_string = 0;
13619 }
13620 }
13621
13622 /* Now close the string if we have written one. Then end the line. */
13623 if (to_close)
9ebbca7d 13624 fputs (to_close, file);
9878760c
RK
13625}
13626\f
13627/* Generate a unique section name for FILENAME for a section type
13628 represented by SECTION_DESC. Output goes into BUF.
13629
13630 SECTION_DESC can be any string, as long as it is different for each
13631 possible section type.
13632
13633 We name the section in the same manner as xlc. The name begins with an
13634 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13635 names) with the last period replaced by the string SECTION_DESC. If
13636 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13637 the name. */
9878760c
RK
13638
13639void
a2369ed3
DJ
13640rs6000_gen_section_name (char **buf, const char *filename,
13641 const char *section_desc)
9878760c 13642{
9ebbca7d 13643 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13644 char *p;
13645 int len;
9878760c
RK
13646
13647 after_last_slash = filename;
13648 for (q = filename; *q; q++)
11e5fe42
RK
13649 {
13650 if (*q == '/')
13651 after_last_slash = q + 1;
13652 else if (*q == '.')
13653 last_period = q;
13654 }
9878760c 13655
11e5fe42 13656 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13657 *buf = (char *) xmalloc (len);
9878760c
RK
13658
13659 p = *buf;
13660 *p++ = '_';
13661
13662 for (q = after_last_slash; *q; q++)
13663 {
11e5fe42 13664 if (q == last_period)
9878760c
RK
13665 {
13666 strcpy (p, section_desc);
13667 p += strlen (section_desc);
e3981aab 13668 break;
9878760c
RK
13669 }
13670
e9a780ec 13671 else if (ISALNUM (*q))
9878760c
RK
13672 *p++ = *q;
13673 }
13674
11e5fe42 13675 if (last_period == 0)
9878760c
RK
13676 strcpy (p, section_desc);
13677 else
13678 *p = '\0';
13679}
e165f3f0 13680\f
a4f6c312 13681/* Emit profile function. */
411707f4 13682
411707f4 13683void
a2369ed3 13684output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13685{
ffcfcb5f
AM
13686 if (TARGET_PROFILE_KERNEL)
13687 return;
13688
8480e480
CC
13689 if (DEFAULT_ABI == ABI_AIX)
13690 {
9739c90c
JJ
13691#ifndef NO_PROFILE_COUNTERS
13692# define NO_PROFILE_COUNTERS 0
13693#endif
13694 if (NO_PROFILE_COUNTERS)
13695 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13696 else
13697 {
13698 char buf[30];
13699 const char *label_name;
13700 rtx fun;
411707f4 13701
9739c90c
JJ
13702 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13703 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13704 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13705
9739c90c
JJ
13706 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13707 fun, Pmode);
13708 }
8480e480 13709 }
ee890fe2
SS
13710 else if (DEFAULT_ABI == ABI_DARWIN)
13711 {
d5fa86ba 13712 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13713 int caller_addr_regno = LINK_REGISTER_REGNUM;
13714
13715 /* Be conservative and always set this, at least for now. */
13716 current_function_uses_pic_offset_table = 1;
13717
13718#if TARGET_MACHO
13719 /* For PIC code, set up a stub and collect the caller's address
13720 from r0, which is where the prologue puts it. */
ab82a49f 13721 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13722 {
13723 mcount_name = machopic_stub_name (mcount_name);
13724 if (current_function_uses_pic_offset_table)
13725 caller_addr_regno = 0;
13726 }
13727#endif
13728 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13729 0, VOIDmode, 1,
13730 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13731 }
411707f4
CC
13732}
13733
a4f6c312 13734/* Write function profiler code. */
e165f3f0
RK
13735
13736void
a2369ed3 13737output_function_profiler (FILE *file, int labelno)
e165f3f0 13738{
3daf36a4 13739 char buf[100];
09eeeacb 13740 int save_lr = 8;
e165f3f0 13741
38c1f2d7 13742 switch (DEFAULT_ABI)
3daf36a4 13743 {
38c1f2d7
MM
13744 default:
13745 abort ();
13746
13747 case ABI_V4:
09eeeacb 13748 save_lr = 4;
09eeeacb
AM
13749 if (!TARGET_32BIT)
13750 {
13751 warning ("no profiling of 64-bit code for this ABI");
13752 return;
13753 }
ffcfcb5f 13754 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13755 fprintf (file, "\tmflr %s\n", reg_names[0]);
13756 if (flag_pic == 1)
13757 {
dfdfa60f 13758 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13759 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13760 reg_names[0], save_lr, reg_names[1]);
17167fd8 13761 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13762 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13763 assemble_name (file, buf);
17167fd8 13764 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13765 }
9ebbca7d 13766 else if (flag_pic > 1)
38c1f2d7 13767 {
09eeeacb
AM
13768 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13769 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13770 /* Now, we need to get the address of the label. */
13771 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13772 assemble_name (file, buf);
9ebbca7d
GK
13773 fputs ("-.\n1:", file);
13774 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13775 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13776 reg_names[0], reg_names[11]);
13777 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13778 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13779 }
38c1f2d7
MM
13780 else
13781 {
17167fd8 13782 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13783 assemble_name (file, buf);
dfdfa60f 13784 fputs ("@ha\n", file);
09eeeacb
AM
13785 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13786 reg_names[0], save_lr, reg_names[1]);
a260abc9 13787 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13788 assemble_name (file, buf);
17167fd8 13789 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13790 }
13791
50d440bc 13792 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
13793 fprintf (file, "\tbl %s%s\n",
13794 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
13795 break;
13796
13797 case ABI_AIX:
ee890fe2 13798 case ABI_DARWIN:
ffcfcb5f
AM
13799 if (!TARGET_PROFILE_KERNEL)
13800 {
a3c9585f 13801 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
13802 }
13803 else
13804 {
13805 if (TARGET_32BIT)
13806 abort ();
13807
13808 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13809 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13810
13811 if (current_function_needs_context)
13812 {
13813 asm_fprintf (file, "\tstd %s,24(%s)\n",
13814 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13815 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13816 asm_fprintf (file, "\tld %s,24(%s)\n",
13817 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13818 }
13819 else
13820 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13821 }
38c1f2d7
MM
13822 break;
13823 }
e165f3f0 13824}
a251ffd0 13825
b54cf83a
DE
13826\f
13827static int
863d938c 13828rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13829{
13830 return 1;
13831}
13832
b54cf83a
DE
13833/* Power4 load update and store update instructions are cracked into a
13834 load or store and an integer insn which are executed in the same cycle.
13835 Branches have their own dispatch slot which does not count against the
13836 GCC issue rate, but it changes the program flow so there are no other
13837 instructions to issue in this cycle. */
13838
13839static int
a2369ed3
DJ
13840rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13841 int verbose ATTRIBUTE_UNUSED,
13842 rtx insn, int more)
b54cf83a
DE
13843{
13844 if (GET_CODE (PATTERN (insn)) == USE
13845 || GET_CODE (PATTERN (insn)) == CLOBBER)
13846 return more;
13847
13848 if (rs6000_cpu == PROCESSOR_POWER4)
13849 {
cbe26ab8
DN
13850 if (is_microcoded_insn (insn))
13851 return 0;
13852 else if (is_cracked_insn (insn))
13853 return more > 2 ? more - 2 : 0;
b54cf83a 13854 }
165b263e
DE
13855
13856 return more - 1;
b54cf83a
DE
13857}
13858
a251ffd0
TG
13859/* Adjust the cost of a scheduling dependency. Return the new cost of
13860 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13861
c237e94a 13862static int
a2369ed3
DJ
13863rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13864 int cost)
a251ffd0
TG
13865{
13866 if (! recog_memoized (insn))
13867 return 0;
13868
13869 if (REG_NOTE_KIND (link) != 0)
13870 return 0;
13871
13872 if (REG_NOTE_KIND (link) == 0)
13873 {
ed947a96
DJ
13874 /* Data dependency; DEP_INSN writes a register that INSN reads
13875 some cycles later. */
13876 switch (get_attr_type (insn))
13877 {
13878 case TYPE_JMPREG:
309323c2 13879 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13880 a mtctr and bctr (and mtlr and br/blr). The first
13881 scheduling pass will not know about this latency since
13882 the mtctr instruction, which has the latency associated
13883 to it, will be generated by reload. */
309323c2 13884 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13885 case TYPE_BRANCH:
13886 /* Leave some extra cycles between a compare and its
13887 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13888 if ((rs6000_cpu_attr == CPU_PPC603
13889 || rs6000_cpu_attr == CPU_PPC604
13890 || rs6000_cpu_attr == CPU_PPC604E
13891 || rs6000_cpu_attr == CPU_PPC620
13892 || rs6000_cpu_attr == CPU_PPC630
13893 || rs6000_cpu_attr == CPU_PPC750
13894 || rs6000_cpu_attr == CPU_PPC7400
13895 || rs6000_cpu_attr == CPU_PPC7450
13896 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13897 && recog_memoized (dep_insn)
13898 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13899 && (get_attr_type (dep_insn) == TYPE_CMP
13900 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13901 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13902 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13903 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13904 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13905 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13906 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13907 return cost + 2;
13908 default:
13909 break;
13910 }
a251ffd0
TG
13911 /* Fall out to return default cost. */
13912 }
13913
13914 return cost;
13915}
b6c9286a 13916
cbe26ab8 13917/* The function returns a true if INSN is microcoded.
839a4992 13918 Return false otherwise. */
cbe26ab8
DN
13919
13920static bool
13921is_microcoded_insn (rtx insn)
13922{
13923 if (!insn || !INSN_P (insn)
13924 || GET_CODE (PATTERN (insn)) == USE
13925 || GET_CODE (PATTERN (insn)) == CLOBBER)
13926 return false;
13927
13928 if (rs6000_cpu == PROCESSOR_POWER4)
13929 {
13930 enum attr_type type = get_attr_type (insn);
13931 if (type == TYPE_LOAD_EXT_U
13932 || type == TYPE_LOAD_EXT_UX
13933 || type == TYPE_LOAD_UX
13934 || type == TYPE_STORE_UX
13935 || type == TYPE_MFCR)
13936 return true;
13937 }
13938
13939 return false;
13940}
13941
5c425df5 13942/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
13943 as the first insn in a dispatch group ("dispatch-slot restricted").
13944 In this case, the returned value indicates how many dispatch slots
13945 the insn occupies (at the beginning of the group).
79ae11c4
DN
13946 Return 0 otherwise. */
13947
cbe26ab8 13948static int
79ae11c4
DN
13949is_dispatch_slot_restricted (rtx insn)
13950{
13951 enum attr_type type;
13952
13953 if (rs6000_cpu != PROCESSOR_POWER4)
13954 return 0;
13955
13956 if (!insn
13957 || insn == NULL_RTX
13958 || GET_CODE (insn) == NOTE
13959 || GET_CODE (PATTERN (insn)) == USE
13960 || GET_CODE (PATTERN (insn)) == CLOBBER)
13961 return 0;
13962
13963 type = get_attr_type (insn);
13964
13965 switch (type){
13966 case TYPE_MFCR:
13967 case TYPE_MFCRF:
13968 case TYPE_MTCR:
13969 case TYPE_DELAYED_CR:
13970 case TYPE_CR_LOGICAL:
13971 case TYPE_MTJMPR:
13972 case TYPE_MFJMPR:
13973 return 1;
13974 case TYPE_IDIV:
13975 case TYPE_LDIV:
13976 return 2;
13977 default:
13978 return 0;
13979 }
13980}
13981
cbe26ab8
DN
13982/* The function returns true if INSN is cracked into 2 instructions
13983 by the processor (and therefore occupies 2 issue slots). */
13984
13985static bool
13986is_cracked_insn (rtx insn)
13987{
13988 if (!insn || !INSN_P (insn)
13989 || GET_CODE (PATTERN (insn)) == USE
13990 || GET_CODE (PATTERN (insn)) == CLOBBER)
13991 return false;
13992
13993 if (rs6000_cpu == PROCESSOR_POWER4)
13994 {
13995 enum attr_type type = get_attr_type (insn);
13996 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
13997 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
13998 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
13999 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
14000 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
14001 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
14002 || type == TYPE_IDIV || type == TYPE_LDIV
14003 || type == TYPE_INSERT_WORD)
14004 return true;
14005 }
14006
14007 return false;
14008}
14009
14010/* The function returns true if INSN can be issued only from
a3c9585f 14011 the branch slot. */
cbe26ab8
DN
14012
14013static bool
14014is_branch_slot_insn (rtx insn)
14015{
14016 if (!insn || !INSN_P (insn)
14017 || GET_CODE (PATTERN (insn)) == USE
14018 || GET_CODE (PATTERN (insn)) == CLOBBER)
14019 return false;
14020
14021 if (rs6000_cpu == PROCESSOR_POWER4)
14022 {
14023 enum attr_type type = get_attr_type (insn);
14024 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
14025 return true;
14026 return false;
14027 }
14028
14029 return false;
14030}
79ae11c4 14031
a4f6c312 14032/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
14033 priority INSN_PRIORITY (INSN). Increase the priority to execute the
14034 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
14035 define this macro if you do not need to adjust the scheduling
14036 priorities of insns. */
bef84347 14037
c237e94a 14038static int
a2369ed3 14039rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 14040{
a4f6c312
SS
14041 /* On machines (like the 750) which have asymmetric integer units,
14042 where one integer unit can do multiply and divides and the other
14043 can't, reduce the priority of multiply/divide so it is scheduled
14044 before other integer operations. */
bef84347
VM
14045
14046#if 0
2c3c49de 14047 if (! INSN_P (insn))
bef84347
VM
14048 return priority;
14049
14050 if (GET_CODE (PATTERN (insn)) == USE)
14051 return priority;
14052
14053 switch (rs6000_cpu_attr) {
14054 case CPU_PPC750:
14055 switch (get_attr_type (insn))
14056 {
14057 default:
14058 break;
14059
14060 case TYPE_IMUL:
14061 case TYPE_IDIV:
3cb999d8
DE
14062 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
14063 priority, priority);
bef84347
VM
14064 if (priority >= 0 && priority < 0x01000000)
14065 priority >>= 3;
14066 break;
14067 }
14068 }
14069#endif
14070
79ae11c4
DN
14071 if (is_dispatch_slot_restricted (insn)
14072 && reload_completed
14073 && current_sched_info->sched_max_insns_priority
14074 && rs6000_sched_restricted_insns_priority)
14075 {
14076
14077 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
14078 if (rs6000_sched_restricted_insns_priority == 1)
14079 /* Attach highest priority to insn. This means that in
14080 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
14081 precede 'priority' (critical path) considerations. */
14082 return current_sched_info->sched_max_insns_priority;
14083 else if (rs6000_sched_restricted_insns_priority == 2)
14084 /* Increase priority of insn by a minimal amount. This means that in
14085 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
14086 precede dispatch-slot restriction considerations. */
14087 return (priority + 1);
14088 }
14089
bef84347
VM
14090 return priority;
14091}
14092
a4f6c312
SS
14093/* Return how many instructions the machine can issue per cycle. */
14094
c237e94a 14095static int
863d938c 14096rs6000_issue_rate (void)
b6c9286a 14097{
3317bab1
DE
14098 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
14099 if (!reload_completed)
14100 return 1;
14101
b6c9286a 14102 switch (rs6000_cpu_attr) {
3cb999d8
DE
14103 case CPU_RIOS1: /* ? */
14104 case CPU_RS64A:
14105 case CPU_PPC601: /* ? */
ed947a96 14106 case CPU_PPC7450:
3cb999d8 14107 return 3;
b54cf83a 14108 case CPU_PPC440:
b6c9286a 14109 case CPU_PPC603:
bef84347 14110 case CPU_PPC750:
ed947a96 14111 case CPU_PPC7400:
be12c2b0 14112 case CPU_PPC8540:
bef84347 14113 return 2;
3cb999d8 14114 case CPU_RIOS2:
b6c9286a 14115 case CPU_PPC604:
19684119 14116 case CPU_PPC604E:
b6c9286a 14117 case CPU_PPC620:
3cb999d8 14118 case CPU_PPC630:
b6c9286a 14119 return 4;
cbe26ab8
DN
14120 case CPU_POWER4:
14121 return 5;
b6c9286a
MM
14122 default:
14123 return 1;
14124 }
14125}
14126
be12c2b0
VM
14127/* Return how many instructions to look ahead for better insn
14128 scheduling. */
14129
14130static int
863d938c 14131rs6000_use_sched_lookahead (void)
be12c2b0
VM
14132{
14133 if (rs6000_cpu_attr == CPU_PPC8540)
14134 return 4;
14135 return 0;
14136}
14137
569fa502
DN
14138/* Determine is PAT refers to memory. */
14139
14140static bool
14141is_mem_ref (rtx pat)
14142{
14143 const char * fmt;
14144 int i, j;
14145 bool ret = false;
14146
14147 if (GET_CODE (pat) == MEM)
14148 return true;
14149
14150 /* Recursively process the pattern. */
14151 fmt = GET_RTX_FORMAT (GET_CODE (pat));
14152
14153 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
14154 {
14155 if (fmt[i] == 'e')
14156 ret |= is_mem_ref (XEXP (pat, i));
14157 else if (fmt[i] == 'E')
14158 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
14159 ret |= is_mem_ref (XVECEXP (pat, i, j));
14160 }
14161
14162 return ret;
14163}
14164
14165/* Determine if PAT is a PATTERN of a load insn. */
14166
14167static bool
14168is_load_insn1 (rtx pat)
14169{
14170 if (!pat || pat == NULL_RTX)
14171 return false;
14172
14173 if (GET_CODE (pat) == SET)
14174 return is_mem_ref (SET_SRC (pat));
14175
14176 if (GET_CODE (pat) == PARALLEL)
14177 {
14178 int i;
14179
14180 for (i = 0; i < XVECLEN (pat, 0); i++)
14181 if (is_load_insn1 (XVECEXP (pat, 0, i)))
14182 return true;
14183 }
14184
14185 return false;
14186}
14187
14188/* Determine if INSN loads from memory. */
14189
14190static bool
14191is_load_insn (rtx insn)
14192{
14193 if (!insn || !INSN_P (insn))
14194 return false;
14195
14196 if (GET_CODE (insn) == CALL_INSN)
14197 return false;
14198
14199 return is_load_insn1 (PATTERN (insn));
14200}
14201
14202/* Determine if PAT is a PATTERN of a store insn. */
14203
14204static bool
14205is_store_insn1 (rtx pat)
14206{
14207 if (!pat || pat == NULL_RTX)
14208 return false;
14209
14210 if (GET_CODE (pat) == SET)
14211 return is_mem_ref (SET_DEST (pat));
14212
14213 if (GET_CODE (pat) == PARALLEL)
14214 {
14215 int i;
14216
14217 for (i = 0; i < XVECLEN (pat, 0); i++)
14218 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14219 return true;
14220 }
14221
14222 return false;
14223}
14224
14225/* Determine if INSN stores to memory. */
14226
14227static bool
14228is_store_insn (rtx insn)
14229{
14230 if (!insn || !INSN_P (insn))
14231 return false;
14232
14233 return is_store_insn1 (PATTERN (insn));
14234}
14235
14236/* Returns whether the dependence between INSN and NEXT is considered
14237 costly by the given target. */
14238
14239static bool
14240rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14241{
14242 /* If the flag is not enbled - no dependence is considered costly;
14243 allow all dependent insns in the same group.
14244 This is the most aggressive option. */
14245 if (rs6000_sched_costly_dep == no_dep_costly)
14246 return false;
14247
14248 /* If the flag is set to 1 - a dependence is always considered costly;
14249 do not allow dependent instructions in the same group.
14250 This is the most conservative option. */
14251 if (rs6000_sched_costly_dep == all_deps_costly)
14252 return true;
14253
14254 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14255 && is_load_insn (next)
14256 && is_store_insn (insn))
14257 /* Prevent load after store in the same group. */
14258 return true;
14259
14260 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14261 && is_load_insn (next)
14262 && is_store_insn (insn)
14263 && (!link || (int) REG_NOTE_KIND (link) == 0))
14264 /* Prevent load after store in the same group if it is a true dependence. */
14265 return true;
14266
14267 /* The flag is set to X; dependences with latency >= X are considered costly,
14268 and will not be scheduled in the same group. */
14269 if (rs6000_sched_costly_dep <= max_dep_latency
14270 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14271 return true;
14272
14273 return false;
14274}
14275
cbe26ab8
DN
14276/* Return the next insn after INSN that is found before TAIL is reached,
14277 skipping any "non-active" insns - insns that will not actually occupy
14278 an issue slot. Return NULL_RTX if such an insn is not found. */
14279
14280static rtx
14281get_next_active_insn (rtx insn, rtx tail)
14282{
14283 rtx next_insn;
14284
14285 if (!insn || insn == tail)
14286 return NULL_RTX;
14287
14288 next_insn = NEXT_INSN (insn);
14289
14290 while (next_insn
14291 && next_insn != tail
14292 && (GET_CODE(next_insn) == NOTE
14293 || GET_CODE (PATTERN (next_insn)) == USE
14294 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14295 {
14296 next_insn = NEXT_INSN (next_insn);
14297 }
14298
14299 if (!next_insn || next_insn == tail)
14300 return NULL_RTX;
14301
14302 return next_insn;
14303}
14304
839a4992 14305/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14306 of group WHICH_GROUP.
14307
14308 If WHICH_GROUP == current_group, this function will return true if INSN
14309 causes the termination of the current group (i.e, the dispatch group to
14310 which INSN belongs). This means that INSN will be the last insn in the
14311 group it belongs to.
14312
14313 If WHICH_GROUP == previous_group, this function will return true if INSN
14314 causes the termination of the previous group (i.e, the dispatch group that
14315 precedes the group to which INSN belongs). This means that INSN will be
14316 the first insn in the group it belongs to). */
14317
14318static bool
14319insn_terminates_group_p (rtx insn, enum group_termination which_group)
14320{
14321 enum attr_type type;
14322
14323 if (! insn)
14324 return false;
569fa502 14325
cbe26ab8
DN
14326 type = get_attr_type (insn);
14327
14328 if (is_microcoded_insn (insn))
14329 return true;
14330
14331 if (which_group == current_group)
14332 {
14333 if (is_branch_slot_insn (insn))
14334 return true;
14335 return false;
14336 }
14337 else if (which_group == previous_group)
14338 {
14339 if (is_dispatch_slot_restricted (insn))
14340 return true;
14341 return false;
14342 }
14343
14344 return false;
14345}
14346
839a4992 14347/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14348 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14349
14350static bool
14351is_costly_group (rtx *group_insns, rtx next_insn)
14352{
14353 int i;
14354 rtx link;
14355 int cost;
14356 int issue_rate = rs6000_issue_rate ();
14357
14358 for (i = 0; i < issue_rate; i++)
14359 {
14360 rtx insn = group_insns[i];
14361 if (!insn)
14362 continue;
14363 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14364 {
14365 rtx next = XEXP (link, 0);
14366 if (next == next_insn)
14367 {
14368 cost = insn_cost (insn, link, next_insn);
14369 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14370 return true;
14371 }
14372 }
14373 }
14374
14375 return false;
14376}
14377
14378/* Utility of the function redefine_groups.
14379 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14380 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14381 to keep it "far" (in a separate group) from GROUP_INSNS, following
14382 one of the following schemes, depending on the value of the flag
14383 -minsert_sched_nops = X:
14384 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14385 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14386 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14387 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14388 insertion (has a group just ended, how many vacant issue slots remain in the
14389 last group, and how many dispatch groups were encountered so far). */
14390
14391static int
14392force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14393 bool *group_end, int can_issue_more, int *group_count)
14394{
14395 rtx nop;
14396 bool force;
14397 int issue_rate = rs6000_issue_rate ();
14398 bool end = *group_end;
14399 int i;
14400
14401 if (next_insn == NULL_RTX)
14402 return can_issue_more;
14403
14404 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14405 return can_issue_more;
14406
14407 force = is_costly_group (group_insns, next_insn);
14408 if (!force)
14409 return can_issue_more;
14410
14411 if (sched_verbose > 6)
14412 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14413 *group_count ,can_issue_more);
14414
14415 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14416 {
14417 if (*group_end)
14418 can_issue_more = 0;
14419
14420 /* Since only a branch can be issued in the last issue_slot, it is
14421 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14422 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14423 in this case the last nop will start a new group and the branch will be
14424 forced to the new group. */
14425 if (can_issue_more && !is_branch_slot_insn (next_insn))
14426 can_issue_more--;
14427
14428 while (can_issue_more > 0)
14429 {
14430 nop = gen_nop();
14431 emit_insn_before (nop, next_insn);
14432 can_issue_more--;
14433 }
14434
14435 *group_end = true;
14436 return 0;
14437 }
14438
14439 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14440 {
14441 int n_nops = rs6000_sched_insert_nops;
14442
14443 /* Nops can't be issued from the branch slot, so the effective
14444 issue_rate for nops is 'issue_rate - 1'. */
14445 if (can_issue_more == 0)
14446 can_issue_more = issue_rate;
14447 can_issue_more--;
14448 if (can_issue_more == 0)
14449 {
14450 can_issue_more = issue_rate - 1;
14451 (*group_count)++;
14452 end = true;
14453 for (i = 0; i < issue_rate; i++)
14454 {
14455 group_insns[i] = 0;
14456 }
14457 }
14458
14459 while (n_nops > 0)
14460 {
14461 nop = gen_nop ();
14462 emit_insn_before (nop, next_insn);
14463 if (can_issue_more == issue_rate - 1) /* new group begins */
14464 end = false;
14465 can_issue_more--;
14466 if (can_issue_more == 0)
14467 {
14468 can_issue_more = issue_rate - 1;
14469 (*group_count)++;
14470 end = true;
14471 for (i = 0; i < issue_rate; i++)
14472 {
14473 group_insns[i] = 0;
14474 }
14475 }
14476 n_nops--;
14477 }
14478
14479 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14480 can_issue_more++;
14481
14482 *group_end = /* Is next_insn going to start a new group? */
14483 (end
14484 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14485 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14486 || (can_issue_more < issue_rate &&
14487 insn_terminates_group_p (next_insn, previous_group)));
14488 if (*group_end && end)
14489 (*group_count)--;
14490
14491 if (sched_verbose > 6)
14492 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14493 *group_count, can_issue_more);
14494 return can_issue_more;
14495 }
14496
14497 return can_issue_more;
14498}
14499
14500/* This function tries to synch the dispatch groups that the compiler "sees"
14501 with the dispatch groups that the processor dispatcher is expected to
14502 form in practice. It tries to achieve this synchronization by forcing the
14503 estimated processor grouping on the compiler (as opposed to the function
14504 'pad_goups' which tries to force the scheduler's grouping on the processor).
14505
14506 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14507 examines the (estimated) dispatch groups that will be formed by the processor
14508 dispatcher. It marks these group boundaries to reflect the estimated
14509 processor grouping, overriding the grouping that the scheduler had marked.
14510 Depending on the value of the flag '-minsert-sched-nops' this function can
14511 force certain insns into separate groups or force a certain distance between
14512 them by inserting nops, for example, if there exists a "costly dependence"
14513 between the insns.
14514
14515 The function estimates the group boundaries that the processor will form as
14516 folllows: It keeps track of how many vacant issue slots are available after
14517 each insn. A subsequent insn will start a new group if one of the following
14518 4 cases applies:
14519 - no more vacant issue slots remain in the current dispatch group.
14520 - only the last issue slot, which is the branch slot, is vacant, but the next
14521 insn is not a branch.
14522 - only the last 2 or less issue slots, including the branch slot, are vacant,
14523 which means that a cracked insn (which occupies two issue slots) can't be
14524 issued in this group.
14525 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14526 start a new group. */
14527
14528static int
14529redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14530{
14531 rtx insn, next_insn;
14532 int issue_rate;
14533 int can_issue_more;
14534 int slot, i;
14535 bool group_end;
14536 int group_count = 0;
14537 rtx *group_insns;
14538
14539 /* Initialize. */
14540 issue_rate = rs6000_issue_rate ();
14541 group_insns = alloca (issue_rate * sizeof (rtx));
14542 for (i = 0; i < issue_rate; i++)
14543 {
14544 group_insns[i] = 0;
14545 }
14546 can_issue_more = issue_rate;
14547 slot = 0;
14548 insn = get_next_active_insn (prev_head_insn, tail);
14549 group_end = false;
14550
14551 while (insn != NULL_RTX)
14552 {
14553 slot = (issue_rate - can_issue_more);
14554 group_insns[slot] = insn;
14555 can_issue_more =
14556 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14557 if (insn_terminates_group_p (insn, current_group))
14558 can_issue_more = 0;
14559
14560 next_insn = get_next_active_insn (insn, tail);
14561 if (next_insn == NULL_RTX)
14562 return group_count + 1;
14563
14564 group_end = /* Is next_insn going to start a new group? */
14565 (can_issue_more == 0
14566 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14567 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14568 || (can_issue_more < issue_rate &&
14569 insn_terminates_group_p (next_insn, previous_group)));
14570
14571 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14572 next_insn, &group_end, can_issue_more, &group_count);
14573
14574 if (group_end)
14575 {
14576 group_count++;
14577 can_issue_more = 0;
14578 for (i = 0; i < issue_rate; i++)
14579 {
14580 group_insns[i] = 0;
14581 }
14582 }
14583
14584 if (GET_MODE (next_insn) == TImode && can_issue_more)
14585 PUT_MODE(next_insn, VOIDmode);
14586 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14587 PUT_MODE (next_insn, TImode);
14588
14589 insn = next_insn;
14590 if (can_issue_more == 0)
14591 can_issue_more = issue_rate;
14592 } /* while */
14593
14594 return group_count;
14595}
14596
14597/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14598 dispatch group boundaries that the scheduler had marked. Pad with nops
14599 any dispatch groups which have vacant issue slots, in order to force the
14600 scheduler's grouping on the processor dispatcher. The function
14601 returns the number of dispatch groups found. */
14602
14603static int
14604pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14605{
14606 rtx insn, next_insn;
14607 rtx nop;
14608 int issue_rate;
14609 int can_issue_more;
14610 int group_end;
14611 int group_count = 0;
14612
14613 /* Initialize issue_rate. */
14614 issue_rate = rs6000_issue_rate ();
14615 can_issue_more = issue_rate;
14616
14617 insn = get_next_active_insn (prev_head_insn, tail);
14618 next_insn = get_next_active_insn (insn, tail);
14619
14620 while (insn != NULL_RTX)
14621 {
14622 can_issue_more =
14623 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14624
14625 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14626
14627 if (next_insn == NULL_RTX)
14628 break;
14629
14630 if (group_end)
14631 {
14632 /* If the scheduler had marked group termination at this location
14633 (between insn and next_indn), and neither insn nor next_insn will
14634 force group termination, pad the group with nops to force group
14635 termination. */
14636 if (can_issue_more
14637 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14638 && !insn_terminates_group_p (insn, current_group)
14639 && !insn_terminates_group_p (next_insn, previous_group))
14640 {
14641 if (!is_branch_slot_insn(next_insn))
14642 can_issue_more--;
14643
14644 while (can_issue_more)
14645 {
14646 nop = gen_nop ();
14647 emit_insn_before (nop, next_insn);
14648 can_issue_more--;
14649 }
14650 }
14651
14652 can_issue_more = issue_rate;
14653 group_count++;
14654 }
14655
14656 insn = next_insn;
14657 next_insn = get_next_active_insn (insn, tail);
14658 }
14659
14660 return group_count;
14661}
14662
14663/* The following function is called at the end of scheduling BB.
14664 After reload, it inserts nops at insn group bundling. */
14665
14666static void
38f391a5 14667rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14668{
14669 int n_groups;
14670
14671 if (sched_verbose)
14672 fprintf (dump, "=== Finishing schedule.\n");
14673
14674 if (reload_completed && rs6000_cpu == PROCESSOR_POWER4)
14675 {
14676 if (rs6000_sched_insert_nops == sched_finish_none)
14677 return;
14678
14679 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14680 n_groups = pad_groups (dump, sched_verbose,
14681 current_sched_info->prev_head,
14682 current_sched_info->next_tail);
14683 else
14684 n_groups = redefine_groups (dump, sched_verbose,
14685 current_sched_info->prev_head,
14686 current_sched_info->next_tail);
14687
14688 if (sched_verbose >= 6)
14689 {
14690 fprintf (dump, "ngroups = %d\n", n_groups);
14691 print_rtl (dump, current_sched_info->prev_head);
14692 fprintf (dump, "Done finish_sched\n");
14693 }
14694 }
14695}
b6c9286a 14696\f
b6c9286a
MM
14697/* Length in units of the trampoline for entering a nested function. */
14698
14699int
863d938c 14700rs6000_trampoline_size (void)
b6c9286a
MM
14701{
14702 int ret = 0;
14703
14704 switch (DEFAULT_ABI)
14705 {
14706 default:
14707 abort ();
14708
14709 case ABI_AIX:
8f802bfb 14710 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
14711 break;
14712
4dabc42d 14713 case ABI_DARWIN:
b6c9286a 14714 case ABI_V4:
03a7e1a5 14715 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 14716 break;
b6c9286a
MM
14717 }
14718
14719 return ret;
14720}
14721
14722/* Emit RTL insns to initialize the variable parts of a trampoline.
14723 FNADDR is an RTX for the address of the function's pure code.
14724 CXT is an RTX for the static chain value for the function. */
14725
14726void
a2369ed3 14727rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 14728{
ac2a93a1 14729 enum machine_mode pmode = Pmode;
8bd04c56
MM
14730 int regsize = (TARGET_32BIT) ? 4 : 8;
14731 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
14732
14733 switch (DEFAULT_ABI)
14734 {
14735 default:
14736 abort ();
14737
8bd04c56 14738/* Macros to shorten the code expansions below. */
39403d82 14739#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
14740#define MEM_PLUS(addr,offset) \
14741 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 14742
b6c9286a
MM
14743 /* Under AIX, just build the 3 word function descriptor */
14744 case ABI_AIX:
8bd04c56
MM
14745 {
14746 rtx fn_reg = gen_reg_rtx (pmode);
14747 rtx toc_reg = gen_reg_rtx (pmode);
14748 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 14749 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
14750 emit_move_insn (MEM_DEREF (addr), fn_reg);
14751 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
14752 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
14753 }
b6c9286a
MM
14754 break;
14755
4dabc42d
TC
14756 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
14757 case ABI_DARWIN:
b6c9286a 14758 case ABI_V4:
39403d82 14759 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
14760 FALSE, VOIDmode, 4,
14761 addr, pmode,
14762 GEN_INT (rs6000_trampoline_size ()), SImode,
14763 fnaddr, pmode,
14764 ctx_reg, pmode);
b6c9286a 14765 break;
b6c9286a
MM
14766 }
14767
14768 return;
14769}
7509c759
MM
14770
14771\f
91d231cb 14772/* Table of valid machine attributes. */
a4f6c312 14773
91d231cb 14774const struct attribute_spec rs6000_attribute_table[] =
7509c759 14775{
91d231cb 14776 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 14777 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
14778 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14779 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14780 { NULL, 0, 0, false, false, false, NULL }
91d231cb 14781};
7509c759 14782
8bb418a3
ZL
14783/* Handle the "altivec" attribute. The attribute may have
14784 arguments as follows:
14785
14786 __attribute__((altivec(vector__)))
14787 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
14788 __attribute__((altivec(bool__))) (always followed by 'unsigned')
14789
14790 and may appear more than once (e.g., 'vector bool char') in a
14791 given declaration. */
14792
14793static tree
14794rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
14795 int flags ATTRIBUTE_UNUSED,
14796 bool *no_add_attrs)
14797{
14798 tree type = *node, result = NULL_TREE;
14799 enum machine_mode mode;
14800 int unsigned_p;
14801 char altivec_type
14802 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
14803 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
14804 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
14805 : '?');
14806
14807 while (POINTER_TYPE_P (type)
14808 || TREE_CODE (type) == FUNCTION_TYPE
14809 || TREE_CODE (type) == METHOD_TYPE
14810 || TREE_CODE (type) == ARRAY_TYPE)
14811 type = TREE_TYPE (type);
14812
14813 mode = TYPE_MODE (type);
14814
14815 if (rs6000_warn_altivec_long
14816 && (type == long_unsigned_type_node || type == long_integer_type_node))
14817 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
14818
14819 switch (altivec_type)
14820 {
14821 case 'v':
14822 unsigned_p = TREE_UNSIGNED (type);
14823 switch (mode)
14824 {
14825 case SImode:
14826 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
14827 break;
14828 case HImode:
14829 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
14830 break;
14831 case QImode:
14832 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
14833 break;
14834 case SFmode: result = V4SF_type_node; break;
14835 /* If the user says 'vector int bool', we may be handed the 'bool'
14836 attribute _before_ the 'vector' attribute, and so select the proper
14837 type in the 'b' case below. */
14838 case V4SImode: case V8HImode: case V16QImode: result = type;
14839 default: break;
14840 }
14841 break;
14842 case 'b':
14843 switch (mode)
14844 {
14845 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
14846 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
14847 case QImode: case V16QImode: result = bool_V16QI_type_node;
14848 default: break;
14849 }
14850 break;
14851 case 'p':
14852 switch (mode)
14853 {
14854 case V8HImode: result = pixel_V8HI_type_node;
14855 default: break;
14856 }
14857 default: break;
14858 }
14859
14860 *no_add_attrs = true; /* No need to hang on to the attribute. */
14861
14862 if (!result)
14863 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
14864 else
14865 *node = reconstruct_complex_type (*node, result);
14866
14867 return NULL_TREE;
14868}
14869
a5c76ee6
ZW
14870/* Handle a "longcall" or "shortcall" attribute; arguments as in
14871 struct attribute_spec.handler. */
a4f6c312 14872
91d231cb 14873static tree
a2369ed3
DJ
14874rs6000_handle_longcall_attribute (tree *node, tree name,
14875 tree args ATTRIBUTE_UNUSED,
14876 int flags ATTRIBUTE_UNUSED,
14877 bool *no_add_attrs)
91d231cb
JM
14878{
14879 if (TREE_CODE (*node) != FUNCTION_TYPE
14880 && TREE_CODE (*node) != FIELD_DECL
14881 && TREE_CODE (*node) != TYPE_DECL)
14882 {
14883 warning ("`%s' attribute only applies to functions",
14884 IDENTIFIER_POINTER (name));
14885 *no_add_attrs = true;
14886 }
6a4cee5f 14887
91d231cb 14888 return NULL_TREE;
7509c759
MM
14889}
14890
a5c76ee6
ZW
14891/* Set longcall attributes on all functions declared when
14892 rs6000_default_long_calls is true. */
14893static void
a2369ed3 14894rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
14895{
14896 if (rs6000_default_long_calls
14897 && (TREE_CODE (type) == FUNCTION_TYPE
14898 || TREE_CODE (type) == METHOD_TYPE))
14899 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
14900 NULL_TREE,
14901 TYPE_ATTRIBUTES (type));
14902}
14903
3cb999d8
DE
14904/* Return a reference suitable for calling a function with the
14905 longcall attribute. */
a4f6c312 14906
6a4cee5f 14907struct rtx_def *
a2369ed3 14908rs6000_longcall_ref (rtx call_ref)
6a4cee5f 14909{
d330fd93 14910 const char *call_name;
6a4cee5f
MM
14911 tree node;
14912
14913 if (GET_CODE (call_ref) != SYMBOL_REF)
14914 return call_ref;
14915
14916 /* System V adds '.' to the internal name, so skip them. */
14917 call_name = XSTR (call_ref, 0);
14918 if (*call_name == '.')
14919 {
14920 while (*call_name == '.')
14921 call_name++;
14922
14923 node = get_identifier (call_name);
39403d82 14924 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
14925 }
14926
14927 return force_reg (Pmode, call_ref);
14928}
7509c759 14929\f
b64a1b53
RH
14930#ifdef USING_ELFOS_H
14931
7509c759
MM
14932/* A C statement or statements to switch to the appropriate section
14933 for output of RTX in mode MODE. You can assume that RTX is some
14934 kind of constant in RTL. The argument MODE is redundant except in
14935 the case of a `const_int' rtx. Select the section by calling
14936 `text_section' or one of the alternatives for other sections.
14937
14938 Do not define this macro if you put all constants in the read-only
14939 data section. */
14940
b64a1b53 14941static void
a2369ed3
DJ
14942rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
14943 unsigned HOST_WIDE_INT align)
7509c759 14944{
a9098fd0 14945 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 14946 toc_section ();
7509c759 14947 else
b64a1b53 14948 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
14949}
14950
14951/* A C statement or statements to switch to the appropriate
14952 section for output of DECL. DECL is either a `VAR_DECL' node
14953 or a constant of some sort. RELOC indicates whether forming
14954 the initial value of DECL requires link-time relocations. */
14955
ae46c4e0 14956static void
a2369ed3
DJ
14957rs6000_elf_select_section (tree decl, int reloc,
14958 unsigned HOST_WIDE_INT align)
7509c759 14959{
f1384257
AM
14960 /* Pretend that we're always building for a shared library when
14961 ABI_AIX, because otherwise we end up with dynamic relocations
14962 in read-only sections. This happens for function pointers,
14963 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
14964 default_elf_select_section_1 (decl, reloc, align,
14965 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
14966}
14967
14968/* A C statement to build up a unique section name, expressed as a
14969 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
14970 RELOC indicates whether the initial value of EXP requires
14971 link-time relocations. If you do not define this macro, GCC will use
14972 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 14973 macro can now be called for uninitialized data items as well as
4912a07c 14974 initialized data and functions. */
63019373 14975
ae46c4e0 14976static void
a2369ed3 14977rs6000_elf_unique_section (tree decl, int reloc)
63019373 14978{
f1384257
AM
14979 /* As above, pretend that we're always building for a shared library
14980 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
14981 default_unique_section_1 (decl, reloc,
14982 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 14983}
d9407988 14984\f
d1908feb
JJ
14985/* For a SYMBOL_REF, set generic flags and then perform some
14986 target-specific processing.
14987
d1908feb
JJ
14988 When the AIX ABI is requested on a non-AIX system, replace the
14989 function name with the real name (with a leading .) rather than the
14990 function descriptor name. This saves a lot of overriding code to
14991 read the prefixes. */
d9407988 14992
fb49053f 14993static void
a2369ed3 14994rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 14995{
d1908feb 14996 default_encode_section_info (decl, rtl, first);
b2003250 14997
d1908feb
JJ
14998 if (first
14999 && TREE_CODE (decl) == FUNCTION_DECL
15000 && !TARGET_AIX
15001 && DEFAULT_ABI == ABI_AIX)
d9407988 15002 {
c6a2438a 15003 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
15004 size_t len = strlen (XSTR (sym_ref, 0));
15005 char *str = alloca (len + 2);
15006 str[0] = '.';
15007 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
15008 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 15009 }
d9407988
MM
15010}
15011
0e5dbd9b 15012static bool
a2369ed3 15013rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
15014{
15015 if (rs6000_sdata == SDATA_NONE)
15016 return false;
15017
15018 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
15019 {
15020 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
15021 if (strcmp (section, ".sdata") == 0
15022 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
15023 || strcmp (section, ".sbss") == 0
15024 || strcmp (section, ".sbss2") == 0
15025 || strcmp (section, ".PPC.EMB.sdata0") == 0
15026 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
15027 return true;
15028 }
15029 else
15030 {
15031 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
15032
15033 if (size > 0
307b599c 15034 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
15035 /* If it's not public, and we're not going to reference it there,
15036 there's no need to put it in the small data section. */
0e5dbd9b
DE
15037 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
15038 return true;
15039 }
15040
15041 return false;
15042}
15043
b91da81f 15044#endif /* USING_ELFOS_H */
000034eb 15045
a6c2a102 15046\f
000034eb 15047/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
15048 ADDR can be effectively incremented by incrementing REG.
15049
15050 r0 is special and we must not select it as an address
15051 register by this routine since our caller will try to
15052 increment the returned register via an "la" instruction. */
000034eb
DE
15053
15054struct rtx_def *
a2369ed3 15055find_addr_reg (rtx addr)
000034eb
DE
15056{
15057 while (GET_CODE (addr) == PLUS)
15058 {
02441cd6
JL
15059 if (GET_CODE (XEXP (addr, 0)) == REG
15060 && REGNO (XEXP (addr, 0)) != 0)
000034eb 15061 addr = XEXP (addr, 0);
02441cd6
JL
15062 else if (GET_CODE (XEXP (addr, 1)) == REG
15063 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
15064 addr = XEXP (addr, 1);
15065 else if (CONSTANT_P (XEXP (addr, 0)))
15066 addr = XEXP (addr, 1);
15067 else if (CONSTANT_P (XEXP (addr, 1)))
15068 addr = XEXP (addr, 0);
15069 else
15070 abort ();
15071 }
02441cd6 15072 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
15073 return addr;
15074 abort ();
15075}
15076
a6c2a102 15077void
a2369ed3 15078rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
15079{
15080 fatal_insn ("bad address", op);
15081}
c8023011 15082
ee890fe2
SS
15083#if TARGET_MACHO
15084
15085#if 0
15086/* Returns 1 if OP is either a symbol reference or a sum of a symbol
15087 reference and a constant. */
15088
15089int
a2369ed3 15090symbolic_operand (rtx op)
ee890fe2
SS
15091{
15092 switch (GET_CODE (op))
15093 {
15094 case SYMBOL_REF:
15095 case LABEL_REF:
15096 return 1;
15097 case CONST:
15098 op = XEXP (op, 0);
15099 return (GET_CODE (op) == SYMBOL_REF ||
15100 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
15101 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
15102 && GET_CODE (XEXP (op, 1)) == CONST_INT);
15103 default:
15104 return 0;
15105 }
c8023011 15106}
ee890fe2
SS
15107#endif
15108
efdba735 15109#if TARGET_MACHO
ee890fe2 15110
efdba735 15111static tree branch_island_list = 0;
ee890fe2 15112
efdba735
SH
15113/* Remember to generate a branch island for far calls to the given
15114 function. */
ee890fe2 15115
efdba735
SH
15116static void
15117add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 15118{
efdba735
SH
15119 tree branch_island = build_tree_list (function_name, label_name);
15120 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
15121 TREE_CHAIN (branch_island) = branch_island_list;
15122 branch_island_list = branch_island;
ee890fe2
SS
15123}
15124
efdba735
SH
15125#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
15126#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
15127#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
15128 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 15129
efdba735
SH
15130/* Generate far-jump branch islands for everything on the
15131 branch_island_list. Invoked immediately after the last instruction
15132 of the epilogue has been emitted; the branch-islands must be
15133 appended to, and contiguous with, the function body. Mach-O stubs
15134 are generated in machopic_output_stub(). */
ee890fe2 15135
efdba735
SH
15136static void
15137macho_branch_islands (void)
15138{
15139 char tmp_buf[512];
15140 tree branch_island;
15141
15142 for (branch_island = branch_island_list;
15143 branch_island;
15144 branch_island = TREE_CHAIN (branch_island))
15145 {
15146 const char *label =
15147 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
15148 const char *name =
15149 darwin_strip_name_encoding (
15150 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
15151 char name_buf[512];
15152 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
15153 if (name[0] == '*' || name[0] == '&')
15154 strcpy (name_buf, name+1);
15155 else
15156 {
15157 name_buf[0] = '_';
15158 strcpy (name_buf+1, name);
15159 }
15160 strcpy (tmp_buf, "\n");
15161 strcat (tmp_buf, label);
ee890fe2 15162#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15163 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15164 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15165 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 15166#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
15167 if (flag_pic)
15168 {
15169 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
15170 strcat (tmp_buf, label);
15171 strcat (tmp_buf, "_pic\n");
15172 strcat (tmp_buf, label);
15173 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
15174
15175 strcat (tmp_buf, "\taddis r11,r11,ha16(");
15176 strcat (tmp_buf, name_buf);
15177 strcat (tmp_buf, " - ");
15178 strcat (tmp_buf, label);
15179 strcat (tmp_buf, "_pic)\n");
15180
15181 strcat (tmp_buf, "\tmtlr r0\n");
15182
15183 strcat (tmp_buf, "\taddi r12,r11,lo16(");
15184 strcat (tmp_buf, name_buf);
15185 strcat (tmp_buf, " - ");
15186 strcat (tmp_buf, label);
15187 strcat (tmp_buf, "_pic)\n");
15188
15189 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
15190 }
15191 else
15192 {
15193 strcat (tmp_buf, ":\nlis r12,hi16(");
15194 strcat (tmp_buf, name_buf);
15195 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
15196 strcat (tmp_buf, name_buf);
15197 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
15198 }
15199 output_asm_insn (tmp_buf, 0);
ee890fe2 15200#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15201 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15202 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15203 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 15204#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 15205 }
ee890fe2 15206
efdba735 15207 branch_island_list = 0;
ee890fe2
SS
15208}
15209
15210/* NO_PREVIOUS_DEF checks in the link list whether the function name is
15211 already there or not. */
15212
efdba735 15213static int
a2369ed3 15214no_previous_def (tree function_name)
ee890fe2 15215{
efdba735
SH
15216 tree branch_island;
15217 for (branch_island = branch_island_list;
15218 branch_island;
15219 branch_island = TREE_CHAIN (branch_island))
15220 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
15221 return 0;
15222 return 1;
15223}
15224
15225/* GET_PREV_LABEL gets the label name from the previous definition of
15226 the function. */
15227
efdba735 15228static tree
a2369ed3 15229get_prev_label (tree function_name)
ee890fe2 15230{
efdba735
SH
15231 tree branch_island;
15232 for (branch_island = branch_island_list;
15233 branch_island;
15234 branch_island = TREE_CHAIN (branch_island))
15235 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
15236 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
15237 return 0;
15238}
15239
15240/* INSN is either a function call or a millicode call. It may have an
15241 unconditional jump in its delay slot.
15242
15243 CALL_DEST is the routine we are calling. */
15244
15245char *
efdba735 15246output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
15247{
15248 static char buf[256];
efdba735
SH
15249 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
15250 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
15251 {
15252 tree labelname;
efdba735 15253 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
15254
15255 if (no_previous_def (funname))
15256 {
308c142a 15257 int line_number = 0;
ee890fe2
SS
15258 rtx label_rtx = gen_label_rtx ();
15259 char *label_buf, temp_buf[256];
15260 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
15261 CODE_LABEL_NUMBER (label_rtx));
15262 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
15263 labelname = get_identifier (label_buf);
15264 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
15265 if (insn)
15266 line_number = NOTE_LINE_NUMBER (insn);
efdba735 15267 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
15268 }
15269 else
15270 labelname = get_prev_label (funname);
15271
efdba735
SH
15272 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
15273 instruction will reach 'foo', otherwise link as 'bl L42'".
15274 "L42" should be a 'branch island', that will do a far jump to
15275 'foo'. Branch islands are generated in
15276 macho_branch_islands(). */
ee890fe2 15277 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 15278 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
15279 }
15280 else
efdba735
SH
15281 sprintf (buf, "bl %%z%d", dest_operand_number);
15282 return buf;
ee890fe2
SS
15283}
15284
efdba735 15285#endif /* TARGET_MACHO */
ee890fe2 15286
ee890fe2
SS
15287/* Generate PIC and indirect symbol stubs. */
15288
15289void
a2369ed3 15290machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15291{
15292 unsigned int length;
a4f6c312
SS
15293 char *symbol_name, *lazy_ptr_name;
15294 char *local_label_0;
ee890fe2
SS
15295 static int label = 0;
15296
df56a27f 15297 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15298 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15299
ee890fe2 15300
ee890fe2
SS
15301 length = strlen (symb);
15302 symbol_name = alloca (length + 32);
15303 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15304
15305 lazy_ptr_name = alloca (length + 32);
15306 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15307
ee890fe2 15308 if (flag_pic == 2)
d3c300d2 15309 machopic_picsymbol_stub1_section ();
ee890fe2 15310 else
d3c300d2
DJ
15311 machopic_symbol_stub1_section ();
15312 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15313
15314 fprintf (file, "%s:\n", stub);
15315 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15316
15317 if (flag_pic == 2)
15318 {
876455fa
AP
15319 label++;
15320 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15321 sprintf (local_label_0, "\"L%011d$spb\"", label);
15322
ee890fe2
SS
15323 fprintf (file, "\tmflr r0\n");
15324 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15325 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15326 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15327 lazy_ptr_name, local_label_0);
15328 fprintf (file, "\tmtlr r0\n");
d3c300d2 15329 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15330 lazy_ptr_name, local_label_0);
15331 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15332 fprintf (file, "\tbctr\n");
15333 }
15334 else
ab82a49f
AP
15335 {
15336 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15337 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15338 fprintf (file, "\tmtctr r12\n");
15339 fprintf (file, "\tbctr\n");
15340 }
ee890fe2
SS
15341
15342 machopic_lazy_symbol_ptr_section ();
15343 fprintf (file, "%s:\n", lazy_ptr_name);
15344 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15345 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15346}
15347
15348/* Legitimize PIC addresses. If the address is already
15349 position-independent, we return ORIG. Newly generated
15350 position-independent addresses go into a reg. This is REG if non
15351 zero, otherwise we allocate register(s) as necessary. */
15352
c859cda6 15353#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15354
15355rtx
a2369ed3
DJ
15356rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15357 rtx reg)
ee890fe2
SS
15358{
15359 rtx base, offset;
15360
15361 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15362 reg = gen_reg_rtx (Pmode);
15363
15364 if (GET_CODE (orig) == CONST)
15365 {
15366 if (GET_CODE (XEXP (orig, 0)) == PLUS
15367 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15368 return orig;
15369
15370 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15371 {
2cf520bf 15372 /* Use a different reg for the intermediate value, as
a3c9585f 15373 it will be marked UNCHANGING. */
2cf520bf
GK
15374 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15375
a4f6c312
SS
15376 base =
15377 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15378 Pmode, reg_temp);
a4f6c312
SS
15379 offset =
15380 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15381 Pmode, reg);
ee890fe2
SS
15382 }
15383 else
15384 abort ();
15385
15386 if (GET_CODE (offset) == CONST_INT)
15387 {
15388 if (SMALL_INT (offset))
ed8908e7 15389 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15390 else if (! reload_in_progress && ! reload_completed)
15391 offset = force_reg (Pmode, offset);
15392 else
c859cda6
DJ
15393 {
15394 rtx mem = force_const_mem (Pmode, orig);
15395 return machopic_legitimize_pic_address (mem, Pmode, reg);
15396 }
ee890fe2 15397 }
f1c25d3b 15398 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15399 }
15400
15401 /* Fall back on generic machopic code. */
15402 return machopic_legitimize_pic_address (orig, mode, reg);
15403}
15404
15405/* This is just a placeholder to make linking work without having to
15406 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15407 ever needed for Darwin (not too likely!) this would have to get a
15408 real definition. */
15409
15410void
863d938c 15411toc_section (void)
ee890fe2
SS
15412{
15413}
15414
15415#endif /* TARGET_MACHO */
7c262518
RH
15416
15417#if TARGET_ELF
15418static unsigned int
a2369ed3 15419rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15420{
1ff8f81a
AM
15421 return default_section_type_flags_1 (decl, name, reloc,
15422 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15423}
d9f6800d
RH
15424
15425/* Record an element in the table of global constructors. SYMBOL is
15426 a SYMBOL_REF of the function to be called; PRIORITY is a number
15427 between 0 and MAX_INIT_PRIORITY.
15428
15429 This differs from default_named_section_asm_out_constructor in
15430 that we have special handling for -mrelocatable. */
15431
15432static void
a2369ed3 15433rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15434{
15435 const char *section = ".ctors";
15436 char buf[16];
15437
15438 if (priority != DEFAULT_INIT_PRIORITY)
15439 {
15440 sprintf (buf, ".ctors.%.5u",
15441 /* Invert the numbering so the linker puts us in the proper
15442 order; constructors are run from right to left, and the
15443 linker sorts in increasing order. */
15444 MAX_INIT_PRIORITY - priority);
15445 section = buf;
15446 }
15447
715bdd29
RH
15448 named_section_flags (section, SECTION_WRITE);
15449 assemble_align (POINTER_SIZE);
d9f6800d
RH
15450
15451 if (TARGET_RELOCATABLE)
15452 {
15453 fputs ("\t.long (", asm_out_file);
15454 output_addr_const (asm_out_file, symbol);
15455 fputs (")@fixup\n", asm_out_file);
15456 }
15457 else
c8af3574 15458 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15459}
15460
15461static void
a2369ed3 15462rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15463{
15464 const char *section = ".dtors";
15465 char buf[16];
15466
15467 if (priority != DEFAULT_INIT_PRIORITY)
15468 {
15469 sprintf (buf, ".dtors.%.5u",
15470 /* Invert the numbering so the linker puts us in the proper
15471 order; constructors are run from right to left, and the
15472 linker sorts in increasing order. */
15473 MAX_INIT_PRIORITY - priority);
15474 section = buf;
15475 }
15476
715bdd29
RH
15477 named_section_flags (section, SECTION_WRITE);
15478 assemble_align (POINTER_SIZE);
d9f6800d
RH
15479
15480 if (TARGET_RELOCATABLE)
15481 {
15482 fputs ("\t.long (", asm_out_file);
15483 output_addr_const (asm_out_file, symbol);
15484 fputs (")@fixup\n", asm_out_file);
15485 }
15486 else
c8af3574 15487 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15488}
9739c90c
JJ
15489
15490void
a2369ed3 15491rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15492{
15493 if (TARGET_64BIT)
15494 {
15495 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15496 ASM_OUTPUT_LABEL (file, name);
15497 fputs (DOUBLE_INT_ASM_OP, file);
15498 putc ('.', file);
15499 assemble_name (file, name);
15500 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15501 assemble_name (file, name);
15502 fputs (",24\n\t.type\t.", file);
15503 assemble_name (file, name);
15504 fputs (",@function\n", file);
15505 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15506 {
15507 fputs ("\t.globl\t.", file);
15508 assemble_name (file, name);
15509 putc ('\n', file);
15510 }
15511 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15512 putc ('.', file);
15513 ASM_OUTPUT_LABEL (file, name);
15514 return;
15515 }
15516
15517 if (TARGET_RELOCATABLE
15518 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15519 && uses_TOC ())
9739c90c
JJ
15520 {
15521 char buf[256];
15522
15523 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15524
15525 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15526 fprintf (file, "\t.long ");
15527 assemble_name (file, buf);
15528 putc ('-', file);
15529 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15530 assemble_name (file, buf);
15531 putc ('\n', file);
15532 }
15533
15534 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15535 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15536
15537 if (DEFAULT_ABI == ABI_AIX)
15538 {
15539 const char *desc_name, *orig_name;
15540
15541 orig_name = (*targetm.strip_name_encoding) (name);
15542 desc_name = orig_name;
15543 while (*desc_name == '.')
15544 desc_name++;
15545
15546 if (TREE_PUBLIC (decl))
15547 fprintf (file, "\t.globl %s\n", desc_name);
15548
15549 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15550 fprintf (file, "%s:\n", desc_name);
15551 fprintf (file, "\t.long %s\n", orig_name);
15552 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15553 if (DEFAULT_ABI == ABI_AIX)
15554 fputs ("\t.long 0\n", file);
15555 fprintf (file, "\t.previous\n");
15556 }
15557 ASM_OUTPUT_LABEL (file, name);
15558}
7c262518
RH
15559#endif
15560
cbaaba19 15561#if TARGET_XCOFF
7c262518 15562static void
a2369ed3 15563rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15564{
15565 fputs (GLOBAL_ASM_OP, stream);
15566 RS6000_OUTPUT_BASENAME (stream, name);
15567 putc ('\n', stream);
15568}
15569
15570static void
a2369ed3 15571rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15572{
0e5dbd9b
DE
15573 int smclass;
15574 static const char * const suffix[3] = { "PR", "RO", "RW" };
15575
15576 if (flags & SECTION_CODE)
15577 smclass = 0;
15578 else if (flags & SECTION_WRITE)
15579 smclass = 2;
15580 else
15581 smclass = 1;
15582
5b5198f7 15583 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15584 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15585 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15586}
ae46c4e0
RH
15587
15588static void
a2369ed3
DJ
15589rs6000_xcoff_select_section (tree decl, int reloc,
15590 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15591{
5add3202 15592 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15593 {
0e5dbd9b 15594 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15595 read_only_data_section ();
15596 else
15597 read_only_private_data_section ();
15598 }
15599 else
15600 {
0e5dbd9b 15601 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15602 data_section ();
15603 else
15604 private_data_section ();
15605 }
15606}
15607
15608static void
a2369ed3 15609rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15610{
15611 const char *name;
ae46c4e0 15612
5b5198f7
DE
15613 /* Use select_section for private and uninitialized data. */
15614 if (!TREE_PUBLIC (decl)
15615 || DECL_COMMON (decl)
0e5dbd9b
DE
15616 || DECL_INITIAL (decl) == NULL_TREE
15617 || DECL_INITIAL (decl) == error_mark_node
15618 || (flag_zero_initialized_in_bss
15619 && initializer_zerop (DECL_INITIAL (decl))))
15620 return;
15621
15622 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15623 name = (*targetm.strip_name_encoding) (name);
15624 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15625}
b64a1b53 15626
fb49053f
RH
15627/* Select section for constant in constant pool.
15628
15629 On RS/6000, all constants are in the private read-only data area.
15630 However, if this is being placed in the TOC it must be output as a
15631 toc entry. */
15632
b64a1b53 15633static void
a2369ed3
DJ
15634rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15635 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15636{
15637 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15638 toc_section ();
15639 else
15640 read_only_private_data_section ();
15641}
772c5265
RH
15642
15643/* Remove any trailing [DS] or the like from the symbol name. */
15644
15645static const char *
a2369ed3 15646rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15647{
15648 size_t len;
15649 if (*name == '*')
15650 name++;
15651 len = strlen (name);
15652 if (name[len - 1] == ']')
15653 return ggc_alloc_string (name, len - 4);
15654 else
15655 return name;
15656}
15657
5add3202
DE
15658/* Section attributes. AIX is always PIC. */
15659
15660static unsigned int
a2369ed3 15661rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15662{
5b5198f7
DE
15663 unsigned int align;
15664 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15665
15666 /* Align to at least UNIT size. */
15667 if (flags & SECTION_CODE)
15668 align = MIN_UNITS_PER_WORD;
15669 else
15670 /* Increase alignment of large objects if not already stricter. */
15671 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
15672 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
15673 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
15674
15675 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 15676}
a5fe455b 15677
1bc7c5b6
ZW
15678/* Output at beginning of assembler file.
15679
15680 Initialize the section names for the RS/6000 at this point.
15681
15682 Specify filename, including full path, to assembler.
15683
15684 We want to go into the TOC section so at least one .toc will be emitted.
15685 Also, in order to output proper .bs/.es pairs, we need at least one static
15686 [RW] section emitted.
15687
15688 Finally, declare mcount when profiling to make the assembler happy. */
15689
15690static void
863d938c 15691rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
15692{
15693 rs6000_gen_section_name (&xcoff_bss_section_name,
15694 main_input_filename, ".bss_");
15695 rs6000_gen_section_name (&xcoff_private_data_section_name,
15696 main_input_filename, ".rw_");
15697 rs6000_gen_section_name (&xcoff_read_only_section_name,
15698 main_input_filename, ".ro_");
15699
15700 fputs ("\t.file\t", asm_out_file);
15701 output_quoted_string (asm_out_file, main_input_filename);
15702 fputc ('\n', asm_out_file);
15703 toc_section ();
15704 if (write_symbols != NO_DEBUG)
15705 private_data_section ();
15706 text_section ();
15707 if (profile_flag)
15708 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
15709 rs6000_file_start ();
15710}
15711
a5fe455b
ZW
15712/* Output at end of assembler file.
15713 On the RS/6000, referencing data should automatically pull in text. */
15714
15715static void
863d938c 15716rs6000_xcoff_file_end (void)
a5fe455b
ZW
15717{
15718 text_section ();
15719 fputs ("_section_.text:\n", asm_out_file);
15720 data_section ();
15721 fputs (TARGET_32BIT
15722 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
15723 asm_out_file);
15724}
f1384257 15725#endif /* TARGET_XCOFF */
0e5dbd9b 15726
f1384257
AM
15727#if TARGET_MACHO
15728/* Cross-module name binding. Darwin does not support overriding
7f3d8013 15729 functions at dynamic-link time. */
0e5dbd9b 15730
2bcc50d0 15731static bool
a2369ed3 15732rs6000_binds_local_p (tree decl)
0e5dbd9b 15733{
f1384257 15734 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 15735}
f1384257 15736#endif
34bb030a 15737
3c50106f
RH
15738/* Compute a (partial) cost for rtx X. Return true if the complete
15739 cost has been computed, and false if subexpressions should be
15740 scanned. In either case, *TOTAL contains the cost result. */
15741
15742static bool
a2369ed3
DJ
15743rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
15744 int *total)
3c50106f
RH
15745{
15746 switch (code)
15747 {
15748 /* On the RS/6000, if it is valid in the insn, it is free.
15749 So this always returns 0. */
15750 case CONST_INT:
15751 case CONST:
15752 case LABEL_REF:
15753 case SYMBOL_REF:
15754 case CONST_DOUBLE:
15755 case HIGH:
15756 *total = 0;
15757 return true;
15758
15759 case PLUS:
15760 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15761 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
15762 + 0x8000) >= 0x10000)
15763 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15764 ? COSTS_N_INSNS (2)
15765 : COSTS_N_INSNS (1));
15766 return true;
15767
15768 case AND:
15769 case IOR:
15770 case XOR:
15771 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15772 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
15773 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15774 ? COSTS_N_INSNS (2)
15775 : COSTS_N_INSNS (1));
15776 return true;
15777
15778 case MULT:
15779 if (optimize_size)
15780 {
15781 *total = COSTS_N_INSNS (2);
15782 return true;
15783 }
15784 switch (rs6000_cpu)
15785 {
15786 case PROCESSOR_RIOS1:
15787 case PROCESSOR_PPC405:
15788 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15789 ? COSTS_N_INSNS (5)
15790 : (INTVAL (XEXP (x, 1)) >= -256
15791 && INTVAL (XEXP (x, 1)) <= 255)
15792 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15793 return true;
15794
02ca7595
DE
15795 case PROCESSOR_PPC440:
15796 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15797 ? COSTS_N_INSNS (3)
15798 : COSTS_N_INSNS (2));
15799 return true;
15800
3c50106f
RH
15801 case PROCESSOR_RS64A:
15802 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15803 ? GET_MODE (XEXP (x, 1)) != DImode
15804 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
15805 : (INTVAL (XEXP (x, 1)) >= -256
15806 && INTVAL (XEXP (x, 1)) <= 255)
15807 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
15808 return true;
15809
15810 case PROCESSOR_RIOS2:
15811 case PROCESSOR_MPCCORE:
15812 case PROCESSOR_PPC604e:
15813 *total = COSTS_N_INSNS (2);
15814 return true;
15815
15816 case PROCESSOR_PPC601:
15817 *total = COSTS_N_INSNS (5);
15818 return true;
15819
15820 case PROCESSOR_PPC603:
15821 case PROCESSOR_PPC7400:
15822 case PROCESSOR_PPC750:
15823 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15824 ? COSTS_N_INSNS (5)
15825 : (INTVAL (XEXP (x, 1)) >= -256
15826 && INTVAL (XEXP (x, 1)) <= 255)
15827 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
15828 return true;
15829
15830 case PROCESSOR_PPC7450:
15831 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15832 ? COSTS_N_INSNS (4)
15833 : COSTS_N_INSNS (3));
15834 return true;
15835
15836 case PROCESSOR_PPC403:
15837 case PROCESSOR_PPC604:
15838 case PROCESSOR_PPC8540:
15839 *total = COSTS_N_INSNS (4);
15840 return true;
15841
15842 case PROCESSOR_PPC620:
15843 case PROCESSOR_PPC630:
3c50106f
RH
15844 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15845 ? GET_MODE (XEXP (x, 1)) != DImode
15846 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
15847 : (INTVAL (XEXP (x, 1)) >= -256
15848 && INTVAL (XEXP (x, 1)) <= 255)
15849 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15850 return true;
15851
9259f3b0
DE
15852 case PROCESSOR_POWER4:
15853 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15854 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
15855 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
15856 : COSTS_N_INSNS (2));
9259f3b0
DE
15857 return true;
15858
3c50106f
RH
15859 default:
15860 abort ();
15861 }
15862
15863 case DIV:
15864 case MOD:
15865 if (GET_CODE (XEXP (x, 1)) == CONST_INT
15866 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
15867 {
15868 *total = COSTS_N_INSNS (2);
15869 return true;
15870 }
5efb1046 15871 /* FALLTHRU */
3c50106f
RH
15872
15873 case UDIV:
15874 case UMOD:
15875 switch (rs6000_cpu)
15876 {
15877 case PROCESSOR_RIOS1:
15878 *total = COSTS_N_INSNS (19);
15879 return true;
15880
15881 case PROCESSOR_RIOS2:
15882 *total = COSTS_N_INSNS (13);
15883 return true;
15884
15885 case PROCESSOR_RS64A:
15886 *total = (GET_MODE (XEXP (x, 1)) != DImode
15887 ? COSTS_N_INSNS (65)
15888 : COSTS_N_INSNS (67));
15889 return true;
15890
15891 case PROCESSOR_MPCCORE:
15892 *total = COSTS_N_INSNS (6);
15893 return true;
15894
15895 case PROCESSOR_PPC403:
15896 *total = COSTS_N_INSNS (33);
15897 return true;
15898
15899 case PROCESSOR_PPC405:
15900 *total = COSTS_N_INSNS (35);
15901 return true;
15902
02ca7595
DE
15903 case PROCESSOR_PPC440:
15904 *total = COSTS_N_INSNS (34);
15905 return true;
15906
3c50106f
RH
15907 case PROCESSOR_PPC601:
15908 *total = COSTS_N_INSNS (36);
15909 return true;
15910
15911 case PROCESSOR_PPC603:
15912 *total = COSTS_N_INSNS (37);
15913 return true;
15914
15915 case PROCESSOR_PPC604:
15916 case PROCESSOR_PPC604e:
15917 *total = COSTS_N_INSNS (20);
15918 return true;
15919
15920 case PROCESSOR_PPC620:
15921 case PROCESSOR_PPC630:
3c50106f
RH
15922 *total = (GET_MODE (XEXP (x, 1)) != DImode
15923 ? COSTS_N_INSNS (21)
15924 : COSTS_N_INSNS (37));
15925 return true;
15926
15927 case PROCESSOR_PPC750:
15928 case PROCESSOR_PPC8540:
15929 case PROCESSOR_PPC7400:
15930 *total = COSTS_N_INSNS (19);
15931 return true;
15932
15933 case PROCESSOR_PPC7450:
15934 *total = COSTS_N_INSNS (23);
15935 return true;
984e25ac
DE
15936
15937 case PROCESSOR_POWER4:
15938 *total = (GET_MODE (XEXP (x, 1)) != DImode
15939 ? COSTS_N_INSNS (18)
15940 : COSTS_N_INSNS (34));
15941 return true;
3c50106f
RH
15942
15943 default:
15944 abort ();
15945 }
15946
15947 case FFS:
15948 *total = COSTS_N_INSNS (4);
15949 return true;
15950
15951 case MEM:
a3c9585f 15952 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
15953 *total = 5;
15954 return true;
15955
15956 default:
15957 return false;
15958 }
15959}
15960
34bb030a
DE
15961/* A C expression returning the cost of moving data from a register of class
15962 CLASS1 to one of CLASS2. */
15963
15964int
a2369ed3
DJ
15965rs6000_register_move_cost (enum machine_mode mode,
15966 enum reg_class from, enum reg_class to)
34bb030a
DE
15967{
15968 /* Moves from/to GENERAL_REGS. */
15969 if (reg_classes_intersect_p (to, GENERAL_REGS)
15970 || reg_classes_intersect_p (from, GENERAL_REGS))
15971 {
15972 if (! reg_classes_intersect_p (to, GENERAL_REGS))
15973 from = to;
15974
15975 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
15976 return (rs6000_memory_move_cost (mode, from, 0)
15977 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
15978
a3c9585f 15979/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
15980 else if (from == CR_REGS)
15981 return 4;
15982
15983 else
15984/* A move will cost one instruction per GPR moved. */
15985 return 2 * HARD_REGNO_NREGS (0, mode);
15986 }
15987
15988/* Moving between two similar registers is just one instruction. */
15989 else if (reg_classes_intersect_p (to, from))
15990 return mode == TFmode ? 4 : 2;
15991
15992/* Everything else has to go through GENERAL_REGS. */
15993 else
15994 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
15995 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
15996}
15997
15998/* A C expressions returning the cost of moving data of MODE from a register to
15999 or from memory. */
16000
16001int
a2369ed3
DJ
16002rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
16003 int in ATTRIBUTE_UNUSED)
34bb030a
DE
16004{
16005 if (reg_classes_intersect_p (class, GENERAL_REGS))
16006 return 4 * HARD_REGNO_NREGS (0, mode);
16007 else if (reg_classes_intersect_p (class, FLOAT_REGS))
16008 return 4 * HARD_REGNO_NREGS (32, mode);
16009 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
16010 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
16011 else
16012 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
16013}
16014
ded9bf77
AH
16015/* Return an RTX representing where to find the function value of a
16016 function returning MODE. */
16017static rtx
16018rs6000_complex_function_value (enum machine_mode mode)
16019{
16020 unsigned int regno;
16021 rtx r1, r2;
16022 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 16023 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77
AH
16024
16025 if (FLOAT_MODE_P (mode))
16026 regno = FP_ARG_RETURN;
16027 else
16028 {
16029 regno = GP_ARG_RETURN;
16030
16031 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 16032 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
16033 return gen_rtx_REG (mode, regno);
16034 }
16035
fb7e4164
AM
16036 if (inner_bytes >= 8)
16037 return gen_rtx_REG (mode, regno);
16038
ded9bf77
AH
16039 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
16040 const0_rtx);
16041 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 16042 GEN_INT (inner_bytes));
ded9bf77
AH
16043 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
16044}
16045
a6ebc39a
AH
16046/* Define how to find the value returned by a function.
16047 VALTYPE is the data type of the value (as a tree).
16048 If the precise function being called is known, FUNC is its FUNCTION_DECL;
16049 otherwise, FUNC is 0.
16050
16051 On the SPE, both FPs and vectors are returned in r3.
16052
16053 On RS/6000 an integer value is in r3 and a floating-point value is in
16054 fp1, unless -msoft-float. */
16055
16056rtx
16057rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
16058{
16059 enum machine_mode mode;
2a8fa26c 16060 unsigned int regno;
a6ebc39a 16061
0e67400a
FJ
16062 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
16063 {
16064 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
16065 return gen_rtx_PARALLEL (DImode,
16066 gen_rtvec (2,
16067 gen_rtx_EXPR_LIST (VOIDmode,
16068 gen_rtx_REG (SImode, GP_ARG_RETURN),
16069 const0_rtx),
16070 gen_rtx_EXPR_LIST (VOIDmode,
16071 gen_rtx_REG (SImode,
16072 GP_ARG_RETURN + 1),
16073 GEN_INT (4))));
16074 }
16075
a6ebc39a
AH
16076 if ((INTEGRAL_TYPE_P (valtype)
16077 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
16078 || POINTER_TYPE_P (valtype))
b78d48dd 16079 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
16080 else
16081 mode = TYPE_MODE (valtype);
16082
2a8fa26c
DE
16083 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
16084 regno = FP_ARG_RETURN;
ded9bf77
AH
16085 else if (TREE_CODE (valtype) == COMPLEX_TYPE
16086 && TARGET_HARD_FLOAT
42ba5130 16087 && targetm.calls.split_complex_arg)
ded9bf77 16088 return rs6000_complex_function_value (mode);
2a8fa26c 16089 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
16090 regno = ALTIVEC_ARG_RETURN;
16091 else
16092 regno = GP_ARG_RETURN;
16093
16094 return gen_rtx_REG (mode, regno);
16095}
16096
ded9bf77
AH
16097/* Define how to find the value returned by a library function
16098 assuming the value has mode MODE. */
16099rtx
16100rs6000_libcall_value (enum machine_mode mode)
16101{
16102 unsigned int regno;
16103
16104 if (GET_MODE_CLASS (mode) == MODE_FLOAT
16105 && TARGET_HARD_FLOAT && TARGET_FPRS)
16106 regno = FP_ARG_RETURN;
16107 else if (ALTIVEC_VECTOR_MODE (mode))
16108 regno = ALTIVEC_ARG_RETURN;
42ba5130 16109 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
16110 return rs6000_complex_function_value (mode);
16111 else
16112 regno = GP_ARG_RETURN;
16113
16114 return gen_rtx_REG (mode, regno);
16115}
16116
d1d0c603
JJ
16117/* Define the offset between two registers, FROM to be eliminated and its
16118 replacement TO, at the start of a routine. */
16119HOST_WIDE_INT
16120rs6000_initial_elimination_offset (int from, int to)
16121{
16122 rs6000_stack_t *info = rs6000_stack_info ();
16123 HOST_WIDE_INT offset;
16124
16125 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16126 offset = info->push_p ? 0 : -info->total_size;
16127 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
16128 offset = info->total_size;
16129 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16130 offset = info->push_p ? info->total_size : 0;
16131 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
16132 offset = 0;
16133 else
16134 abort ();
16135
16136 return offset;
16137}
16138
62e1dfcf
NC
16139/* Return true if TYPE is of type __ev64_opaque__. */
16140
c8e4f0e9 16141static bool
a2369ed3 16142is_ev64_opaque_type (tree type)
62e1dfcf 16143{
c8e4f0e9 16144 return (TARGET_SPE
2abe3e28
AH
16145 && (type == opaque_V2SI_type_node
16146 || type == opaque_V2SF_type_node
36252949 16147 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
16148}
16149
96714395 16150static rtx
a2369ed3 16151rs6000_dwarf_register_span (rtx reg)
96714395
AH
16152{
16153 unsigned regno;
16154
16155 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
16156 return NULL_RTX;
16157
16158 regno = REGNO (reg);
16159
16160 /* The duality of the SPE register size wreaks all kinds of havoc.
16161 This is a way of distinguishing r0 in 32-bits from r0 in
16162 64-bits. */
16163 return
16164 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
16165 BYTES_BIG_ENDIAN
16166 ? gen_rtvec (2,
16167 gen_rtx_REG (SImode, regno + 1200),
16168 gen_rtx_REG (SImode, regno))
16169 : gen_rtvec (2,
16170 gen_rtx_REG (SImode, regno),
16171 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
16172}
16173
93c9d1ba
AM
16174/* Map internal gcc register numbers to DWARF2 register numbers. */
16175
16176unsigned int
16177rs6000_dbx_register_number (unsigned int regno)
16178{
16179 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
16180 return regno;
16181 if (regno == MQ_REGNO)
16182 return 100;
16183 if (regno == LINK_REGISTER_REGNUM)
16184 return 108;
16185 if (regno == COUNT_REGISTER_REGNUM)
16186 return 109;
16187 if (CR_REGNO_P (regno))
16188 return regno - CR0_REGNO + 86;
16189 if (regno == XER_REGNO)
16190 return 101;
16191 if (ALTIVEC_REGNO_P (regno))
16192 return regno - FIRST_ALTIVEC_REGNO + 1124;
16193 if (regno == VRSAVE_REGNO)
16194 return 356;
16195 if (regno == VSCR_REGNO)
16196 return 67;
16197 if (regno == SPE_ACC_REGNO)
16198 return 99;
16199 if (regno == SPEFSCR_REGNO)
16200 return 612;
16201 /* SPE high reg number. We get these values of regno from
16202 rs6000_dwarf_register_span. */
16203 if (regno >= 1200 && regno < 1232)
16204 return regno;
16205
16206 abort ();
16207}
16208
17211ab5 16209#include "gt-rs6000.h"