]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* c-decl.c (c_static_assembler_name): Remove TREE_STATIC test.
[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,
d3c300d2 3 2000, 2001, 2002, 2003 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"
1bc7c5b6
ZW
54#if TARGET_XCOFF
55#include "xcoffout.h" /* get declarations of xcoff_*_section_name */
56#endif
9b30bae2 57
7509c759
MM
58#ifndef TARGET_NO_PROTOTYPE
59#define TARGET_NO_PROTOTYPE 0
60#endif
61
d744e06e
AH
62#define EASY_VECTOR_15(n, x, y) ((n) >= -16 && (n) <= 15 \
63 && easy_vector_same (x, y))
64
65#define EASY_VECTOR_15_ADD_SELF(n, x, y) ((n) >= 0x10 && (n) <= 0x1e \
66 && !((n) & 1) \
67 && easy_vector_same (x, y))
68
9878760c
RK
69#define min(A,B) ((A) < (B) ? (A) : (B))
70#define max(A,B) ((A) > (B) ? (A) : (B))
71
5248c961
RK
72/* Target cpu type */
73
74enum processor_type rs6000_cpu;
8e3f41e7
MM
75struct rs6000_cpu_select rs6000_select[3] =
76{
815cdc52
MM
77 /* switch name, tune arch */
78 { (const char *)0, "--with-cpu=", 1, 1 },
79 { (const char *)0, "-mcpu=", 1, 1 },
80 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 81};
5248c961 82
6fa3f289
ZW
83/* Size of long double */
84const char *rs6000_long_double_size_string;
85int rs6000_long_double_type_size;
86
87/* Whether -mabi=altivec has appeared */
88int rs6000_altivec_abi;
89
08b57fb3
AH
90/* Whether VRSAVE instructions should be generated. */
91int rs6000_altivec_vrsave;
92
93/* String from -mvrsave= option. */
94const char *rs6000_altivec_vrsave_string;
95
a3170dc6
AH
96/* Nonzero if we want SPE ABI extensions. */
97int rs6000_spe_abi;
98
99/* Whether isel instructions should be generated. */
100int rs6000_isel;
101
993f19a8
AH
102/* Whether SPE simd instructions should be generated. */
103int rs6000_spe;
104
5da702b1
AH
105/* Nonzero if floating point operations are done in the GPRs. */
106int rs6000_float_gprs = 0;
107
108/* String from -mfloat-gprs=. */
109const char *rs6000_float_gprs_string;
a3170dc6
AH
110
111/* String from -misel=. */
112const char *rs6000_isel_string;
113
993f19a8
AH
114/* String from -mspe=. */
115const char *rs6000_spe_string;
116
a0ab749a 117/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 118static GTY(()) int common_mode_defined;
c81bebd7 119
9878760c
RK
120/* Save information from a "cmpxx" operation until the branch or scc is
121 emitted. */
9878760c
RK
122rtx rs6000_compare_op0, rs6000_compare_op1;
123int rs6000_compare_fp_p;
874a0744 124
874a0744
MM
125/* Label number of label created for -mrelocatable, to call to so we can
126 get the address of the GOT section */
127int rs6000_pic_labelno;
c81bebd7 128
b91da81f 129#ifdef USING_ELFOS_H
c81bebd7 130/* Which abi to adhere to */
9739c90c 131const char *rs6000_abi_name;
d9407988
MM
132
133/* Semantics of the small data area */
134enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
135
136/* Which small data model to use */
815cdc52 137const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
138
139/* Counter for labels which are to be placed in .fixup. */
140int fixuplabelno = 0;
874a0744 141#endif
4697a36c 142
c4501e62
JJ
143/* Bit size of immediate TLS offsets and string from which it is decoded. */
144int rs6000_tls_size = 32;
145const char *rs6000_tls_size_string;
146
b6c9286a
MM
147/* ABI enumeration available for subtarget to use. */
148enum rs6000_abi rs6000_current_abi;
149
0ac081f6
AH
150/* ABI string from -mabi= option. */
151const char *rs6000_abi_string;
152
38c1f2d7 153/* Debug flags */
815cdc52 154const char *rs6000_debug_name;
38c1f2d7
MM
155int rs6000_debug_stack; /* debug stack applications */
156int rs6000_debug_arg; /* debug argument handling */
157
6035d635 158/* Opaque types. */
2abe3e28 159static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 160static GTY(()) tree opaque_V2SF_type_node;
6035d635 161static GTY(()) tree opaque_p_V2SI_type_node;
2abe3e28 162
57ac7be9
AM
163const char *rs6000_traceback_name;
164static enum {
165 traceback_default = 0,
166 traceback_none,
167 traceback_part,
168 traceback_full
169} rs6000_traceback;
170
38c1f2d7
MM
171/* Flag to say the TOC is initialized */
172int toc_initialized;
9ebbca7d 173char toc_label_name[10];
38c1f2d7 174
9ebbca7d
GK
175/* Alias set for saves and restores from the rs6000 stack. */
176static int rs6000_sr_alias_set;
c8023011 177
a5c76ee6
ZW
178/* Call distance, overridden by -mlongcall and #pragma longcall(1).
179 The only place that looks at this is rs6000_set_default_type_attributes;
180 everywhere else should rely on the presence or absence of a longcall
181 attribute on the function declaration. */
182int rs6000_default_long_calls;
183const char *rs6000_longcall_switch;
184
025d9908
KH
185/* Control alignment for fields within structures. */
186/* String from -malign-XXXXX. */
187const char *rs6000_alignment_string;
188int rs6000_alignment_flags;
189
a3170dc6
AH
190struct builtin_description
191{
192 /* mask is not const because we're going to alter it below. This
193 nonsense will go away when we rewrite the -march infrastructure
194 to give us more target flag bits. */
195 unsigned int mask;
196 const enum insn_code icode;
197 const char *const name;
198 const enum rs6000_builtins code;
199};
200
4977bab6 201static bool rs6000_function_ok_for_sibcall PARAMS ((tree, tree));
9ebbca7d 202static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
39a10a29
GK
203static void validate_condition_mode
204 PARAMS ((enum rtx_code, enum machine_mode));
205static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
e50f5f3d 206static void rs6000_maybe_dead PARAMS ((rtx));
9ebbca7d
GK
207static void rs6000_emit_stack_tie PARAMS ((void));
208static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
c19de7aa
AH
209static rtx spe_synthesize_frame_save PARAMS ((rtx));
210static bool spe_func_has_64bit_regs_p PARAMS ((void));
89e7058f
AH
211static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode,
212 unsigned int, int, int));
a3170dc6 213static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int));
9ebbca7d
GK
214static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
215static unsigned rs6000_hash_constant PARAMS ((rtx));
216static unsigned toc_hash_function PARAMS ((const void *));
217static int toc_hash_eq PARAMS ((const void *, const void *));
9ebbca7d 218static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
4d588c14
RH
219static bool constant_pool_expr_p PARAMS ((rtx));
220static bool toc_relative_expr_p PARAMS ((rtx));
221static bool legitimate_small_data_p PARAMS ((enum machine_mode, rtx));
222static bool legitimate_offset_address_p PARAMS ((enum machine_mode, rtx, int));
223static bool legitimate_indexed_address_p PARAMS ((rtx, int));
224static bool legitimate_indirect_address_p PARAMS ((rtx, int));
225static bool legitimate_lo_sum_address_p PARAMS ((enum machine_mode, rtx, int));
e2500fed 226static struct machine_function * rs6000_init_machine_status PARAMS ((void));
301d03af 227static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
5add3202 228#ifdef HAVE_GAS_HIDDEN
25fdb4dc 229static void rs6000_assemble_visibility PARAMS ((tree, int));
5add3202 230#endif
71f123ca 231static int rs6000_ra_ever_killed PARAMS ((void));
91d231cb 232static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
b86fe7b4 233extern const struct attribute_spec rs6000_attribute_table[];
a5c76ee6 234static void rs6000_set_default_type_attributes PARAMS ((tree));
08c148a8
NB
235static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
236static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
3961e8fe
RH
237static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
238 HOST_WIDE_INT, tree));
2bfcf297
DB
239static rtx rs6000_emit_set_long_const PARAMS ((rtx,
240 HOST_WIDE_INT, HOST_WIDE_INT));
1bc7c5b6 241static void rs6000_file_start PARAMS ((void));
7c262518
RH
242#if TARGET_ELF
243static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
244 int));
d9f6800d
RH
245static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
246static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
ae46c4e0 247static void rs6000_elf_select_section PARAMS ((tree, int,
5b71a4e7 248 unsigned HOST_WIDE_INT));
ae46c4e0 249static void rs6000_elf_unique_section PARAMS ((tree, int));
b64a1b53
RH
250static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
251 unsigned HOST_WIDE_INT));
c6a2438a 252static void rs6000_elf_encode_section_info PARAMS ((tree, rtx, int))
0e5dbd9b 253 ATTRIBUTE_UNUSED;
0e5dbd9b 254static bool rs6000_elf_in_small_data_p PARAMS ((tree));
7c262518 255#endif
cbaaba19 256#if TARGET_XCOFF
b275d088
DE
257static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *));
258static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int));
ae46c4e0
RH
259static void rs6000_xcoff_select_section PARAMS ((tree, int,
260 unsigned HOST_WIDE_INT));
261static void rs6000_xcoff_unique_section PARAMS ((tree, int));
b64a1b53
RH
262static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx,
263 unsigned HOST_WIDE_INT));
772c5265 264static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
5add3202 265static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
1bc7c5b6 266static void rs6000_xcoff_file_start PARAMS ((void));
a5fe455b 267static void rs6000_xcoff_file_end PARAMS ((void));
f1384257
AM
268#endif
269#if TARGET_MACHO
2bcc50d0 270static bool rs6000_binds_local_p PARAMS ((tree));
f1384257 271#endif
b54cf83a 272static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
b54cf83a 273static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
3c50106f 274static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
c237e94a
ZW
275static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
276static int rs6000_adjust_priority PARAMS ((rtx, int));
277static int rs6000_issue_rate PARAMS ((void));
be12c2b0 278static int rs6000_use_sched_lookahead PARAMS ((void));
c237e94a 279
6fa3f289 280static void rs6000_init_builtins PARAMS ((void));
92898235
AH
281static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
282static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
283static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 284static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
92898235 285static void altivec_init_builtins PARAMS ((void));
a3170dc6
AH
286static void rs6000_common_init_builtins PARAMS ((void));
287
288static void enable_mask_for_builtins PARAMS ((struct builtin_description *,
289 int, enum rs6000_builtins,
290 enum rs6000_builtins));
291static void spe_init_builtins PARAMS ((void));
292static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *));
293static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx));
294static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx));
295static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx));
296
92898235 297static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
3a9b8c7e
AH
298static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *));
299static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *));
300static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *));
100c4561 301static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
ae4b4a02 302static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
6525c0e7 303static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
0ac081f6 304static void rs6000_parse_abi_options PARAMS ((void));
025d9908 305static void rs6000_parse_alignment_option PARAMS ((void));
c4501e62 306static void rs6000_parse_tls_size_option PARAMS ((void));
5da702b1 307static void rs6000_parse_yes_no_option (const char *, const char *, int *);
00b960c7
AH
308static int first_altivec_reg_to_save PARAMS ((void));
309static unsigned int compute_vrsave_mask PARAMS ((void));
310static void is_altivec_return_reg PARAMS ((rtx, void *));
9aa86737 311static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
d744e06e
AH
312int easy_vector_constant PARAMS ((rtx, enum machine_mode));
313static int easy_vector_same PARAMS ((rtx, enum machine_mode));
c8e4f0e9 314static bool is_ev64_opaque_type PARAMS ((tree));
96714395 315static rtx rs6000_dwarf_register_span PARAMS ((rtx));
c4501e62
JJ
316static rtx rs6000_legitimize_tls_address PARAMS ((rtx, enum tls_model));
317static rtx rs6000_tls_get_addr PARAMS ((void));
318static rtx rs6000_got_sym PARAMS ((void));
319static inline int rs6000_tls_symbol_ref_1 PARAMS ((rtx *, void *));
320static const char *rs6000_get_some_local_dynamic_name PARAMS ((void));
321static int rs6000_get_some_local_dynamic_name_1 PARAMS ((rtx *, void *));
ded9bf77 322static rtx rs6000_complex_function_value (enum machine_mode);
a6c9bed4 323static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *, enum machine_mode, tree);
17211ab5
GK
324
325/* Hash table stuff for keeping track of TOC entries. */
326
327struct toc_hash_struct GTY(())
328{
329 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
330 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
331 rtx key;
332 enum machine_mode key_mode;
333 int labelno;
334};
335
336static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
337\f
338/* Default register names. */
339char rs6000_reg_names[][8] =
340{
802a0058
MM
341 "0", "1", "2", "3", "4", "5", "6", "7",
342 "8", "9", "10", "11", "12", "13", "14", "15",
343 "16", "17", "18", "19", "20", "21", "22", "23",
344 "24", "25", "26", "27", "28", "29", "30", "31",
345 "0", "1", "2", "3", "4", "5", "6", "7",
346 "8", "9", "10", "11", "12", "13", "14", "15",
347 "16", "17", "18", "19", "20", "21", "22", "23",
348 "24", "25", "26", "27", "28", "29", "30", "31",
349 "mq", "lr", "ctr","ap",
350 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
351 "xer",
352 /* AltiVec registers. */
0cd5e3a1
AH
353 "0", "1", "2", "3", "4", "5", "6", "7",
354 "8", "9", "10", "11", "12", "13", "14", "15",
355 "16", "17", "18", "19", "20", "21", "22", "23",
356 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
357 "vrsave", "vscr",
358 /* SPE registers. */
359 "spe_acc", "spefscr"
c81bebd7
MM
360};
361
362#ifdef TARGET_REGNAMES
8b60264b 363static const char alt_reg_names[][8] =
c81bebd7 364{
802a0058
MM
365 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
366 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
367 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
368 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
369 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
370 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
371 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
372 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
373 "mq", "lr", "ctr", "ap",
374 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 375 "xer",
59a4c851 376 /* AltiVec registers. */
0ac081f6 377 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
378 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
379 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
380 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
381 "vrsave", "vscr",
382 /* SPE registers. */
383 "spe_acc", "spefscr"
c81bebd7
MM
384};
385#endif
9878760c 386\f
daf11973
MM
387#ifndef MASK_STRICT_ALIGN
388#define MASK_STRICT_ALIGN 0
389#endif
ffcfcb5f
AM
390#ifndef TARGET_PROFILE_KERNEL
391#define TARGET_PROFILE_KERNEL 0
392#endif
3961e8fe
RH
393
394/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
395#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
396
397/* Return 1 for a symbol ref for a thread-local storage symbol. */
398#define RS6000_SYMBOL_REF_TLS_P(RTX) \
399 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
400\f
401/* Initialize the GCC target structure. */
91d231cb
JM
402#undef TARGET_ATTRIBUTE_TABLE
403#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
404#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
405#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 406
301d03af
RS
407#undef TARGET_ASM_ALIGNED_DI_OP
408#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
409
410/* Default unaligned ops are only provided for ELF. Find the ops needed
411 for non-ELF systems. */
412#ifndef OBJECT_FORMAT_ELF
cbaaba19 413#if TARGET_XCOFF
ae6c1efd 414/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
415 64-bit targets. */
416#undef TARGET_ASM_UNALIGNED_HI_OP
417#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
418#undef TARGET_ASM_UNALIGNED_SI_OP
419#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
420#undef TARGET_ASM_UNALIGNED_DI_OP
421#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
422#else
423/* For Darwin. */
424#undef TARGET_ASM_UNALIGNED_HI_OP
425#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
426#undef TARGET_ASM_UNALIGNED_SI_OP
427#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
428#endif
429#endif
430
431/* This hook deals with fixups for relocatable code and DI-mode objects
432 in 64-bit code. */
433#undef TARGET_ASM_INTEGER
434#define TARGET_ASM_INTEGER rs6000_assemble_integer
435
93638d7a
AM
436#ifdef HAVE_GAS_HIDDEN
437#undef TARGET_ASM_ASSEMBLE_VISIBILITY
438#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
439#endif
440
c4501e62
JJ
441#undef TARGET_HAVE_TLS
442#define TARGET_HAVE_TLS HAVE_AS_TLS
443
444#undef TARGET_CANNOT_FORCE_CONST_MEM
445#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
446
08c148a8
NB
447#undef TARGET_ASM_FUNCTION_PROLOGUE
448#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
449#undef TARGET_ASM_FUNCTION_EPILOGUE
450#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
451
b54cf83a
DE
452#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
453#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
454#undef TARGET_SCHED_VARIABLE_ISSUE
455#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
456
c237e94a
ZW
457#undef TARGET_SCHED_ISSUE_RATE
458#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
459#undef TARGET_SCHED_ADJUST_COST
460#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
461#undef TARGET_SCHED_ADJUST_PRIORITY
462#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
463
be12c2b0
VM
464#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
465#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
466
0ac081f6
AH
467#undef TARGET_INIT_BUILTINS
468#define TARGET_INIT_BUILTINS rs6000_init_builtins
469
470#undef TARGET_EXPAND_BUILTIN
471#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
472
f1384257 473#if TARGET_MACHO
0e5dbd9b
DE
474#undef TARGET_BINDS_LOCAL_P
475#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 476#endif
0e5dbd9b 477
3961e8fe
RH
478#undef TARGET_ASM_OUTPUT_MI_THUNK
479#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
480
3961e8fe 481#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 482#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 483
4977bab6
ZW
484#undef TARGET_FUNCTION_OK_FOR_SIBCALL
485#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
486
3c50106f
RH
487#undef TARGET_RTX_COSTS
488#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
489#undef TARGET_ADDRESS_COST
490#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 491
c8e4f0e9
AH
492#undef TARGET_VECTOR_OPAQUE_P
493#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 494
96714395
AH
495#undef TARGET_DWARF_REGISTER_SPAN
496#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
497
f6897b10 498struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 499\f
5248c961
RK
500/* Override command line options. Mostly we process the processor
501 type and sometimes adjust other TARGET_ options. */
502
503void
8e3f41e7 504rs6000_override_options (default_cpu)
d330fd93 505 const char *default_cpu;
5248c961 506{
c4d38ccb 507 size_t i, j;
8e3f41e7 508 struct rs6000_cpu_select *ptr;
5248c961 509
85638c0d
RK
510 /* Simplify the entries below by making a mask for any POWER
511 variant and any PowerPC variant. */
512
938937d8 513#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
514#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
515 | MASK_PPC_GFXOPT | MASK_POWERPC64)
516#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 517
5248c961
RK
518 static struct ptt
519 {
8b60264b
KG
520 const char *const name; /* Canonical processor name. */
521 const enum processor_type processor; /* Processor type enum value. */
522 const int target_enable; /* Target flags to enable. */
523 const int target_disable; /* Target flags to disable. */
524 } const processor_target_table[]
cf27b467
MM
525 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
526 POWER_MASKS | POWERPC_MASKS},
db7f1e43 527 {"power", PROCESSOR_POWER,
938937d8 528 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 529 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
530 {"power2", PROCESSOR_POWER,
531 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
532 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
533 {"power3", PROCESSOR_PPC630,
534 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 535 POWER_MASKS},
309323c2 536 {"power4", PROCESSOR_POWER4,
7f3d8013 537 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a12f8290 538 POWER_MASKS},
db7f1e43
RK
539 {"powerpc", PROCESSOR_POWERPC,
540 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 541 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
542 {"powerpc64", PROCESSOR_POWERPC64,
543 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
544 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 545 {"rios", PROCESSOR_RIOS1,
938937d8 546 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
547 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
548 {"rios1", PROCESSOR_RIOS1,
938937d8 549 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
550 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
551 {"rsc", PROCESSOR_PPC601,
938937d8 552 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
553 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
554 {"rsc1", PROCESSOR_PPC601,
938937d8 555 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
556 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
557 {"rios2", PROCESSOR_RIOS2,
938937d8 558 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 559 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
560 {"rs64a", PROCESSOR_RS64A,
561 MASK_POWERPC | MASK_NEW_MNEMONICS,
562 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
563 {"401", PROCESSOR_PPC403,
564 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
565 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 566 {"403", PROCESSOR_PPC403,
daf11973 567 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 568 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
569 {"405", PROCESSOR_PPC405,
570 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
571 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
02ca7595
DE
572 {"405fp", PROCESSOR_PPC405,
573 MASK_POWERPC | MASK_NEW_MNEMONICS,
574 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
575 {"440", PROCESSOR_PPC440,
576 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
577 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
578 {"440fp", PROCESSOR_PPC440,
4977bab6
ZW
579 MASK_POWERPC | MASK_NEW_MNEMONICS,
580 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
581 {"505", PROCESSOR_MPCCORE,
582 MASK_POWERPC | MASK_NEW_MNEMONICS,
583 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 584 {"601", PROCESSOR_PPC601,
938937d8 585 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 586 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 587 {"602", PROCESSOR_PPC603,
cf27b467
MM
588 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
589 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 590 {"603", PROCESSOR_PPC603,
68c49ffa
RK
591 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
592 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
593 {"603e", PROCESSOR_PPC603,
594 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
595 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 596 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
597 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
598 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 599 {"604", PROCESSOR_PPC604,
b6c9286a
MM
600 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
601 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 602 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
603 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
604 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 605 {"620", PROCESSOR_PPC620,
68c49ffa 606 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 607 POWER_MASKS},
3cb999d8
DE
608 {"630", PROCESSOR_PPC630,
609 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 610 POWER_MASKS},
bef84347
VM
611 {"740", PROCESSOR_PPC750,
612 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
613 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
614 {"750", PROCESSOR_PPC750,
615 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
616 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
617 {"7400", PROCESSOR_PPC7400,
618 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
619 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
620 {"7450", PROCESSOR_PPC7450,
621 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
622 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a3170dc6
AH
623 {"8540", PROCESSOR_PPC8540,
624 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
625 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
626 {"801", PROCESSOR_MPCCORE,
627 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
628 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
629 {"821", PROCESSOR_MPCCORE,
630 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
631 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
632 {"823", PROCESSOR_MPCCORE,
633 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
634 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
635 {"860", PROCESSOR_MPCCORE,
636 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
7177e720
DE
637 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
638 {"970", PROCESSOR_POWER4,
639 MASK_POWERPC | POWERPC_OPT_MASKS | MASK_NEW_MNEMONICS,
640 POWER_MASKS}};
5248c961 641
ca7558fc 642 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 643
a4f6c312
SS
644 /* Save current -mmultiple/-mno-multiple status. */
645 int multiple = TARGET_MULTIPLE;
646 /* Save current -mstring/-mno-string status. */
647 int string = TARGET_STRING;
8a61d227 648
a4f6c312 649 /* Identify the processor type. */
8e3f41e7 650 rs6000_select[0].string = default_cpu;
3cb999d8 651 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 652
b6a1cbae 653 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 654 {
8e3f41e7
MM
655 ptr = &rs6000_select[i];
656 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 657 {
8e3f41e7
MM
658 for (j = 0; j < ptt_size; j++)
659 if (! strcmp (ptr->string, processor_target_table[j].name))
660 {
661 if (ptr->set_tune_p)
662 rs6000_cpu = processor_target_table[j].processor;
663
664 if (ptr->set_arch_p)
665 {
666 target_flags |= processor_target_table[j].target_enable;
667 target_flags &= ~processor_target_table[j].target_disable;
668 }
669 break;
670 }
671
4406229e 672 if (j == ptt_size)
8e3f41e7 673 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
674 }
675 }
8a61d227 676
993f19a8 677 if (TARGET_E500)
a3170dc6
AH
678 rs6000_isel = 1;
679
dff9f1b6
DE
680 /* If we are optimizing big endian systems for space, use the load/store
681 multiple and string instructions. */
ef792183 682 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 683 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 684
8a61d227
MM
685 /* If -mmultiple or -mno-multiple was explicitly used, don't
686 override with the processor default */
b21fb038 687 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 688 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 689
a4f6c312
SS
690 /* If -mstring or -mno-string was explicitly used, don't override
691 with the processor default. */
b21fb038 692 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 693 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 694
a4f6c312
SS
695 /* Don't allow -mmultiple or -mstring on little endian systems
696 unless the cpu is a 750, because the hardware doesn't support the
697 instructions used in little endian mode, and causes an alignment
698 trap. The 750 does not cause an alignment trap (except when the
699 target is unaligned). */
bef84347 700
b21fb038 701 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
702 {
703 if (TARGET_MULTIPLE)
704 {
705 target_flags &= ~MASK_MULTIPLE;
b21fb038 706 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
707 warning ("-mmultiple is not supported on little endian systems");
708 }
709
710 if (TARGET_STRING)
711 {
712 target_flags &= ~MASK_STRING;
b21fb038 713 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 714 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
715 }
716 }
3933e0e1 717
38c1f2d7
MM
718 /* Set debug flags */
719 if (rs6000_debug_name)
720 {
bfc79d3b 721 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 722 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 723 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 724 rs6000_debug_stack = 1;
bfc79d3b 725 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
726 rs6000_debug_arg = 1;
727 else
c725bd79 728 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
729 }
730
57ac7be9
AM
731 if (rs6000_traceback_name)
732 {
733 if (! strncmp (rs6000_traceback_name, "full", 4))
734 rs6000_traceback = traceback_full;
735 else if (! strncmp (rs6000_traceback_name, "part", 4))
736 rs6000_traceback = traceback_part;
737 else if (! strncmp (rs6000_traceback_name, "no", 2))
738 rs6000_traceback = traceback_none;
739 else
740 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
741 rs6000_traceback_name);
742 }
743
6fa3f289
ZW
744 /* Set size of long double */
745 rs6000_long_double_type_size = 64;
746 if (rs6000_long_double_size_string)
747 {
748 char *tail;
749 int size = strtol (rs6000_long_double_size_string, &tail, 10);
750 if (*tail != '\0' || (size != 64 && size != 128))
751 error ("Unknown switch -mlong-double-%s",
752 rs6000_long_double_size_string);
753 else
754 rs6000_long_double_type_size = size;
755 }
756
0ac081f6
AH
757 /* Handle -mabi= options. */
758 rs6000_parse_abi_options ();
759
025d9908
KH
760 /* Handle -malign-XXXXX option. */
761 rs6000_parse_alignment_option ();
762
5da702b1
AH
763 /* Handle generic -mFOO=YES/NO options. */
764 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
765 &rs6000_altivec_vrsave);
766 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
767 &rs6000_isel);
768 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
769 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
770 &rs6000_float_gprs);
993f19a8 771
c4501e62
JJ
772 /* Handle -mtls-size option. */
773 rs6000_parse_tls_size_option ();
774
a7ae18e2
AH
775#ifdef SUBTARGET_OVERRIDE_OPTIONS
776 SUBTARGET_OVERRIDE_OPTIONS;
777#endif
778#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
779 SUBSUBTARGET_OVERRIDE_OPTIONS;
780#endif
781
5da702b1
AH
782 if (TARGET_E500)
783 {
784 /* The e500 does not have string instructions, and we set
785 MASK_STRING above when optimizing for size. */
786 if ((target_flags & MASK_STRING) != 0)
787 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
788
789 /* No SPE means 64-bit long doubles, even if an E500. */
790 if (rs6000_spe_string != 0
791 && !strcmp (rs6000_spe_string, "no"))
792 rs6000_long_double_type_size = 64;
5da702b1
AH
793 }
794 else if (rs6000_select[1].string != NULL)
795 {
796 /* For the powerpc-eabispe configuration, we set all these by
797 default, so let's unset them if we manually set another
798 CPU that is not the E500. */
799 if (rs6000_abi_string == 0)
800 rs6000_spe_abi = 0;
801 if (rs6000_spe_string == 0)
802 rs6000_spe = 0;
803 if (rs6000_float_gprs_string == 0)
804 rs6000_float_gprs = 0;
805 if (rs6000_isel_string == 0)
806 rs6000_isel = 0;
b6e59a3a
AH
807 if (rs6000_long_double_size_string == 0)
808 rs6000_long_double_type_size = 64;
5da702b1 809 }
b5044283 810
a5c76ee6
ZW
811 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
812 using TARGET_OPTIONS to handle a toggle switch, but we're out of
813 bits in target_flags so TARGET_SWITCHES cannot be used.
814 Assumption here is that rs6000_longcall_switch points into the
815 text of the complete option, rather than being a copy, so we can
816 scan back for the presence or absence of the no- modifier. */
817 if (rs6000_longcall_switch)
818 {
819 const char *base = rs6000_longcall_switch;
820 while (base[-1] != 'm') base--;
821
822 if (*rs6000_longcall_switch != '\0')
823 error ("invalid option `%s'", base);
824 rs6000_default_long_calls = (base[0] != 'n');
825 }
826
c81bebd7 827#ifdef TARGET_REGNAMES
a4f6c312
SS
828 /* If the user desires alternate register names, copy in the
829 alternate names now. */
c81bebd7 830 if (TARGET_REGNAMES)
4e135bdd 831 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
832#endif
833
6fa3f289
ZW
834 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
835 If -maix-struct-return or -msvr4-struct-return was explicitly
836 used, don't override with the ABI default. */
b21fb038 837 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
838 {
839 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
840 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
841 else
842 target_flags |= MASK_AIX_STRUCT_RET;
843 }
844
fcce224d
DE
845 if (TARGET_LONG_DOUBLE_128
846 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
847 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
848
9ebbca7d
GK
849 /* Allocate an alias set for register saves & restores from stack. */
850 rs6000_sr_alias_set = new_alias_set ();
851
852 if (TARGET_TOC)
853 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 854
301d03af
RS
855 /* We can only guarantee the availability of DI pseudo-ops when
856 assembling for 64-bit targets. */
ae6c1efd 857 if (!TARGET_64BIT)
301d03af
RS
858 {
859 targetm.asm_out.aligned_op.di = NULL;
860 targetm.asm_out.unaligned_op.di = NULL;
861 }
862
2792d578
DE
863 /* Set maximum branch target alignment at two instructions, eight bytes. */
864 align_jumps_max_skip = 8;
865 align_loops_max_skip = 8;
866
71f123ca
FS
867 /* Arrange to save and restore machine status around nested functions. */
868 init_machine_status = rs6000_init_machine_status;
5248c961 869}
5accd822 870
5da702b1
AH
871/* Handle generic options of the form -mfoo=yes/no.
872 NAME is the option name.
873 VALUE is the option value.
874 FLAG is the pointer to the flag where to store a 1 or 0, depending on
875 whether the option value is 'yes' or 'no' respectively. */
993f19a8 876static void
5da702b1 877rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 878{
5da702b1 879 if (value == 0)
993f19a8 880 return;
5da702b1
AH
881 else if (!strcmp (value, "yes"))
882 *flag = 1;
883 else if (!strcmp (value, "no"))
884 *flag = 0;
08b57fb3 885 else
5da702b1 886 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
887}
888
0ac081f6 889/* Handle -mabi= options. */
00b960c7
AH
890static void
891rs6000_parse_abi_options ()
0ac081f6
AH
892{
893 if (rs6000_abi_string == 0)
894 return;
895 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 896 rs6000_altivec_abi = 1;
76a773f3
AH
897 else if (! strcmp (rs6000_abi_string, "no-altivec"))
898 rs6000_altivec_abi = 0;
a3170dc6 899 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
900 {
901 rs6000_spe_abi = 1;
902 if (!TARGET_SPE_ABI)
903 error ("not configured for ABI: '%s'", rs6000_abi_string);
904 }
905
a3170dc6
AH
906 else if (! strcmp (rs6000_abi_string, "no-spe"))
907 rs6000_spe_abi = 0;
0ac081f6 908 else
c725bd79 909 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
910}
911
025d9908
KH
912/* Handle -malign-XXXXXX options. */
913static void
914rs6000_parse_alignment_option ()
915{
916 if (rs6000_alignment_string == 0
917 || ! strcmp (rs6000_alignment_string, "power"))
918 rs6000_alignment_flags = MASK_ALIGN_POWER;
919 else if (! strcmp (rs6000_alignment_string, "natural"))
920 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
921 else
922 error ("unknown -malign-XXXXX option specified: '%s'",
923 rs6000_alignment_string);
924}
925
c4501e62
JJ
926/* Validate and record the size specified with the -mtls-size option. */
927
928static void
929rs6000_parse_tls_size_option ()
930{
931 if (rs6000_tls_size_string == 0)
932 return;
933 else if (strcmp (rs6000_tls_size_string, "16") == 0)
934 rs6000_tls_size = 16;
935 else if (strcmp (rs6000_tls_size_string, "32") == 0)
936 rs6000_tls_size = 32;
937 else if (strcmp (rs6000_tls_size_string, "64") == 0)
938 rs6000_tls_size = 64;
939 else
940 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
941}
942
5accd822
DE
943void
944optimization_options (level, size)
e2c953b6 945 int level ATTRIBUTE_UNUSED;
5accd822
DE
946 int size ATTRIBUTE_UNUSED;
947{
5accd822 948}
3cfa4909
MM
949\f
950/* Do anything needed at the start of the asm file. */
951
1bc7c5b6
ZW
952static void
953rs6000_file_start ()
3cfa4909 954{
c4d38ccb 955 size_t i;
3cfa4909 956 char buffer[80];
d330fd93 957 const char *start = buffer;
3cfa4909 958 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
959 const char *default_cpu = TARGET_CPU_DEFAULT;
960 FILE *file = asm_out_file;
961
962 default_file_start ();
963
964#ifdef TARGET_BI_ARCH
965 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
966 default_cpu = 0;
967#endif
3cfa4909
MM
968
969 if (flag_verbose_asm)
970 {
971 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
972 rs6000_select[0].string = default_cpu;
973
b6a1cbae 974 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
975 {
976 ptr = &rs6000_select[i];
977 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
978 {
979 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
980 start = "";
981 }
982 }
983
b91da81f 984#ifdef USING_ELFOS_H
3cfa4909
MM
985 switch (rs6000_sdata)
986 {
987 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
988 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
989 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
990 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
991 }
992
993 if (rs6000_sdata && g_switch_value)
994 {
307b599c
MK
995 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
996 g_switch_value);
3cfa4909
MM
997 start = "";
998 }
999#endif
1000
1001 if (*start == '\0')
949ea356 1002 putc ('\n', file);
3cfa4909
MM
1003 }
1004}
5248c961 1005\f
a0ab749a 1006/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1007
1008int
1009direct_return ()
1010{
4697a36c
MM
1011 if (reload_completed)
1012 {
1013 rs6000_stack_t *info = rs6000_stack_info ();
1014
1015 if (info->first_gp_reg_save == 32
1016 && info->first_fp_reg_save == 64
00b960c7 1017 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1018 && ! info->lr_save_p
1019 && ! info->cr_save_p
00b960c7 1020 && info->vrsave_mask == 0
c81fc13e 1021 && ! info->push_p)
4697a36c
MM
1022 return 1;
1023 }
1024
1025 return 0;
9878760c
RK
1026}
1027
1028/* Returns 1 always. */
1029
1030int
1031any_operand (op, mode)
592696dd 1032 rtx op ATTRIBUTE_UNUSED;
296b8152 1033 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
1034{
1035 return 1;
1036}
1037
a4f6c312 1038/* Returns 1 if op is the count register. */
38c1f2d7 1039int
a4f6c312 1040count_register_operand (op, mode)
592696dd 1041 rtx op;
296b8152 1042 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
1043{
1044 if (GET_CODE (op) != REG)
1045 return 0;
1046
1047 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1048 return 1;
1049
1050 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1051 return 1;
1052
1053 return 0;
1054}
1055
0ec4e2a8
AH
1056/* Returns 1 if op is an altivec register. */
1057int
1058altivec_register_operand (op, mode)
1059 rtx op;
1060 enum machine_mode mode ATTRIBUTE_UNUSED;
1061{
1062
1063 return (register_operand (op, mode)
1064 && (GET_CODE (op) != REG
1065 || REGNO (op) > FIRST_PSEUDO_REGISTER
1066 || ALTIVEC_REGNO_P (REGNO (op))));
1067}
1068
38c1f2d7 1069int
a4f6c312 1070xer_operand (op, mode)
592696dd 1071 rtx op;
296b8152 1072 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
1073{
1074 if (GET_CODE (op) != REG)
1075 return 0;
1076
9ebbca7d 1077 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1078 return 1;
1079
802a0058
MM
1080 return 0;
1081}
1082
c859cda6 1083/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1084 by such constants completes more quickly. */
c859cda6
DJ
1085
1086int
1087s8bit_cint_operand (op, mode)
1088 rtx op;
1089 enum machine_mode mode ATTRIBUTE_UNUSED;
1090{
1091 return ( GET_CODE (op) == CONST_INT
1092 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1093}
1094
9878760c
RK
1095/* Return 1 if OP is a constant that can fit in a D field. */
1096
1097int
1098short_cint_operand (op, mode)
592696dd 1099 rtx op;
296b8152 1100 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1101{
5f59ecb7
DE
1102 return (GET_CODE (op) == CONST_INT
1103 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1104}
1105
5519a4f9 1106/* Similar for an unsigned D field. */
9878760c
RK
1107
1108int
1109u_short_cint_operand (op, mode)
592696dd 1110 rtx op;
296b8152 1111 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1112{
19684119 1113 return (GET_CODE (op) == CONST_INT
c1f11548 1114 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1115}
1116
dcfedcd0
RK
1117/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1118
1119int
1120non_short_cint_operand (op, mode)
592696dd 1121 rtx op;
296b8152 1122 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1123{
1124 return (GET_CODE (op) == CONST_INT
a7653a2c 1125 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1126}
1127
2bfcf297
DB
1128/* Returns 1 if OP is a CONST_INT that is a positive value
1129 and an exact power of 2. */
1130
1131int
1132exact_log2_cint_operand (op, mode)
592696dd 1133 rtx op;
2bfcf297
DB
1134 enum machine_mode mode ATTRIBUTE_UNUSED;
1135{
1136 return (GET_CODE (op) == CONST_INT
1137 && INTVAL (op) > 0
1138 && exact_log2 (INTVAL (op)) >= 0);
1139}
1140
9878760c
RK
1141/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1142 ctr, or lr). */
1143
1144int
cd2b37d9 1145gpc_reg_operand (op, mode)
592696dd 1146 rtx op;
9878760c
RK
1147 enum machine_mode mode;
1148{
1149 return (register_operand (op, mode)
802a0058 1150 && (GET_CODE (op) != REG
9ebbca7d
GK
1151 || (REGNO (op) >= ARG_POINTER_REGNUM
1152 && !XER_REGNO_P (REGNO (op)))
1153 || REGNO (op) < MQ_REGNO));
9878760c
RK
1154}
1155
1156/* Returns 1 if OP is either a pseudo-register or a register denoting a
1157 CR field. */
1158
1159int
1160cc_reg_operand (op, mode)
592696dd 1161 rtx op;
9878760c
RK
1162 enum machine_mode mode;
1163{
1164 return (register_operand (op, mode)
1165 && (GET_CODE (op) != REG
1166 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1167 || CR_REGNO_P (REGNO (op))));
1168}
1169
815cdc52
MM
1170/* Returns 1 if OP is either a pseudo-register or a register denoting a
1171 CR field that isn't CR0. */
1172
1173int
1174cc_reg_not_cr0_operand (op, mode)
592696dd 1175 rtx op;
815cdc52
MM
1176 enum machine_mode mode;
1177{
1178 return (register_operand (op, mode)
1179 && (GET_CODE (op) != REG
1180 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1181 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1182}
1183
a4f6c312
SS
1184/* Returns 1 if OP is either a constant integer valid for a D-field or
1185 a non-special register. If a register, it must be in the proper
1186 mode unless MODE is VOIDmode. */
9878760c
RK
1187
1188int
1189reg_or_short_operand (op, mode)
592696dd 1190 rtx op;
9878760c
RK
1191 enum machine_mode mode;
1192{
f5a28898 1193 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1194}
1195
a4f6c312
SS
1196/* Similar, except check if the negation of the constant would be
1197 valid for a D-field. */
9878760c
RK
1198
1199int
1200reg_or_neg_short_operand (op, mode)
592696dd 1201 rtx op;
9878760c
RK
1202 enum machine_mode mode;
1203{
1204 if (GET_CODE (op) == CONST_INT)
1205 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1206
cd2b37d9 1207 return gpc_reg_operand (op, mode);
9878760c
RK
1208}
1209
768070a0
TR
1210/* Returns 1 if OP is either a constant integer valid for a DS-field or
1211 a non-special register. If a register, it must be in the proper
1212 mode unless MODE is VOIDmode. */
1213
1214int
1215reg_or_aligned_short_operand (op, mode)
1216 rtx op;
1217 enum machine_mode mode;
1218{
1219 if (gpc_reg_operand (op, mode))
1220 return 1;
1221 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1222 return 1;
1223
1224 return 0;
1225}
1226
1227
a4f6c312
SS
1228/* Return 1 if the operand is either a register or an integer whose
1229 high-order 16 bits are zero. */
9878760c
RK
1230
1231int
1232reg_or_u_short_operand (op, mode)
592696dd 1233 rtx op;
9878760c
RK
1234 enum machine_mode mode;
1235{
e675f625 1236 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1237}
1238
1239/* Return 1 is the operand is either a non-special register or ANY
1240 constant integer. */
1241
1242int
1243reg_or_cint_operand (op, mode)
592696dd 1244 rtx op;
9878760c
RK
1245 enum machine_mode mode;
1246{
a4f6c312 1247 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1248}
1249
1250/* Return 1 is the operand is either a non-special register or ANY
1251 32-bit signed constant integer. */
1252
1253int
1254reg_or_arith_cint_operand (op, mode)
592696dd 1255 rtx op;
f6bf7de2
DE
1256 enum machine_mode mode;
1257{
a4f6c312
SS
1258 return (gpc_reg_operand (op, mode)
1259 || (GET_CODE (op) == CONST_INT
f6bf7de2 1260#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1261 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1262 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1263#endif
a4f6c312 1264 ));
9878760c
RK
1265}
1266
2bfcf297
DB
1267/* Return 1 is the operand is either a non-special register or a 32-bit
1268 signed constant integer valid for 64-bit addition. */
1269
1270int
1271reg_or_add_cint64_operand (op, mode)
592696dd 1272 rtx op;
2bfcf297
DB
1273 enum machine_mode mode;
1274{
a4f6c312
SS
1275 return (gpc_reg_operand (op, mode)
1276 || (GET_CODE (op) == CONST_INT
a65c591c 1277#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1278 && INTVAL (op) < 0x7fff8000
a65c591c 1279#else
a4f6c312
SS
1280 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1281 < 0x100000000ll)
2bfcf297 1282#endif
a4f6c312 1283 ));
2bfcf297
DB
1284}
1285
1286/* Return 1 is the operand is either a non-special register or a 32-bit
1287 signed constant integer valid for 64-bit subtraction. */
1288
1289int
1290reg_or_sub_cint64_operand (op, mode)
592696dd 1291 rtx op;
2bfcf297
DB
1292 enum machine_mode mode;
1293{
a4f6c312
SS
1294 return (gpc_reg_operand (op, mode)
1295 || (GET_CODE (op) == CONST_INT
a65c591c 1296#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1297 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1298#else
a4f6c312
SS
1299 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1300 < 0x100000000ll)
2bfcf297 1301#endif
a4f6c312 1302 ));
2bfcf297
DB
1303}
1304
9ebbca7d
GK
1305/* Return 1 is the operand is either a non-special register or ANY
1306 32-bit unsigned constant integer. */
1307
1308int
1d328b19 1309reg_or_logical_cint_operand (op, mode)
592696dd 1310 rtx op;
9ebbca7d
GK
1311 enum machine_mode mode;
1312{
1d328b19
GK
1313 if (GET_CODE (op) == CONST_INT)
1314 {
1315 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1316 {
1317 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1318 abort ();
1d328b19
GK
1319
1320 if (INTVAL (op) < 0)
1321 return 0;
1322 }
1323
1324 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1325 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1326 }
1327 else if (GET_CODE (op) == CONST_DOUBLE)
1328 {
1329 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1330 || mode != DImode)
a4f6c312 1331 abort ();
1d328b19
GK
1332
1333 return CONST_DOUBLE_HIGH (op) == 0;
1334 }
1335 else
1336 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1337}
1338
51d3e7d6 1339/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1340
1341int
1342got_operand (op, mode)
592696dd 1343 rtx op;
296b8152 1344 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
1345{
1346 return (GET_CODE (op) == SYMBOL_REF
1347 || GET_CODE (op) == CONST
1348 || GET_CODE (op) == LABEL_REF);
1349}
1350
38c1f2d7
MM
1351/* Return 1 if the operand is a simple references that can be loaded via
1352 the GOT (labels involving addition aren't allowed). */
1353
1354int
1355got_no_const_operand (op, mode)
592696dd 1356 rtx op;
296b8152 1357 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
1358{
1359 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1360}
1361
4e74d8ec
MM
1362/* Return the number of instructions it takes to form a constant in an
1363 integer register. */
1364
1365static int
1366num_insns_constant_wide (value)
1367 HOST_WIDE_INT value;
1368{
1369 /* signed constant loadable with {cal|addi} */
5f59ecb7 1370 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1371 return 1;
1372
4e74d8ec 1373 /* constant loadable with {cau|addis} */
5f59ecb7 1374 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1375 return 1;
1376
5f59ecb7 1377#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1378 else if (TARGET_POWERPC64)
4e74d8ec 1379 {
a65c591c
DE
1380 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1381 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1382
a65c591c 1383 if (high == 0 || high == -1)
4e74d8ec
MM
1384 return 2;
1385
a65c591c 1386 high >>= 1;
4e74d8ec 1387
a65c591c 1388 if (low == 0)
4e74d8ec 1389 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1390 else
1391 return (num_insns_constant_wide (high)
e396202a 1392 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1393 }
1394#endif
1395
1396 else
1397 return 2;
1398}
1399
1400int
1401num_insns_constant (op, mode)
1402 rtx op;
1403 enum machine_mode mode;
1404{
4e74d8ec 1405 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1406 {
1407#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1408 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1409 && mask64_operand (op, mode))
0d30d435
DE
1410 return 2;
1411 else
1412#endif
1413 return num_insns_constant_wide (INTVAL (op));
1414 }
4e74d8ec 1415
6fc48950
MM
1416 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1417 {
1418 long l;
1419 REAL_VALUE_TYPE rv;
1420
1421 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1422 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1423 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1424 }
1425
47ad8c61 1426 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1427 {
47ad8c61
MM
1428 HOST_WIDE_INT low;
1429 HOST_WIDE_INT high;
1430 long l[2];
1431 REAL_VALUE_TYPE rv;
1432 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1433
47ad8c61
MM
1434 if (mode == VOIDmode || mode == DImode)
1435 {
1436 high = CONST_DOUBLE_HIGH (op);
1437 low = CONST_DOUBLE_LOW (op);
1438 }
1439 else
1440 {
1441 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1442 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1443 high = l[endian];
1444 low = l[1 - endian];
1445 }
4e74d8ec 1446
47ad8c61
MM
1447 if (TARGET_32BIT)
1448 return (num_insns_constant_wide (low)
1449 + num_insns_constant_wide (high));
4e74d8ec
MM
1450
1451 else
47ad8c61 1452 {
e72247f4 1453 if (high == 0 && low >= 0)
47ad8c61
MM
1454 return num_insns_constant_wide (low);
1455
e72247f4 1456 else if (high == -1 && low < 0)
47ad8c61
MM
1457 return num_insns_constant_wide (low);
1458
a260abc9
DE
1459 else if (mask64_operand (op, mode))
1460 return 2;
1461
47ad8c61
MM
1462 else if (low == 0)
1463 return num_insns_constant_wide (high) + 1;
1464
1465 else
1466 return (num_insns_constant_wide (high)
1467 + num_insns_constant_wide (low) + 1);
1468 }
4e74d8ec
MM
1469 }
1470
1471 else
1472 abort ();
1473}
1474
a4f6c312
SS
1475/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1476 register with one instruction per word. We only do this if we can
1477 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1478
1479int
1480easy_fp_constant (op, mode)
592696dd
SS
1481 rtx op;
1482 enum machine_mode mode;
9878760c 1483{
9878760c
RK
1484 if (GET_CODE (op) != CONST_DOUBLE
1485 || GET_MODE (op) != mode
4e74d8ec 1486 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1487 return 0;
1488
a4f6c312 1489 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1490 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1491 && mode != DImode)
b6c9286a
MM
1492 return 1;
1493
a4f6c312 1494 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1495 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1496 return 0;
1497
5ae4759c 1498#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1499 /* Similarly if we are using -mrelocatable, consider all constants
1500 to be hard. */
5ae4759c
MM
1501 if (TARGET_RELOCATABLE)
1502 return 0;
1503#endif
1504
fcce224d
DE
1505 if (mode == TFmode)
1506 {
1507 long k[4];
1508 REAL_VALUE_TYPE rv;
1509
1510 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1511 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1512
1513 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1514 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1515 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1516 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1517 }
1518
1519 else if (mode == DFmode)
042259f2
DE
1520 {
1521 long k[2];
1522 REAL_VALUE_TYPE rv;
1523
1524 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1525 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1526
a65c591c
DE
1527 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1528 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1529 }
4e74d8ec
MM
1530
1531 else if (mode == SFmode)
042259f2
DE
1532 {
1533 long l;
1534 REAL_VALUE_TYPE rv;
1535
1536 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1537 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1538
4e74d8ec 1539 return num_insns_constant_wide (l) == 1;
042259f2 1540 }
4e74d8ec 1541
a260abc9 1542 else if (mode == DImode)
c81fc13e 1543 return ((TARGET_POWERPC64
a260abc9
DE
1544 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1545 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1546
a9098fd0
GK
1547 else if (mode == SImode)
1548 return 1;
4e74d8ec
MM
1549 else
1550 abort ();
9878760c 1551}
8f75773e 1552
72ac76be 1553/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1554
1555static int
d744e06e
AH
1556easy_vector_same (op, mode)
1557 rtx op;
1558 enum machine_mode mode ATTRIBUTE_UNUSED;
1559{
1560 int units, i, cst;
1561
1562 units = CONST_VECTOR_NUNITS (op);
1563
1564 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1565 for (i = 1; i < units; ++i)
1566 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1567 break;
1568 if (i == units)
1569 return 1;
1570 return 0;
1571}
1572
1573/* Return 1 if the operand is a CONST_INT and can be put into a
1574 register without using memory. */
1575
1576int
1577easy_vector_constant (op, mode)
69ef87e2 1578 rtx op;
d744e06e 1579 enum machine_mode mode;
69ef87e2 1580{
d744e06e 1581 int cst, cst2;
69ef87e2 1582
d744e06e
AH
1583 if (GET_CODE (op) != CONST_VECTOR
1584 || (!TARGET_ALTIVEC
1585 && !TARGET_SPE))
69ef87e2
AH
1586 return 0;
1587
d744e06e
AH
1588 if (zero_constant (op, mode)
1589 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1590 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1591 return 1;
69ef87e2 1592
d744e06e
AH
1593 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1594 return 0;
1595
f5119d10
AH
1596 if (TARGET_SPE && mode == V1DImode)
1597 return 0;
1598
d744e06e
AH
1599 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1600 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1601
1602 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1603 li r0, CONSTANT1
1604 evmergelo r0, r0, r0
1605 li r0, CONSTANT2
1606
1607 I don't know how efficient it would be to allow bigger constants,
1608 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1609 instructions is better than a 64-bit memory load, but I don't
1610 have the e500 timing specs. */
1611 if (TARGET_SPE && mode == V2SImode
1612 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1613 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1614 return 1;
1615
1616 if (TARGET_ALTIVEC && EASY_VECTOR_15 (cst, op, mode))
1617 return 1;
1618
1619 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1620 return 1;
1621
1622 return 0;
1623}
1624
1625/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1626
1627int
1628easy_vector_constant_add_self (op, mode)
1629 rtx op;
1630 enum machine_mode mode;
1631{
1632 int cst;
1633
1634 if (!easy_vector_constant (op, mode))
1635 return 0;
1636
1637 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1638
1639 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1640}
1641
1642const char *
1643output_vec_const_move (operands)
1644 rtx *operands;
1645{
1646 int cst, cst2;
1647 enum machine_mode mode;
1648 rtx dest, vec;
1649
1650 dest = operands[0];
1651 vec = operands[1];
69ef87e2 1652
d744e06e
AH
1653 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1654 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1655 mode = GET_MODE (dest);
69ef87e2 1656
d744e06e
AH
1657 if (TARGET_ALTIVEC)
1658 {
1659 if (zero_constant (vec, mode))
1660 return "vxor %0,%0,%0";
1661 else if (EASY_VECTOR_15 (cst, vec, mode))
98ef3137 1662 {
d744e06e
AH
1663 operands[1] = GEN_INT (cst);
1664 switch (mode)
1665 {
1666 case V4SImode:
1667 return "vspltisw %0,%1";
1668 case V8HImode:
1669 return "vspltish %0,%1";
1670 case V16QImode:
1671 return "vspltisb %0,%1";
1672 default:
1673 abort ();
1674 }
98ef3137 1675 }
d744e06e
AH
1676 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1677 return "#";
1678 else
1679 abort ();
69ef87e2
AH
1680 }
1681
d744e06e
AH
1682 if (TARGET_SPE)
1683 {
1684 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1685 pattern of V1DI, V4HI, and V2SF.
1686
c1207243 1687 FIXME: We should probably return # and add post reload
d744e06e
AH
1688 splitters for these, but this way is so easy ;-).
1689 */
1690 operands[1] = GEN_INT (cst);
1691 operands[2] = GEN_INT (cst2);
1692 if (cst == cst2)
1693 return "li %0,%1\n\tevmergelo %0,%0,%0";
1694 else
1695 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1696 }
1697
1698 abort ();
69ef87e2
AH
1699}
1700
1701/* Return 1 if the operand is the constant 0. This works for scalars
1702 as well as vectors. */
1703int
1704zero_constant (op, mode)
1705 rtx op;
1706 enum machine_mode mode;
1707{
1708 return op == CONST0_RTX (mode);
1709}
1710
50a0b056
GK
1711/* Return 1 if the operand is 0.0. */
1712int
1713zero_fp_constant (op, mode)
592696dd
SS
1714 rtx op;
1715 enum machine_mode mode;
50a0b056
GK
1716{
1717 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1718}
1719
a4f6c312
SS
1720/* Return 1 if the operand is in volatile memory. Note that during
1721 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1722 volatile memory references. So this function allows us to
1723 recognize volatile references where its safe. */
1724
1725int
1726volatile_mem_operand (op, mode)
592696dd 1727 rtx op;
b6c9286a
MM
1728 enum machine_mode mode;
1729{
1730 if (GET_CODE (op) != MEM)
1731 return 0;
1732
1733 if (!MEM_VOLATILE_P (op))
1734 return 0;
1735
1736 if (mode != GET_MODE (op))
1737 return 0;
1738
1739 if (reload_completed)
1740 return memory_operand (op, mode);
1741
1742 if (reload_in_progress)
1743 return strict_memory_address_p (mode, XEXP (op, 0));
1744
1745 return memory_address_p (mode, XEXP (op, 0));
1746}
1747
97f6e72f 1748/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1749
1750int
97f6e72f 1751offsettable_mem_operand (op, mode)
592696dd 1752 rtx op;
914c2e77
RK
1753 enum machine_mode mode;
1754{
97f6e72f 1755 return ((GET_CODE (op) == MEM)
677a9668 1756 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1757 mode, XEXP (op, 0)));
914c2e77
RK
1758}
1759
9878760c
RK
1760/* Return 1 if the operand is either an easy FP constant (see above) or
1761 memory. */
1762
1763int
1764mem_or_easy_const_operand (op, mode)
592696dd 1765 rtx op;
9878760c
RK
1766 enum machine_mode mode;
1767{
1768 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1769}
1770
1771/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1772 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1773
1774int
1775add_operand (op, mode)
592696dd 1776 rtx op;
9878760c
RK
1777 enum machine_mode mode;
1778{
2bfcf297 1779 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1780 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1781 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1782
1783 return gpc_reg_operand (op, mode);
9878760c
RK
1784}
1785
dcfedcd0
RK
1786/* Return 1 if OP is a constant but not a valid add_operand. */
1787
1788int
1789non_add_cint_operand (op, mode)
592696dd 1790 rtx op;
296b8152 1791 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1792{
1793 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1794 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1795 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1796}
1797
9878760c
RK
1798/* Return 1 if the operand is a non-special register or a constant that
1799 can be used as the operand of an OR or XOR insn on the RS/6000. */
1800
1801int
1802logical_operand (op, mode)
592696dd 1803 rtx op;
9878760c
RK
1804 enum machine_mode mode;
1805{
40501e5f 1806 HOST_WIDE_INT opl, oph;
1d328b19 1807
dfbdccdb
GK
1808 if (gpc_reg_operand (op, mode))
1809 return 1;
1d328b19 1810
dfbdccdb 1811 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1812 {
1813 opl = INTVAL (op) & GET_MODE_MASK (mode);
1814
1815#if HOST_BITS_PER_WIDE_INT <= 32
1816 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1817 return 0;
1818#endif
1819 }
dfbdccdb
GK
1820 else if (GET_CODE (op) == CONST_DOUBLE)
1821 {
1d328b19 1822 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1823 abort ();
1d328b19
GK
1824
1825 opl = CONST_DOUBLE_LOW (op);
1826 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1827 if (oph != 0)
38886f37 1828 return 0;
dfbdccdb
GK
1829 }
1830 else
1831 return 0;
1d328b19 1832
40501e5f
AM
1833 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1834 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1835}
1836
dcfedcd0 1837/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1838 above), but could be split into one. */
dcfedcd0
RK
1839
1840int
1841non_logical_cint_operand (op, mode)
592696dd 1842 rtx op;
5f59ecb7 1843 enum machine_mode mode;
dcfedcd0 1844{
dfbdccdb 1845 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1846 && ! logical_operand (op, mode)
1847 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1848}
1849
19ba8161 1850/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1851 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1852 Reject all ones and all zeros, since these should have been optimized
1853 away and confuse the making of MB and ME. */
1854
1855int
19ba8161 1856mask_operand (op, mode)
592696dd 1857 rtx op;
19ba8161 1858 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1859{
02071907 1860 HOST_WIDE_INT c, lsb;
9878760c 1861
19ba8161
DE
1862 if (GET_CODE (op) != CONST_INT)
1863 return 0;
1864
1865 c = INTVAL (op);
1866
57deb3a1
AM
1867 /* Fail in 64-bit mode if the mask wraps around because the upper
1868 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1869 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1870 return 0;
1871
c5059423
AM
1872 /* We don't change the number of transitions by inverting,
1873 so make sure we start with the LS bit zero. */
1874 if (c & 1)
1875 c = ~c;
1876
1877 /* Reject all zeros or all ones. */
1878 if (c == 0)
9878760c
RK
1879 return 0;
1880
c5059423
AM
1881 /* Find the first transition. */
1882 lsb = c & -c;
1883
1884 /* Invert to look for a second transition. */
1885 c = ~c;
9878760c 1886
c5059423
AM
1887 /* Erase first transition. */
1888 c &= -lsb;
9878760c 1889
c5059423
AM
1890 /* Find the second transition (if any). */
1891 lsb = c & -c;
1892
1893 /* Match if all the bits above are 1's (or c is zero). */
1894 return c == -lsb;
9878760c
RK
1895}
1896
0ba1b2ff
AM
1897/* Return 1 for the PowerPC64 rlwinm corner case. */
1898
1899int
1900mask_operand_wrap (op, mode)
1901 rtx op;
1902 enum machine_mode mode ATTRIBUTE_UNUSED;
1903{
1904 HOST_WIDE_INT c, lsb;
1905
1906 if (GET_CODE (op) != CONST_INT)
1907 return 0;
1908
1909 c = INTVAL (op);
1910
1911 if ((c & 0x80000001) != 0x80000001)
1912 return 0;
1913
1914 c = ~c;
1915 if (c == 0)
1916 return 0;
1917
1918 lsb = c & -c;
1919 c = ~c;
1920 c &= -lsb;
1921 lsb = c & -c;
1922 return c == -lsb;
1923}
1924
a260abc9
DE
1925/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1926 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
1927 Reject all zeros, since zero should have been optimized away and
1928 confuses the making of MB and ME. */
9878760c
RK
1929
1930int
a260abc9 1931mask64_operand (op, mode)
592696dd 1932 rtx op;
0ba1b2ff 1933 enum machine_mode mode ATTRIBUTE_UNUSED;
a260abc9
DE
1934{
1935 if (GET_CODE (op) == CONST_INT)
1936 {
02071907 1937 HOST_WIDE_INT c, lsb;
a260abc9 1938
c5059423 1939 c = INTVAL (op);
a260abc9 1940
0ba1b2ff 1941 /* Reject all zeros. */
c5059423 1942 if (c == 0)
e2c953b6
DE
1943 return 0;
1944
0ba1b2ff
AM
1945 /* We don't change the number of transitions by inverting,
1946 so make sure we start with the LS bit zero. */
1947 if (c & 1)
1948 c = ~c;
1949
c5059423
AM
1950 /* Find the transition, and check that all bits above are 1's. */
1951 lsb = c & -c;
e3981aab
DE
1952
1953 /* Match if all the bits above are 1's (or c is zero). */
c5059423 1954 return c == -lsb;
e2c953b6 1955 }
0ba1b2ff
AM
1956 return 0;
1957}
1958
1959/* Like mask64_operand, but allow up to three transitions. This
1960 predicate is used by insn patterns that generate two rldicl or
1961 rldicr machine insns. */
1962
1963int
1964mask64_2_operand (op, mode)
1965 rtx op;
1966 enum machine_mode mode ATTRIBUTE_UNUSED;
1967{
1968 if (GET_CODE (op) == CONST_INT)
a260abc9 1969 {
0ba1b2ff 1970 HOST_WIDE_INT c, lsb;
a260abc9 1971
0ba1b2ff 1972 c = INTVAL (op);
a260abc9 1973
0ba1b2ff
AM
1974 /* Disallow all zeros. */
1975 if (c == 0)
1976 return 0;
a260abc9 1977
0ba1b2ff
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;
a260abc9 1982
0ba1b2ff
AM
1983 /* Find the first transition. */
1984 lsb = c & -c;
a260abc9 1985
0ba1b2ff
AM
1986 /* Invert to look for a second transition. */
1987 c = ~c;
1988
1989 /* Erase first transition. */
1990 c &= -lsb;
1991
1992 /* Find the second transition. */
1993 lsb = c & -c;
1994
1995 /* Invert to look for a third transition. */
1996 c = ~c;
1997
1998 /* Erase second transition. */
1999 c &= -lsb;
2000
2001 /* Find the third transition (if any). */
2002 lsb = c & -c;
2003
2004 /* Match if all the bits above are 1's (or c is zero). */
2005 return c == -lsb;
2006 }
2007 return 0;
2008}
2009
2010/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2011 implement ANDing by the mask IN. */
2012void
2013build_mask64_2_operands (in, out)
2014 rtx in;
2015 rtx *out;
2016{
2017#if HOST_BITS_PER_WIDE_INT >= 64
2018 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2019 int shift;
2020
2021 if (GET_CODE (in) != CONST_INT)
2022 abort ();
2023
2024 c = INTVAL (in);
2025 if (c & 1)
2026 {
2027 /* Assume c initially something like 0x00fff000000fffff. The idea
2028 is to rotate the word so that the middle ^^^^^^ group of zeros
2029 is at the MS end and can be cleared with an rldicl mask. We then
2030 rotate back and clear off the MS ^^ group of zeros with a
2031 second rldicl. */
2032 c = ~c; /* c == 0xff000ffffff00000 */
2033 lsb = c & -c; /* lsb == 0x0000000000100000 */
2034 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2035 c = ~c; /* c == 0x00fff000000fffff */
2036 c &= -lsb; /* c == 0x00fff00000000000 */
2037 lsb = c & -c; /* lsb == 0x0000100000000000 */
2038 c = ~c; /* c == 0xff000fffffffffff */
2039 c &= -lsb; /* c == 0xff00000000000000 */
2040 shift = 0;
2041 while ((lsb >>= 1) != 0)
2042 shift++; /* shift == 44 on exit from loop */
2043 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2044 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2045 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2046 }
2047 else
0ba1b2ff
AM
2048 {
2049 /* Assume c initially something like 0xff000f0000000000. The idea
2050 is to rotate the word so that the ^^^ middle group of zeros
2051 is at the LS end and can be cleared with an rldicr mask. We then
2052 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2053 a second rldicr. */
2054 lsb = c & -c; /* lsb == 0x0000010000000000 */
2055 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2056 c = ~c; /* c == 0x00fff0ffffffffff */
2057 c &= -lsb; /* c == 0x00fff00000000000 */
2058 lsb = c & -c; /* lsb == 0x0000100000000000 */
2059 c = ~c; /* c == 0xff000fffffffffff */
2060 c &= -lsb; /* c == 0xff00000000000000 */
2061 shift = 0;
2062 while ((lsb >>= 1) != 0)
2063 shift++; /* shift == 44 on exit from loop */
2064 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2065 m1 >>= shift; /* m1 == 0x0000000000000fff */
2066 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2067 }
2068
2069 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2070 masks will be all 1's. We are guaranteed more than one transition. */
2071 out[0] = GEN_INT (64 - shift);
2072 out[1] = GEN_INT (m1);
2073 out[2] = GEN_INT (shift);
2074 out[3] = GEN_INT (m2);
2075#else
045572c7
GK
2076 (void)in;
2077 (void)out;
0ba1b2ff
AM
2078 abort ();
2079#endif
a260abc9
DE
2080}
2081
2082/* Return 1 if the operand is either a non-special register or a constant
2083 that can be used as the operand of a PowerPC64 logical AND insn. */
2084
2085int
2086and64_operand (op, mode)
592696dd 2087 rtx op;
9878760c
RK
2088 enum machine_mode mode;
2089{
a4f6c312 2090 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2091 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2092
2093 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2094}
2095
0ba1b2ff
AM
2096/* Like the above, but also match constants that can be implemented
2097 with two rldicl or rldicr insns. */
2098
2099int
2100and64_2_operand (op, mode)
2101 rtx op;
2102 enum machine_mode mode;
2103{
2104 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
2105 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2106
2107 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2108}
2109
a260abc9
DE
2110/* Return 1 if the operand is either a non-special register or a
2111 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2112
2113int
a260abc9 2114and_operand (op, mode)
592696dd 2115 rtx op;
a260abc9 2116 enum machine_mode mode;
dcfedcd0 2117{
a4f6c312 2118 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2119 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2120
2121 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2122}
2123
9878760c
RK
2124/* Return 1 if the operand is a general register or memory operand. */
2125
2126int
2127reg_or_mem_operand (op, mode)
592696dd
SS
2128 rtx op;
2129 enum machine_mode mode;
9878760c 2130{
b6c9286a
MM
2131 return (gpc_reg_operand (op, mode)
2132 || memory_operand (op, mode)
2133 || volatile_mem_operand (op, mode));
9878760c
RK
2134}
2135
a7a813f7 2136/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2137 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2138 instruction. */
2139
2140int
2141lwa_operand (op, mode)
592696dd
SS
2142 rtx op;
2143 enum machine_mode mode;
a7a813f7
RK
2144{
2145 rtx inner = op;
2146
2147 if (reload_completed && GET_CODE (inner) == SUBREG)
2148 inner = SUBREG_REG (inner);
2149
2150 return gpc_reg_operand (inner, mode)
2151 || (memory_operand (inner, mode)
2152 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2153 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2154 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2155 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2156 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2157}
2158
cc4d5fec
JH
2159/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2160
2161int
2162symbol_ref_operand (op, mode)
2163 rtx op;
2164 enum machine_mode mode;
2165{
2166 if (mode != VOIDmode && GET_MODE (op) != mode)
2167 return 0;
2168
473f51b6
DE
2169 return (GET_CODE (op) == SYMBOL_REF
2170 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2171}
2172
9878760c 2173/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2174 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2175
2176int
2177call_operand (op, mode)
592696dd 2178 rtx op;
9878760c
RK
2179 enum machine_mode mode;
2180{
2181 if (mode != VOIDmode && GET_MODE (op) != mode)
2182 return 0;
2183
2184 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2185 || (GET_CODE (op) == REG
2186 && (REGNO (op) == LINK_REGISTER_REGNUM
2187 || REGNO (op) == COUNT_REGISTER_REGNUM
2188 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2189}
2190
2af3d377 2191/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2192 this file. */
2af3d377
RK
2193
2194int
2195current_file_function_operand (op, mode)
592696dd 2196 rtx op;
296b8152 2197 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377 2198{
473f51b6
DE
2199 return (GET_CODE (op) == SYMBOL_REF
2200 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2201 && (SYMBOL_REF_LOCAL_P (op)
2202 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2203}
2204
9878760c
RK
2205/* Return 1 if this operand is a valid input for a move insn. */
2206
2207int
2208input_operand (op, mode)
592696dd 2209 rtx op;
9878760c
RK
2210 enum machine_mode mode;
2211{
eb4e8003 2212 /* Memory is always valid. */
9878760c
RK
2213 if (memory_operand (op, mode))
2214 return 1;
2215
34792e82 2216 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2217 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2218 return 1;
2219
eb4e8003
RK
2220 /* For floating-point, easy constants are valid. */
2221 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2222 && CONSTANT_P (op)
2223 && easy_fp_constant (op, mode))
2224 return 1;
2225
4e74d8ec
MM
2226 /* Allow any integer constant. */
2227 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2228 && (GET_CODE (op) == CONST_INT
e675f625 2229 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2230 return 1;
2231
d744e06e
AH
2232 /* Allow easy vector constants. */
2233 if (GET_CODE (op) == CONST_VECTOR
2234 && easy_vector_constant (op, mode))
2235 return 1;
2236
eb4e8003
RK
2237 /* For floating-point or multi-word mode, the only remaining valid type
2238 is a register. */
9878760c
RK
2239 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2240 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2241 return register_operand (op, mode);
9878760c 2242
88fe15a1
RK
2243 /* The only cases left are integral modes one word or smaller (we
2244 do not get called for MODE_CC values). These can be in any
2245 register. */
2246 if (register_operand (op, mode))
a8b3aeda 2247 return 1;
88fe15a1 2248
84cf9dda 2249 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2250 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2251 return 1;
2252
9ebbca7d 2253 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2254 if (toc_relative_expr_p (op))
b6c9286a
MM
2255 return 1;
2256
88228c4b
MM
2257 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2258 to be valid. */
f607bc57 2259 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2260 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2261 && small_data_operand (op, Pmode))
2262 return 1;
2263
042259f2 2264 return 0;
9878760c 2265}
7509c759 2266
a4f6c312 2267/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2268
2269int
2270small_data_operand (op, mode)
296b8152
KG
2271 rtx op ATTRIBUTE_UNUSED;
2272 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 2273{
38c1f2d7 2274#if TARGET_ELF
5f59ecb7 2275 rtx sym_ref;
7509c759 2276
d9407988 2277 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2278 return 0;
a54d04b7 2279
f607bc57 2280 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2281 return 0;
2282
88228c4b
MM
2283 if (GET_CODE (op) == SYMBOL_REF)
2284 sym_ref = op;
2285
2286 else if (GET_CODE (op) != CONST
2287 || GET_CODE (XEXP (op, 0)) != PLUS
2288 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2289 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2290 return 0;
2291
88228c4b 2292 else
dbf55e53
MM
2293 {
2294 rtx sum = XEXP (op, 0);
2295 HOST_WIDE_INT summand;
2296
2297 /* We have to be careful here, because it is the referenced address
2298 that must be 32k from _SDA_BASE_, not just the symbol. */
2299 summand = INTVAL (XEXP (sum, 1));
307b599c 2300 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2301 return 0;
2302
2303 sym_ref = XEXP (sum, 0);
2304 }
88228c4b 2305
20bfcd69 2306 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2307#else
2308 return 0;
2309#endif
7509c759 2310}
46c07df8
HP
2311
2312/* Return 1 for all valid move insn operand combination involving altivec
2313 vectors in gprs. */
2314
2315int
2316altivec_in_gprs_p (rtx op0, rtx op1)
2317{
2318 if (REG_P (op0) && REGNO_REG_CLASS (REGNO (op0)) == GENERAL_REGS)
2319 return 1;
2320
2321 if (REG_P (op1) && REGNO_REG_CLASS (REGNO (op1)) == GENERAL_REGS)
2322 return 1;
2323 return 0;
2324}
2325
9ebbca7d 2326\f
4d588c14
RH
2327/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2328
9ebbca7d
GK
2329static int
2330constant_pool_expr_1 (op, have_sym, have_toc)
2331 rtx op;
2332 int *have_sym;
2333 int *have_toc;
2334{
2335 switch (GET_CODE(op))
2336 {
2337 case SYMBOL_REF:
c4501e62
JJ
2338 if (RS6000_SYMBOL_REF_TLS_P (op))
2339 return 0;
2340 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2341 {
2342 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2343 {
2344 *have_sym = 1;
2345 return 1;
2346 }
2347 else
2348 return 0;
2349 }
2350 else if (! strcmp (XSTR (op, 0), toc_label_name))
2351 {
2352 *have_toc = 1;
2353 return 1;
2354 }
2355 else
2356 return 0;
9ebbca7d
GK
2357 case PLUS:
2358 case MINUS:
c1f11548
DE
2359 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2360 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2361 case CONST:
a4f6c312 2362 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2363 case CONST_INT:
a4f6c312 2364 return 1;
9ebbca7d 2365 default:
a4f6c312 2366 return 0;
9ebbca7d
GK
2367 }
2368}
2369
4d588c14 2370static bool
9ebbca7d
GK
2371constant_pool_expr_p (op)
2372 rtx op;
2373{
2374 int have_sym = 0;
2375 int have_toc = 0;
2376 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2377}
2378
4d588c14 2379static bool
9ebbca7d
GK
2380toc_relative_expr_p (op)
2381 rtx op;
2382{
4d588c14
RH
2383 int have_sym = 0;
2384 int have_toc = 0;
2385 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2386}
2387
2388/* SPE offset addressing is limited to 5-bits worth of double words. */
2389#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2390
2391bool
2392legitimate_constant_pool_address_p (x)
2393 rtx x;
2394{
2395 return (TARGET_TOC
2396 && GET_CODE (x) == PLUS
2397 && GET_CODE (XEXP (x, 0)) == REG
2398 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2399 && constant_pool_expr_p (XEXP (x, 1)));
2400}
2401
2402static bool
2403legitimate_small_data_p (mode, x)
2404 enum machine_mode mode;
2405 rtx x;
2406{
2407 return (DEFAULT_ABI == ABI_V4
2408 && !flag_pic && !TARGET_TOC
2409 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2410 && small_data_operand (x, mode));
2411}
2412
2413static bool
2414legitimate_offset_address_p (mode, x, strict)
2415 enum machine_mode mode;
2416 rtx x;
2417 int strict;
2418{
2419 unsigned HOST_WIDE_INT offset, extra;
2420
2421 if (GET_CODE (x) != PLUS)
2422 return false;
2423 if (GET_CODE (XEXP (x, 0)) != REG)
2424 return false;
2425 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2426 return false;
2427 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2428 return false;
2429
2430 offset = INTVAL (XEXP (x, 1));
2431 extra = 0;
2432 switch (mode)
2433 {
2434 case V16QImode:
2435 case V8HImode:
2436 case V4SFmode:
2437 case V4SImode:
2438 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2439 which leaves the only valid constant offset of zero, which by
2440 canonicalization rules is also invalid. */
2441 return false;
2442
2443 case V4HImode:
2444 case V2SImode:
2445 case V1DImode:
2446 case V2SFmode:
2447 /* SPE vector modes. */
2448 return SPE_CONST_OFFSET_OK (offset);
2449
2450 case DFmode:
2451 case DImode:
2452 if (TARGET_32BIT)
2453 extra = 4;
2454 else if (offset & 3)
2455 return false;
2456 break;
2457
2458 case TFmode:
2459 case TImode:
2460 if (TARGET_32BIT)
2461 extra = 12;
2462 else if (offset & 3)
2463 return false;
2464 else
2465 extra = 8;
2466 break;
2467
2468 default:
2469 break;
2470 }
2471
2472 return (offset + extra >= offset) && (offset + extra + 0x8000 < 0x10000);
2473}
2474
2475static bool
2476legitimate_indexed_address_p (x, strict)
2477 rtx x;
2478 int strict;
2479{
2480 rtx op0, op1;
2481
2482 if (GET_CODE (x) != PLUS)
2483 return false;
2484 op0 = XEXP (x, 0);
2485 op1 = XEXP (x, 1);
2486
2487 if (!REG_P (op0) || !REG_P (op1))
2488 return false;
2489
2490 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2491 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2492 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2493 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2494}
2495
4d588c14
RH
2496static inline bool
2497legitimate_indirect_address_p (x, strict)
2498 rtx x;
2499 int strict;
2500{
2501 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2502}
2503
2504static bool
2505legitimate_lo_sum_address_p (mode, x, strict)
2506 enum machine_mode mode;
2507 rtx x;
2508 int strict;
2509{
2510 if (GET_CODE (x) != LO_SUM)
2511 return false;
2512 if (GET_CODE (XEXP (x, 0)) != REG)
2513 return false;
2514 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2515 return false;
2516 x = XEXP (x, 1);
2517
2518 if (TARGET_ELF)
2519 {
2520 if (DEFAULT_ABI != ABI_AIX && flag_pic)
2521 return false;
2522 if (TARGET_TOC)
2523 return false;
2524 if (GET_MODE_NUNITS (mode) != 1)
2525 return false;
2526 if (GET_MODE_BITSIZE (mode) > 32
2527 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2528 return false;
2529
2530 return CONSTANT_P (x);
2531 }
2532
2533 return false;
2534}
2535
2536
9ebbca7d
GK
2537/* Try machine-dependent ways of modifying an illegitimate address
2538 to be legitimate. If we find one, return the new, valid address.
2539 This is used from only one place: `memory_address' in explow.c.
2540
a4f6c312
SS
2541 OLDX is the address as it was before break_out_memory_refs was
2542 called. In some cases it is useful to look at this to decide what
2543 needs to be done.
9ebbca7d 2544
a4f6c312 2545 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2546
a4f6c312
SS
2547 It is always safe for this function to do nothing. It exists to
2548 recognize opportunities to optimize the output.
9ebbca7d
GK
2549
2550 On RS/6000, first check for the sum of a register with a constant
2551 integer that is out of range. If so, generate code to add the
2552 constant with the low-order 16 bits masked to the register and force
2553 this result into another register (this can be done with `cau').
2554 Then generate an address of REG+(CONST&0xffff), allowing for the
2555 possibility of bit 16 being a one.
2556
2557 Then check for the sum of a register and something not constant, try to
2558 load the other things into a register and return the sum. */
4d588c14 2559
9ebbca7d
GK
2560rtx
2561rs6000_legitimize_address (x, oldx, mode)
2562 rtx x;
2563 rtx oldx ATTRIBUTE_UNUSED;
2564 enum machine_mode mode;
0ac081f6 2565{
c4501e62
JJ
2566 if (GET_CODE (x) == SYMBOL_REF)
2567 {
2568 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2569 if (model != 0)
2570 return rs6000_legitimize_tls_address (x, model);
2571 }
2572
9ebbca7d
GK
2573 if (GET_CODE (x) == PLUS
2574 && GET_CODE (XEXP (x, 0)) == REG
2575 && GET_CODE (XEXP (x, 1)) == CONST_INT
2576 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2577 {
2578 HOST_WIDE_INT high_int, low_int;
2579 rtx sum;
a65c591c
DE
2580 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2581 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2582 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2583 GEN_INT (high_int)), 0);
2584 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2585 }
2586 else if (GET_CODE (x) == PLUS
2587 && GET_CODE (XEXP (x, 0)) == REG
2588 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2589 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2590 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2591 || TARGET_POWERPC64
fcce224d 2592 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2593 && (TARGET_POWERPC64 || mode != DImode)
2594 && mode != TImode)
2595 {
2596 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2597 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2598 }
0ac081f6
AH
2599 else if (ALTIVEC_VECTOR_MODE (mode))
2600 {
2601 rtx reg;
2602
2603 /* Make sure both operands are registers. */
2604 if (GET_CODE (x) == PLUS)
9f85ed45 2605 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2606 force_reg (Pmode, XEXP (x, 1)));
2607
2608 reg = force_reg (Pmode, x);
2609 return reg;
2610 }
a3170dc6
AH
2611 else if (SPE_VECTOR_MODE (mode))
2612 {
2613 /* We accept [reg + reg] and [reg + OFFSET]. */
2614
2615 if (GET_CODE (x) == PLUS)
2616 {
2617 rtx op1 = XEXP (x, 0);
2618 rtx op2 = XEXP (x, 1);
2619
2620 op1 = force_reg (Pmode, op1);
2621
2622 if (GET_CODE (op2) != REG
2623 && (GET_CODE (op2) != CONST_INT
2624 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2625 op2 = force_reg (Pmode, op2);
2626
2627 return gen_rtx_PLUS (Pmode, op1, op2);
2628 }
2629
2630 return force_reg (Pmode, x);
2631 }
f1384257
AM
2632 else if (TARGET_ELF
2633 && TARGET_32BIT
2634 && TARGET_NO_TOC
2635 && ! flag_pic
9ebbca7d
GK
2636 && GET_CODE (x) != CONST_INT
2637 && GET_CODE (x) != CONST_DOUBLE
2638 && CONSTANT_P (x)
6ac7bf2c
GK
2639 && GET_MODE_NUNITS (mode) == 1
2640 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2641 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2642 {
2643 rtx reg = gen_reg_rtx (Pmode);
2644 emit_insn (gen_elf_high (reg, (x)));
2645 return gen_rtx_LO_SUM (Pmode, reg, (x));
2646 }
ee890fe2
SS
2647 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2648 && ! flag_pic
ab82a49f
AP
2649#if TARGET_MACHO
2650 && ! MACHO_DYNAMIC_NO_PIC_P
2651#endif
ee890fe2
SS
2652 && GET_CODE (x) != CONST_INT
2653 && GET_CODE (x) != CONST_DOUBLE
2654 && CONSTANT_P (x)
a3170dc6 2655 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2656 && mode != DImode
2657 && mode != TImode)
2658 {
2659 rtx reg = gen_reg_rtx (Pmode);
2660 emit_insn (gen_macho_high (reg, (x)));
2661 return gen_rtx_LO_SUM (Pmode, reg, (x));
2662 }
9ebbca7d 2663 else if (TARGET_TOC
4d588c14 2664 && constant_pool_expr_p (x)
a9098fd0 2665 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2666 {
2667 return create_TOC_reference (x);
2668 }
2669 else
2670 return NULL_RTX;
2671}
258bfae2 2672
c4501e62
JJ
2673/* Construct the SYMBOL_REF for the tls_get_addr function. */
2674
2675static GTY(()) rtx rs6000_tls_symbol;
2676static rtx
2677rs6000_tls_get_addr ()
2678{
2679 if (!rs6000_tls_symbol)
2680 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2681
2682 return rs6000_tls_symbol;
2683}
2684
2685/* Construct the SYMBOL_REF for TLS GOT references. */
2686
2687static GTY(()) rtx rs6000_got_symbol;
2688static rtx
2689rs6000_got_sym ()
2690{
2691 if (!rs6000_got_symbol)
2692 {
2693 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2694 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2695 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2696 }
2697
2698 return rs6000_got_symbol;
2699}
2700
2701/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2702 this (thread-local) address. */
2703
2704static rtx
2705rs6000_legitimize_tls_address (addr, model)
2706 rtx addr;
2707 enum tls_model model;
2708{
2709 rtx dest, insn;
2710
2711 dest = gen_reg_rtx (Pmode);
2712 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2713 {
2714 rtx tlsreg;
2715
2716 if (TARGET_64BIT)
2717 {
2718 tlsreg = gen_rtx_REG (Pmode, 13);
2719 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2720 }
2721 else
2722 {
2723 tlsreg = gen_rtx_REG (Pmode, 2);
2724 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2725 }
2726 emit_insn (insn);
2727 }
2728 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2729 {
2730 rtx tlsreg, tmp;
2731
2732 tmp = gen_reg_rtx (Pmode);
2733 if (TARGET_64BIT)
2734 {
2735 tlsreg = gen_rtx_REG (Pmode, 13);
2736 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2737 }
2738 else
2739 {
2740 tlsreg = gen_rtx_REG (Pmode, 2);
2741 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2742 }
2743 emit_insn (insn);
2744 if (TARGET_64BIT)
2745 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2746 else
2747 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2748 emit_insn (insn);
2749 }
2750 else
2751 {
2752 rtx r3, got, tga, tmp1, tmp2, eqv;
2753
2754 if (TARGET_64BIT)
2755 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2756 else
2757 {
2758 if (flag_pic == 1)
2759 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2760 else
2761 {
2762 rtx gsym = rs6000_got_sym ();
2763 got = gen_reg_rtx (Pmode);
2764 if (flag_pic == 0)
2765 rs6000_emit_move (got, gsym, Pmode);
2766 else
2767 {
2768 char buf[30];
2769 static int tls_got_labelno = 0;
2770 rtx tempLR, lab, tmp3, mem;
2771 rtx first, last;
2772
2773 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2774 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2775 tempLR = gen_reg_rtx (Pmode);
2776 tmp1 = gen_reg_rtx (Pmode);
2777 tmp2 = gen_reg_rtx (Pmode);
2778 tmp3 = gen_reg_rtx (Pmode);
2779 mem = gen_rtx_MEM (Pmode, tmp1);
2780 RTX_UNCHANGING_P (mem) = 1;
2781
2782 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2783 gsym));
2784 emit_move_insn (tmp1, tempLR);
2785 emit_move_insn (tmp2, mem);
2786 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2787 last = emit_move_insn (got, tmp3);
2788 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2789 REG_NOTES (last));
2790 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2791 REG_NOTES (first));
2792 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2793 REG_NOTES (last));
2794 }
2795 }
2796 }
2797
2798 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2799 {
2800 r3 = gen_rtx_REG (Pmode, 3);
2801 if (TARGET_64BIT)
2802 insn = gen_tls_gd_64 (r3, got, addr);
2803 else
2804 insn = gen_tls_gd_32 (r3, got, addr);
2805 start_sequence ();
2806 emit_insn (insn);
2807 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2808 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2809 insn = emit_call_insn (insn);
2810 CONST_OR_PURE_CALL_P (insn) = 1;
2811 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2812 insn = get_insns ();
2813 end_sequence ();
2814 emit_libcall_block (insn, dest, r3, addr);
2815 }
2816 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2817 {
2818 r3 = gen_rtx_REG (Pmode, 3);
2819 if (TARGET_64BIT)
2820 insn = gen_tls_ld_64 (r3, got);
2821 else
2822 insn = gen_tls_ld_32 (r3, got);
2823 start_sequence ();
2824 emit_insn (insn);
2825 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2826 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2827 insn = emit_call_insn (insn);
2828 CONST_OR_PURE_CALL_P (insn) = 1;
2829 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2830 insn = get_insns ();
2831 end_sequence ();
2832 tmp1 = gen_reg_rtx (Pmode);
2833 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2834 UNSPEC_TLSLD);
2835 emit_libcall_block (insn, tmp1, r3, eqv);
2836 if (rs6000_tls_size == 16)
2837 {
2838 if (TARGET_64BIT)
2839 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
2840 else
2841 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
2842 }
2843 else if (rs6000_tls_size == 32)
2844 {
2845 tmp2 = gen_reg_rtx (Pmode);
2846 if (TARGET_64BIT)
2847 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
2848 else
2849 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
2850 emit_insn (insn);
2851 if (TARGET_64BIT)
2852 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
2853 else
2854 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
2855 }
2856 else
2857 {
2858 tmp2 = gen_reg_rtx (Pmode);
2859 if (TARGET_64BIT)
2860 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
2861 else
2862 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
2863 emit_insn (insn);
2864 insn = gen_rtx_SET (Pmode, dest,
2865 gen_rtx_PLUS (Pmode, tmp2, tmp1));
2866 }
2867 emit_insn (insn);
2868 }
2869 else
2870 {
2871 /* IE, or 64 bit offset LE. */
2872 tmp2 = gen_reg_rtx (Pmode);
2873 if (TARGET_64BIT)
2874 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
2875 else
2876 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
2877 emit_insn (insn);
2878 if (TARGET_64BIT)
2879 insn = gen_tls_tls_64 (dest, tmp2, addr);
2880 else
2881 insn = gen_tls_tls_32 (dest, tmp2, addr);
2882 emit_insn (insn);
2883 }
2884 }
2885
2886 return dest;
2887}
2888
2889/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
2890 instruction definitions. */
2891
2892int
2893rs6000_tls_symbol_ref (x, mode)
2894 rtx x;
2895 enum machine_mode mode ATTRIBUTE_UNUSED;
2896{
2897 return RS6000_SYMBOL_REF_TLS_P (x);
2898}
2899
2900/* Return 1 if X contains a thread-local symbol. */
2901
2902bool
2903rs6000_tls_referenced_p (x)
2904 rtx x;
2905{
2906 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
2907}
2908
2909/* Return 1 if *X is a thread-local symbol. This is the same as
2910 rs6000_tls_symbol_ref except for the type of the unused argument. */
2911
2912static inline int
2913rs6000_tls_symbol_ref_1 (x, data)
2914 rtx *x;
2915 void *data ATTRIBUTE_UNUSED;
2916{
2917 return RS6000_SYMBOL_REF_TLS_P (*x);
2918}
2919
24ea750e
DJ
2920/* The convention appears to be to define this wherever it is used.
2921 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2922 is now used here. */
2923#ifndef REG_MODE_OK_FOR_BASE_P
2924#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2925#endif
2926
2927/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2928 replace the input X, or the original X if no replacement is called for.
2929 The output parameter *WIN is 1 if the calling macro should goto WIN,
2930 0 if it should not.
2931
2932 For RS/6000, we wish to handle large displacements off a base
2933 register by splitting the addend across an addiu/addis and the mem insn.
2934 This cuts number of extra insns needed from 3 to 1.
2935
2936 On Darwin, we use this to generate code for floating point constants.
2937 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2938 The Darwin code is inside #if TARGET_MACHO because only then is
2939 machopic_function_base_name() defined. */
2940rtx
2941rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win)
2942 rtx x;
2943 enum machine_mode mode;
2944 int opnum;
2945 int type;
2946 int ind_levels ATTRIBUTE_UNUSED;
2947 int *win;
2948{
2949 /* We must recognize output that we have already generated ourselves. */
2950 if (GET_CODE (x) == PLUS
2951 && GET_CODE (XEXP (x, 0)) == PLUS
2952 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2953 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2954 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2955 {
2956 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2957 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2958 opnum, (enum reload_type)type);
2959 *win = 1;
2960 return x;
2961 }
3deb2758 2962
24ea750e
DJ
2963#if TARGET_MACHO
2964 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2965 && GET_CODE (x) == LO_SUM
2966 && GET_CODE (XEXP (x, 0)) == PLUS
2967 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2968 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2969 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2970 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2971 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2972 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2973 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2974 {
2975 /* Result of previous invocation of this function on Darwin
6f317ef3 2976 floating point constant. */
24ea750e
DJ
2977 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2978 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2979 opnum, (enum reload_type)type);
2980 *win = 1;
2981 return x;
2982 }
2983#endif
2984 if (GET_CODE (x) == PLUS
2985 && GET_CODE (XEXP (x, 0)) == REG
2986 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2987 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 2988 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 2989 && !SPE_VECTOR_MODE (mode)
78c875e8 2990 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
2991 {
2992 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2993 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2994 HOST_WIDE_INT high
2995 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2996
2997 /* Check for 32-bit overflow. */
2998 if (high + low != val)
2999 {
3000 *win = 0;
3001 return x;
3002 }
3003
3004 /* Reload the high part into a base reg; leave the low part
3005 in the mem directly. */
3006
3007 x = gen_rtx_PLUS (GET_MODE (x),
3008 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3009 GEN_INT (high)),
3010 GEN_INT (low));
3011
3012 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3013 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3014 opnum, (enum reload_type)type);
3015 *win = 1;
3016 return x;
3017 }
3018#if TARGET_MACHO
3019 if (GET_CODE (x) == SYMBOL_REF
3020 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3021 && !ALTIVEC_VECTOR_MODE (mode)
24ea750e
DJ
3022 && flag_pic)
3023 {
3024 /* Darwin load of floating point constant. */
3025 rtx offset = gen_rtx (CONST, Pmode,
3026 gen_rtx (MINUS, Pmode, x,
3027 gen_rtx (SYMBOL_REF, Pmode,
3028 machopic_function_base_name ())));
3029 x = gen_rtx (LO_SUM, GET_MODE (x),
3030 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
3031 gen_rtx (HIGH, Pmode, offset)), offset);
3032 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3033 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3034 opnum, (enum reload_type)type);
3035 *win = 1;
3036 return x;
3037 }
ab82a49f
AP
3038 if (GET_CODE (x) == SYMBOL_REF
3039 && DEFAULT_ABI == ABI_DARWIN
3040 && !ALTIVEC_VECTOR_MODE (mode)
3041 && MACHO_DYNAMIC_NO_PIC_P)
3042 {
3043 /* Darwin load of floating point constant. */
3044 x = gen_rtx (LO_SUM, GET_MODE (x),
3045 gen_rtx (HIGH, Pmode, x), x);
3046 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3047 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3048 opnum, (enum reload_type)type);
3049 *win = 1;
3050 return x;
3051 }
24ea750e
DJ
3052#endif
3053 if (TARGET_TOC
4d588c14 3054 && constant_pool_expr_p (x)
c1f11548 3055 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3056 {
3057 (x) = create_TOC_reference (x);
3058 *win = 1;
3059 return x;
3060 }
3061 *win = 0;
3062 return x;
3063}
3064
258bfae2
FS
3065/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3066 that is a valid memory address for an instruction.
3067 The MODE argument is the machine mode for the MEM expression
3068 that wants to use this address.
3069
3070 On the RS/6000, there are four valid address: a SYMBOL_REF that
3071 refers to a constant pool entry of an address (or the sum of it
3072 plus a constant), a short (16-bit signed) constant plus a register,
3073 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3074 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3075 we must ensure that both words are addressable or PowerPC64 with offset
3076 word aligned.
3077
3078 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3079 32-bit DImode, TImode), indexed addressing cannot be used because
3080 adjacent memory cells are accessed by adding word-sized offsets
3081 during assembly output. */
3082int
3083rs6000_legitimate_address (mode, x, reg_ok_strict)
3084 enum machine_mode mode;
3085 rtx x;
3086 int reg_ok_strict;
3087{
c4501e62
JJ
3088 if (RS6000_SYMBOL_REF_TLS_P (x))
3089 return 0;
4d588c14 3090 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3091 return 1;
3092 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3093 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3094 && !SPE_VECTOR_MODE (mode)
258bfae2 3095 && TARGET_UPDATE
4d588c14 3096 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3097 return 1;
4d588c14 3098 if (legitimate_small_data_p (mode, x))
258bfae2 3099 return 1;
4d588c14 3100 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3101 return 1;
3102 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3103 if (! reg_ok_strict
3104 && GET_CODE (x) == PLUS
3105 && GET_CODE (XEXP (x, 0)) == REG
3106 && XEXP (x, 0) == virtual_stack_vars_rtx
3107 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3108 return 1;
4d588c14 3109 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3110 return 1;
3111 if (mode != TImode
a3170dc6
AH
3112 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3113 || TARGET_POWERPC64
fcce224d 3114 || (mode != DFmode && mode != TFmode))
258bfae2 3115 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3116 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3117 return 1;
4d588c14 3118 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3119 return 1;
3120 return 0;
3121}
4d588c14
RH
3122
3123/* Go to LABEL if ADDR (a legitimate address expression)
3124 has an effect that depends on the machine mode it is used for.
3125
3126 On the RS/6000 this is true of all integral offsets (since AltiVec
3127 modes don't allow them) or is a pre-increment or decrement.
3128
3129 ??? Except that due to conceptual problems in offsettable_address_p
3130 we can't really report the problems of integral offsets. So leave
3131 this assuming that the adjustable offset must be valid for the
3132 sub-words of a TFmode operand, which is what we had before. */
3133
3134bool
3135rs6000_mode_dependent_address (addr)
3136 rtx addr;
3137{
3138 switch (GET_CODE (addr))
3139 {
3140 case PLUS:
3141 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3142 {
3143 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3144 return val + 12 + 0x8000 >= 0x10000;
3145 }
3146 break;
3147
3148 case LO_SUM:
3149 return true;
3150
3151 case PRE_INC:
3152 case PRE_DEC:
3153 return TARGET_UPDATE;
3154
3155 default:
3156 break;
3157 }
3158
3159 return false;
3160}
fb4d4348 3161\f
a4f6c312
SS
3162/* Try to output insns to set TARGET equal to the constant C if it can
3163 be done in less than N insns. Do all computations in MODE.
3164 Returns the place where the output has been placed if it can be
3165 done and the insns have been emitted. If it would take more than N
3166 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3167
3168rtx
3169rs6000_emit_set_const (dest, mode, source, n)
3170 rtx dest, source;
3171 enum machine_mode mode;
3172 int n ATTRIBUTE_UNUSED;
3173{
af8cb5c5 3174 rtx result, insn, set;
2bfcf297
DB
3175 HOST_WIDE_INT c0, c1;
3176
af8cb5c5 3177 if (mode == QImode || mode == HImode)
2bfcf297
DB
3178 {
3179 if (dest == NULL)
3180 dest = gen_reg_rtx (mode);
3181 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3182 return dest;
3183 }
af8cb5c5 3184 else if (mode == SImode)
2bfcf297 3185 {
af8cb5c5
DE
3186 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3187
3188 emit_insn (gen_rtx_SET (VOIDmode, result,
3189 GEN_INT (INTVAL (source)
3190 & (~ (HOST_WIDE_INT) 0xffff))));
3191 emit_insn (gen_rtx_SET (VOIDmode, dest,
3192 gen_rtx_IOR (SImode, result,
3193 GEN_INT (INTVAL (source) & 0xffff))));
3194 result = dest;
2bfcf297 3195 }
af8cb5c5 3196 else if (mode == DImode)
2bfcf297 3197 {
af8cb5c5
DE
3198 if (GET_CODE (source) == CONST_INT)
3199 {
3200 c0 = INTVAL (source);
3201 c1 = -(c0 < 0);
3202 }
3203 else if (GET_CODE (source) == CONST_DOUBLE)
3204 {
2bfcf297 3205#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3206 c0 = CONST_DOUBLE_LOW (source);
3207 c1 = -(c0 < 0);
2bfcf297 3208#else
af8cb5c5
DE
3209 c0 = CONST_DOUBLE_LOW (source);
3210 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3211#endif
af8cb5c5
DE
3212 }
3213 else
3214 abort ();
3215
3216 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3217 }
3218 else
a4f6c312 3219 abort ();
2bfcf297 3220
af8cb5c5
DE
3221 insn = get_last_insn ();
3222 set = single_set (insn);
3223 if (! CONSTANT_P (SET_SRC (set)))
3224 set_unique_reg_note (insn, REG_EQUAL, source);
3225
3226 return result;
2bfcf297
DB
3227}
3228
3229/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3230 fall back to a straight forward decomposition. We do this to avoid
3231 exponential run times encountered when looking for longer sequences
3232 with rs6000_emit_set_const. */
3233static rtx
3234rs6000_emit_set_long_const (dest, c1, c2)
3235 rtx dest;
3236 HOST_WIDE_INT c1, c2;
3237{
3238 if (!TARGET_POWERPC64)
3239 {
3240 rtx operand1, operand2;
3241
3242 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3243 DImode);
3244 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3245 DImode);
3246 emit_move_insn (operand1, GEN_INT (c1));
3247 emit_move_insn (operand2, GEN_INT (c2));
3248 }
3249 else
3250 {
bc06712d 3251 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3252
bc06712d
TR
3253 ud1 = c1 & 0xffff;
3254 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3255#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3256 c2 = c1 >> 32;
2bfcf297 3257#endif
bc06712d
TR
3258 ud3 = c2 & 0xffff;
3259 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3260
bc06712d
TR
3261 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3262 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3263 {
bc06712d
TR
3264 if (ud1 & 0x8000)
3265 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
3266 else
3267 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3268 }
2bfcf297 3269
bc06712d
TR
3270 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3271 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3272 {
bc06712d
TR
3273 if (ud2 & 0x8000)
3274 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3275 - 0x80000000));
252b88f7 3276 else
bc06712d
TR
3277 emit_move_insn (dest, GEN_INT (ud2 << 16));
3278 if (ud1 != 0)
3279 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3280 }
bc06712d
TR
3281 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3282 || (ud4 == 0 && ! (ud3 & 0x8000)))
3283 {
3284 if (ud3 & 0x8000)
3285 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3286 - 0x80000000));
3287 else
3288 emit_move_insn (dest, GEN_INT (ud3 << 16));
3289
3290 if (ud2 != 0)
3291 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3292 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3293 if (ud1 != 0)
3294 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3295 }
3296 else
3297 {
3298 if (ud4 & 0x8000)
3299 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3300 - 0x80000000));
3301 else
3302 emit_move_insn (dest, GEN_INT (ud4 << 16));
3303
3304 if (ud3 != 0)
3305 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3306
bc06712d
TR
3307 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3308 if (ud2 != 0)
3309 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3310 GEN_INT (ud2 << 16)));
3311 if (ud1 != 0)
3312 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3313 }
3314 }
2bfcf297
DB
3315 return dest;
3316}
3317
fb4d4348
GK
3318/* Emit a move from SOURCE to DEST in mode MODE. */
3319void
3320rs6000_emit_move (dest, source, mode)
3321 rtx dest;
3322 rtx source;
3323 enum machine_mode mode;
3324{
3325 rtx operands[2];
3326 operands[0] = dest;
3327 operands[1] = source;
3328
3329 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3330 if (GET_CODE (operands[1]) == CONST_DOUBLE
3331 && ! FLOAT_MODE_P (mode)
3332 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3333 {
3334 /* FIXME. This should never happen. */
3335 /* Since it seems that it does, do the safe thing and convert
3336 to a CONST_INT. */
2496c7bd 3337 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3338 }
3339 if (GET_CODE (operands[1]) == CONST_DOUBLE
3340 && ! FLOAT_MODE_P (mode)
3341 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3342 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3343 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3344 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3345 abort ();
c9e8cb32
DD
3346
3347 /* Check if GCC is setting up a block move that will end up using FP
3348 registers as temporaries. We must make sure this is acceptable. */
3349 if (GET_CODE (operands[0]) == MEM
3350 && GET_CODE (operands[1]) == MEM
3351 && mode == DImode
41543739
GK
3352 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3353 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3354 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3355 ? 32 : MEM_ALIGN (operands[0])))
3356 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3357 ? 32
3358 : MEM_ALIGN (operands[1]))))
3359 && ! MEM_VOLATILE_P (operands [0])
3360 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3361 {
41543739
GK
3362 emit_move_insn (adjust_address (operands[0], SImode, 0),
3363 adjust_address (operands[1], SImode, 0));
3364 emit_move_insn (adjust_address (operands[0], SImode, 4),
3365 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3366 return;
3367 }
fb4d4348 3368
67cef334
DE
3369 if (!no_new_pseudos)
3370 {
3371 if (GET_CODE (operands[1]) == MEM && optimize > 0
3372 && (mode == QImode || mode == HImode || mode == SImode)
3373 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3374 {
3375 rtx reg = gen_reg_rtx (word_mode);
3376
3377 emit_insn (gen_rtx_SET (word_mode, reg,
3378 gen_rtx_ZERO_EXTEND (word_mode,
3379 operands[1])));
3380 operands[1] = gen_lowpart (mode, reg);
3381 }
3382 if (GET_CODE (operands[0]) != REG)
3383 operands[1] = force_reg (mode, operands[1]);
3384 }
a9098fd0 3385
a3170dc6
AH
3386 if (mode == SFmode && ! TARGET_POWERPC
3387 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3388 && GET_CODE (operands[0]) == MEM)
fb4d4348 3389 {
ffc14f31
GK
3390 int regnum;
3391
3392 if (reload_in_progress || reload_completed)
3393 regnum = true_regnum (operands[1]);
3394 else if (GET_CODE (operands[1]) == REG)
3395 regnum = REGNO (operands[1]);
3396 else
3397 regnum = -1;
fb4d4348
GK
3398
3399 /* If operands[1] is a register, on POWER it may have
3400 double-precision data in it, so truncate it to single
3401 precision. */
3402 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3403 {
3404 rtx newreg;
3405 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3406 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3407 operands[1] = newreg;
3408 }
3409 }
3410
c4501e62
JJ
3411 /* Recognize the case where operand[1] is a reference to thread-local
3412 data and load its address to a register. */
3413 if (GET_CODE (operands[1]) == SYMBOL_REF)
3414 {
3415 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3416 if (model != 0)
3417 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3418 }
3419
8f4e6caf
RH
3420 /* Handle the case where reload calls us with an invalid address. */
3421 if (reload_in_progress && mode == Pmode
69ef87e2 3422 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3423 || ! nonimmediate_operand (operands[0], mode)))
3424 goto emit_set;
3425
3426 /* Handle the case of CONSTANT_P_RTX. */
3427 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3428 goto emit_set;
a9098fd0 3429
fb4d4348
GK
3430 /* FIXME: In the long term, this switch statement should go away
3431 and be replaced by a sequence of tests based on things like
3432 mode == Pmode. */
3433 switch (mode)
3434 {
3435 case HImode:
3436 case QImode:
3437 if (CONSTANT_P (operands[1])
3438 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3439 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3440 break;
3441
06f4e019 3442 case TFmode:
fb4d4348
GK
3443 case DFmode:
3444 case SFmode:
3445 if (CONSTANT_P (operands[1])
3446 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3447 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3448 break;
3449
0ac081f6
AH
3450 case V16QImode:
3451 case V8HImode:
3452 case V4SFmode:
3453 case V4SImode:
a3170dc6
AH
3454 case V4HImode:
3455 case V2SFmode:
3456 case V2SImode:
00a892b8 3457 case V1DImode:
69ef87e2 3458 if (CONSTANT_P (operands[1])
d744e06e 3459 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3460 operands[1] = force_const_mem (mode, operands[1]);
3461 break;
3462
fb4d4348 3463 case SImode:
a9098fd0 3464 case DImode:
fb4d4348
GK
3465 /* Use default pattern for address of ELF small data */
3466 if (TARGET_ELF
a9098fd0 3467 && mode == Pmode
f607bc57 3468 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3469 && (GET_CODE (operands[1]) == SYMBOL_REF
3470 || GET_CODE (operands[1]) == CONST)
3471 && small_data_operand (operands[1], mode))
fb4d4348
GK
3472 {
3473 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3474 return;
3475 }
3476
f607bc57 3477 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3478 && mode == Pmode && mode == SImode
3479 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3480 {
3481 emit_insn (gen_movsi_got (operands[0], operands[1]));
3482 return;
3483 }
3484
ee890fe2 3485 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3486 && TARGET_NO_TOC
3487 && ! flag_pic
a9098fd0 3488 && mode == Pmode
fb4d4348
GK
3489 && CONSTANT_P (operands[1])
3490 && GET_CODE (operands[1]) != HIGH
3491 && GET_CODE (operands[1]) != CONST_INT)
3492 {
a9098fd0 3493 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3494
3495 /* If this is a function address on -mcall-aixdesc,
3496 convert it to the address of the descriptor. */
3497 if (DEFAULT_ABI == ABI_AIX
3498 && GET_CODE (operands[1]) == SYMBOL_REF
3499 && XSTR (operands[1], 0)[0] == '.')
3500 {
3501 const char *name = XSTR (operands[1], 0);
3502 rtx new_ref;
3503 while (*name == '.')
3504 name++;
3505 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3506 CONSTANT_POOL_ADDRESS_P (new_ref)
3507 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3508 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3509 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3510 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3511 operands[1] = new_ref;
3512 }
7509c759 3513
ee890fe2
SS
3514 if (DEFAULT_ABI == ABI_DARWIN)
3515 {
ab82a49f
AP
3516#if TARGET_MACHO
3517 if (MACHO_DYNAMIC_NO_PIC_P)
3518 {
3519 /* Take care of any required data indirection. */
3520 operands[1] = rs6000_machopic_legitimize_pic_address (
3521 operands[1], mode, operands[0]);
3522 if (operands[0] != operands[1])
3523 emit_insn (gen_rtx_SET (VOIDmode,
3524 operands[0], operands[1]));
3525 return;
3526 }
3527#endif
ee890fe2
SS
3528 emit_insn (gen_macho_high (target, operands[1]));
3529 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3530 return;
3531 }
3532
fb4d4348
GK
3533 emit_insn (gen_elf_high (target, operands[1]));
3534 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3535 return;
3536 }
3537
a9098fd0
GK
3538 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3539 and we have put it in the TOC, we just need to make a TOC-relative
3540 reference to it. */
3541 if (TARGET_TOC
3542 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3543 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3544 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3545 get_pool_mode (operands[1])))
fb4d4348 3546 {
a9098fd0 3547 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3548 }
a9098fd0
GK
3549 else if (mode == Pmode
3550 && CONSTANT_P (operands[1])
38886f37
AO
3551 && ((GET_CODE (operands[1]) != CONST_INT
3552 && ! easy_fp_constant (operands[1], mode))
3553 || (GET_CODE (operands[1]) == CONST_INT
3554 && num_insns_constant (operands[1], mode) > 2)
3555 || (GET_CODE (operands[0]) == REG
3556 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3557 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3558 && ! legitimate_constant_pool_address_p (operands[1])
3559 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3560 {
3561 /* Emit a USE operation so that the constant isn't deleted if
3562 expensive optimizations are turned on because nobody
3563 references it. This should only be done for operands that
3564 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3565 This should not be done for operands that contain LABEL_REFs.
3566 For now, we just handle the obvious case. */
3567 if (GET_CODE (operands[1]) != LABEL_REF)
3568 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3569
c859cda6 3570#if TARGET_MACHO
ee890fe2 3571 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3572 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3573 {
ee890fe2
SS
3574 operands[1] =
3575 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3576 operands[0]);
3577 if (operands[0] != operands[1])
3578 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3579 return;
3580 }
c859cda6 3581#endif
ee890fe2 3582
fb4d4348
GK
3583 /* If we are to limit the number of things we put in the TOC and
3584 this is a symbol plus a constant we can add in one insn,
3585 just put the symbol in the TOC and add the constant. Don't do
3586 this if reload is in progress. */
3587 if (GET_CODE (operands[1]) == CONST
3588 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3589 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3590 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3591 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3592 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3593 && ! side_effects_p (operands[0]))
3594 {
a4f6c312
SS
3595 rtx sym =
3596 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3597 rtx other = XEXP (XEXP (operands[1], 0), 1);
3598
a9098fd0
GK
3599 sym = force_reg (mode, sym);
3600 if (mode == SImode)
3601 emit_insn (gen_addsi3 (operands[0], sym, other));
3602 else
3603 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3604 return;
3605 }
3606
a9098fd0 3607 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3608
3609 if (TARGET_TOC
4d588c14 3610 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3611 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3612 get_pool_constant (XEXP (operands[1], 0)),
3613 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3614 {
ba4828e0
RK
3615 operands[1]
3616 = gen_rtx_MEM (mode,
3617 create_TOC_reference (XEXP (operands[1], 0)));
3618 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3619 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3620 }
fb4d4348
GK
3621 }
3622 break;
a9098fd0 3623
fb4d4348
GK
3624 case TImode:
3625 if (GET_CODE (operands[0]) == MEM
3626 && GET_CODE (XEXP (operands[0], 0)) != REG
3627 && ! reload_in_progress)
792760b9
RK
3628 operands[0]
3629 = replace_equiv_address (operands[0],
3630 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3631
3632 if (GET_CODE (operands[1]) == MEM
3633 && GET_CODE (XEXP (operands[1], 0)) != REG
3634 && ! reload_in_progress)
792760b9
RK
3635 operands[1]
3636 = replace_equiv_address (operands[1],
3637 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3638 if (TARGET_POWER)
3639 {
3640 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3641 gen_rtvec (2,
3642 gen_rtx_SET (VOIDmode,
3643 operands[0], operands[1]),
3644 gen_rtx_CLOBBER (VOIDmode,
3645 gen_rtx_SCRATCH (SImode)))));
3646 return;
3647 }
fb4d4348
GK
3648 break;
3649
3650 default:
3651 abort ();
3652 }
3653
a9098fd0
GK
3654 /* Above, we may have called force_const_mem which may have returned
3655 an invalid address. If we can, fix this up; otherwise, reload will
3656 have to deal with it. */
8f4e6caf
RH
3657 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3658 operands[1] = validize_mem (operands[1]);
a9098fd0 3659
8f4e6caf 3660 emit_set:
fb4d4348
GK
3661 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3662}
4697a36c
MM
3663\f
3664/* Initialize a variable CUM of type CUMULATIVE_ARGS
3665 for a call to a function whose data type is FNTYPE.
3666 For a library call, FNTYPE is 0.
3667
3668 For incoming args we set the number of arguments in the prototype large
1c20ae99 3669 so we never return a PARALLEL. */
4697a36c
MM
3670
3671void
b9599e46 3672init_cumulative_args (cum, fntype, libname, incoming, libcall)
4697a36c
MM
3673 CUMULATIVE_ARGS *cum;
3674 tree fntype;
296b8152 3675 rtx libname ATTRIBUTE_UNUSED;
4697a36c 3676 int incoming;
b9599e46 3677 int libcall;
4697a36c
MM
3678{
3679 static CUMULATIVE_ARGS zero_cumulative;
3680
3681 *cum = zero_cumulative;
3682 cum->words = 0;
3683 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3684 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3685 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3686 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3687 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3688 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3689 cum->stdarg = fntype
3690 && (TYPE_ARG_TYPES (fntype) != 0
3691 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3692 != void_type_node));
4697a36c
MM
3693
3694 if (incoming)
bd227acc 3695 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
3696
3697 else if (cum->prototype)
3698 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
3699 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
3700 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
3701
3702 else
3703 cum->nargs_prototype = 0;
3704
a5c76ee6
ZW
3705 /* Check for a longcall attribute. */
3706 if (fntype
3707 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3708 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3709 cum->call_cookie = CALL_LONG;
3710
4697a36c
MM
3711 if (TARGET_DEBUG_ARG)
3712 {
3713 fprintf (stderr, "\ninit_cumulative_args:");
3714 if (fntype)
3715 {
3716 tree ret_type = TREE_TYPE (fntype);
3717 fprintf (stderr, " ret code = %s,",
3718 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3719 }
3720
6a4cee5f
MM
3721 if (cum->call_cookie & CALL_LONG)
3722 fprintf (stderr, " longcall,");
3723
4697a36c
MM
3724 fprintf (stderr, " proto = %d, nargs = %d\n",
3725 cum->prototype, cum->nargs_prototype);
3726 }
3727}
3728\f
c229cba9
DE
3729/* If defined, a C expression which determines whether, and in which
3730 direction, to pad out an argument with extra space. The value
3731 should be of type `enum direction': either `upward' to pad above
3732 the argument, `downward' to pad below, or `none' to inhibit
3733 padding.
3734
3735 For the AIX ABI structs are always stored left shifted in their
3736 argument slot. */
3737
9ebbca7d 3738enum direction
c229cba9
DE
3739function_arg_padding (mode, type)
3740 enum machine_mode mode;
3741 tree type;
3742{
6e985040
AM
3743#ifndef AGGREGATE_PADDING_FIXED
3744#define AGGREGATE_PADDING_FIXED 0
3745#endif
3746#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3747#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3748#endif
3749
3750 if (!AGGREGATE_PADDING_FIXED)
3751 {
3752 /* GCC used to pass structures of the same size as integer types as
3753 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3754 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3755 passed padded downward, except that -mstrict-align further
3756 muddied the water in that multi-component structures of 2 and 4
3757 bytes in size were passed padded upward.
3758
3759 The following arranges for best compatibility with previous
3760 versions of gcc, but removes the -mstrict-align dependency. */
3761 if (BYTES_BIG_ENDIAN)
3762 {
3763 HOST_WIDE_INT size = 0;
3764
3765 if (mode == BLKmode)
3766 {
3767 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3768 size = int_size_in_bytes (type);
3769 }
3770 else
3771 size = GET_MODE_SIZE (mode);
3772
3773 if (size == 1 || size == 2 || size == 4)
3774 return downward;
3775 }
3776 return upward;
3777 }
3778
3779 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3780 {
3781 if (type != 0 && AGGREGATE_TYPE_P (type))
3782 return upward;
3783 }
c229cba9
DE
3784
3785 /* This is the default definition. */
3786 return (! BYTES_BIG_ENDIAN
02ca7595
DE
3787 ? upward
3788 : ((mode == BLKmode
3789 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
3790 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
3791 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
3792 ? downward : upward));
c229cba9
DE
3793}
3794
b6c9286a
MM
3795/* If defined, a C expression that gives the alignment boundary, in bits,
3796 of an argument with the specified mode and type. If it is not defined,
3797 PARM_BOUNDARY is used for all arguments.
3798
2310f99a 3799 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3800
3801int
3802function_arg_boundary (mode, type)
3803 enum machine_mode mode;
9ebbca7d 3804 tree type ATTRIBUTE_UNUSED;
b6c9286a 3805{
f607bc57 3806 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3807 return 64;
a3170dc6
AH
3808 else if (SPE_VECTOR_MODE (mode))
3809 return 64;
0ac081f6
AH
3810 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3811 return 128;
9ebbca7d 3812 else
b6c9286a 3813 return PARM_BOUNDARY;
b6c9286a
MM
3814}
3815\f
4697a36c
MM
3816/* Update the data in CUM to advance over an argument
3817 of mode MODE and data type TYPE.
3818 (TYPE is null for libcalls where that information may not be available.) */
3819
3820void
3821function_arg_advance (cum, mode, type, named)
3822 CUMULATIVE_ARGS *cum;
3823 enum machine_mode mode;
3824 tree type;
3825 int named;
3826{
3827 cum->nargs_prototype--;
3828
0ac081f6
AH
3829 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3830 {
3831 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
3832 cum->vregno++;
3833 else
3834 cum->words += RS6000_ARG_SIZE (mode, type);
3835 }
a4b0320c 3836 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
3837 && !cum->stdarg
3838 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 3839 cum->sysv_gregno++;
f607bc57 3840 else if (DEFAULT_ABI == ABI_V4)
4697a36c 3841 {
a3170dc6 3842 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 3843 && (mode == SFmode || mode == DFmode))
4697a36c 3844 {
4cc833b7
RH
3845 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3846 cum->fregno++;
3847 else
3848 {
3849 if (mode == DFmode)
3850 cum->words += cum->words & 1;
d34c5b80 3851 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 3852 }
4697a36c 3853 }
4cc833b7
RH
3854 else
3855 {
3856 int n_words;
3857 int gregno = cum->sysv_gregno;
3858
3859 /* Aggregates and IEEE quad get passed by reference. */
3860 if ((type && AGGREGATE_TYPE_P (type))
3861 || mode == TFmode)
3862 n_words = 1;
3863 else
d34c5b80 3864 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3865
a4b0320c 3866 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3867 if (n_words == 2 && (gregno & 1) == 0)
3868 gregno += 1;
3869
a4b0320c
AH
3870 /* Long long and SPE vectors are not split between registers
3871 and stack. */
4cc833b7
RH
3872 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
3873 {
3874 /* Long long is aligned on the stack. */
3875 if (n_words == 2)
3876 cum->words += cum->words & 1;
3877 cum->words += n_words;
3878 }
4697a36c 3879
4cc833b7
RH
3880 /* Note: continuing to accumulate gregno past when we've started
3881 spilling to the stack indicates the fact that we've started
3882 spilling to the stack to expand_builtin_saveregs. */
3883 cum->sysv_gregno = gregno + n_words;
3884 }
4697a36c 3885
4cc833b7
RH
3886 if (TARGET_DEBUG_ARG)
3887 {
3888 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3889 cum->words, cum->fregno);
3890 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
3891 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
3892 fprintf (stderr, "mode = %4s, named = %d\n",
3893 GET_MODE_NAME (mode), named);
3894 }
4697a36c
MM
3895 }
3896 else
4cc833b7
RH
3897 {
3898 int align = (TARGET_32BIT && (cum->words & 1) != 0
3899 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 3900
d34c5b80 3901 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 3902
a3170dc6
AH
3903 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3904 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 3905 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
3906
3907 if (TARGET_DEBUG_ARG)
3908 {
3909 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3910 cum->words, cum->fregno);
3911 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
3912 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
3913 fprintf (stderr, "named = %d, align = %d\n", named, align);
3914 }
3915 }
4697a36c 3916}
a6c9bed4
AH
3917
3918/* Determine where to put a SIMD argument on the SPE. */
3919static rtx
3920rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type)
3921{
3922 if (cum->stdarg)
3923 {
3924 int gregno = cum->sysv_gregno;
3925 int n_words = RS6000_ARG_SIZE (mode, type);
3926
3927 /* SPE vectors are put in odd registers. */
3928 if (n_words == 2 && (gregno & 1) == 0)
3929 gregno += 1;
3930
3931 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
3932 {
3933 rtx r1, r2;
3934 enum machine_mode m = SImode;
3935
3936 r1 = gen_rtx_REG (m, gregno);
3937 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
3938 r2 = gen_rtx_REG (m, gregno + 1);
3939 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
3940 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
3941 }
3942 else
3943 return NULL;
3944 }
3945 else
3946 {
3947 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
3948 return gen_rtx_REG (mode, cum->sysv_gregno);
3949 else
3950 return NULL;
3951 }
3952}
3953
4697a36c
MM
3954/* Determine where to put an argument to a function.
3955 Value is zero to push the argument on the stack,
3956 or a hard register in which to store the argument.
3957
3958 MODE is the argument's machine mode.
3959 TYPE is the data type of the argument (as a tree).
3960 This is null for libcalls where that information may
3961 not be available.
3962 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3963 the preceding args and about the function being called.
3964 NAMED is nonzero if this argument is a named parameter
3965 (otherwise it is an extra parameter matching an ellipsis).
3966
3967 On RS/6000 the first eight words of non-FP are normally in registers
3968 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
3969 Under V.4, the first 8 FP args are in registers.
3970
3971 If this is floating-point and no prototype is specified, we use
3972 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 3973 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 3974 so we can pass the FP value just in one register. emit_library_function
1c20ae99 3975 doesn't support PARALLEL anyway. */
4697a36c
MM
3976
3977struct rtx_def *
3978function_arg (cum, mode, type, named)
3979 CUMULATIVE_ARGS *cum;
3980 enum machine_mode mode;
3981 tree type;
20c29ebe 3982 int named;
4697a36c 3983{
4cc833b7 3984 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 3985
a4f6c312
SS
3986 /* Return a marker to indicate whether CR1 needs to set or clear the
3987 bit that V.4 uses to say fp args were passed in registers.
3988 Assume that we don't need the marker for software floating point,
3989 or compiler generated library calls. */
4697a36c
MM
3990 if (mode == VOIDmode)
3991 {
f607bc57 3992 if (abi == ABI_V4
7509c759 3993 && cum->nargs_prototype < 0
b9599e46
FS
3994 && (cum->call_cookie & CALL_LIBCALL) == 0
3995 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 3996 {
a3170dc6
AH
3997 /* For the SPE, we need to crxor CR6 always. */
3998 if (TARGET_SPE_ABI)
3999 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4000 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4001 return GEN_INT (cum->call_cookie
4002 | ((cum->fregno == FP_ARG_MIN_REG)
4003 ? CALL_V4_SET_FP_ARGS
4004 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4005 }
4697a36c 4006
7509c759 4007 return GEN_INT (cum->call_cookie);
4697a36c
MM
4008 }
4009
0ac081f6
AH
4010 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4011 {
20c29ebe 4012 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
4013 return gen_rtx_REG (mode, cum->vregno);
4014 else
4015 return NULL;
4016 }
a6c9bed4
AH
4017 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4018 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4019 else if (abi == ABI_V4)
4697a36c 4020 {
a3170dc6 4021 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4022 && (mode == SFmode || mode == DFmode))
4023 {
4024 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4025 return gen_rtx_REG (mode, cum->fregno);
4026 else
4027 return NULL;
4028 }
4029 else
4030 {
4031 int n_words;
4032 int gregno = cum->sysv_gregno;
4033
4034 /* Aggregates and IEEE quad get passed by reference. */
4035 if ((type && AGGREGATE_TYPE_P (type))
4036 || mode == TFmode)
4037 n_words = 1;
4038 else
d34c5b80 4039 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 4040
a4b0320c 4041 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4042 if (n_words == 2 && (gregno & 1) == 0)
4043 gregno += 1;
4044
a6c9bed4 4045 /* Long long do not split between registers and stack. */
4cc833b7 4046 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4047 return gen_rtx_REG (mode, gregno);
4cc833b7
RH
4048 else
4049 return NULL;
4050 }
4697a36c 4051 }
4cc833b7
RH
4052 else
4053 {
4054 int align = (TARGET_32BIT && (cum->words & 1) != 0
4055 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4056 int align_words = cum->words + align;
4697a36c 4057
4cc833b7
RH
4058 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4059 return NULL_RTX;
4060
4061 if (USE_FP_FOR_ARG_P (*cum, mode, type))
4062 {
4063 if (! type
4064 || ((cum->nargs_prototype > 0)
4065 /* IBM AIX extended its linkage convention definition always
4066 to require FP args after register save area hole on the
4067 stack. */
4068 && (DEFAULT_ABI != ABI_AIX
4069 || ! TARGET_XL_CALL
4070 || (align_words < GP_ARG_NUM_REG))))
4071 return gen_rtx_REG (mode, cum->fregno);
4072
4073 return gen_rtx_PARALLEL (mode,
4074 gen_rtvec (2,
39403d82 4075 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
4076 ((align_words >= GP_ARG_NUM_REG)
4077 ? NULL_RTX
4078 : (align_words
d34c5b80 4079 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
4080 > GP_ARG_NUM_REG
4081 /* If this is partially on the stack, then
4082 we only include the portion actually
4083 in registers here. */
39403d82 4084 ? gen_rtx_REG (SImode,
1c20ae99 4085 GP_ARG_MIN_REG + align_words)
39403d82 4086 : gen_rtx_REG (mode,
1c20ae99
JW
4087 GP_ARG_MIN_REG + align_words))),
4088 const0_rtx),
39403d82
DE
4089 gen_rtx_EXPR_LIST (VOIDmode,
4090 gen_rtx_REG (mode, cum->fregno),
1c20ae99 4091 const0_rtx)));
4cc833b7
RH
4092 }
4093 else if (align_words < GP_ARG_NUM_REG)
4094 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4095 else
4096 return NULL_RTX;
4697a36c 4097 }
4697a36c
MM
4098}
4099\f
4100/* For an arg passed partly in registers and partly in memory,
4101 this is the number of registers used.
4102 For args passed entirely in registers or entirely in memory, zero. */
4103
4104int
4105function_arg_partial_nregs (cum, mode, type, named)
4106 CUMULATIVE_ARGS *cum;
4107 enum machine_mode mode;
4108 tree type;
d34c5b80 4109 int named ATTRIBUTE_UNUSED;
4697a36c 4110{
f607bc57 4111 if (DEFAULT_ABI == ABI_V4)
4697a36c 4112 return 0;
4697a36c 4113
0ac081f6
AH
4114 if (USE_FP_FOR_ARG_P (*cum, mode, type)
4115 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
4116 {
4117 if (cum->nargs_prototype >= 0)
4118 return 0;
4119 }
4120
4121 if (cum->words < GP_ARG_NUM_REG
d34c5b80 4122 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
4123 {
4124 int ret = GP_ARG_NUM_REG - cum->words;
4125 if (ret && TARGET_DEBUG_ARG)
4126 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4127
4128 return ret;
4129 }
4130
4131 return 0;
4132}
4133\f
4134/* A C expression that indicates when an argument must be passed by
4135 reference. If nonzero for an argument, a copy of that argument is
4136 made in memory and a pointer to the argument is passed instead of
4137 the argument itself. The pointer is passed in whatever way is
4138 appropriate for passing a pointer to that type.
4139
c8c99a68
DE
4140 Under V.4, structures and unions are passed by reference.
4141
4142 As an extension to all ABIs, variable sized types are passed by
4143 reference. */
4697a36c
MM
4144
4145int
4146function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
4147 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
4148 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 4149 tree type;
296b8152 4150 int named ATTRIBUTE_UNUSED;
4697a36c 4151{
f607bc57 4152 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4153 && ((type && AGGREGATE_TYPE_P (type))
4154 || mode == TFmode))
4697a36c
MM
4155 {
4156 if (TARGET_DEBUG_ARG)
4157 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4158
4159 return 1;
4160 }
c8c99a68 4161 return type && int_size_in_bytes (type) <= 0;
4697a36c 4162}
4697a36c
MM
4163\f
4164/* Perform any needed actions needed for a function that is receiving a
4165 variable number of arguments.
4166
4167 CUM is as above.
4168
4169 MODE and TYPE are the mode and type of the current parameter.
4170
4171 PRETEND_SIZE is a variable that should be set to the amount of stack
4172 that must be pushed by the prolog to pretend that our caller pushed
4173 it.
4174
4175 Normally, this macro will push all remaining incoming registers on the
4176 stack and set PRETEND_SIZE to the length of the registers pushed. */
4177
4178void
4179setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
4180 CUMULATIVE_ARGS *cum;
4181 enum machine_mode mode;
4182 tree type;
de62b72c 4183 int *pretend_size ATTRIBUTE_UNUSED;
4697a36c
MM
4184 int no_rtl;
4185
4186{
4cc833b7
RH
4187 CUMULATIVE_ARGS next_cum;
4188 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4189 rtx save_area = NULL_RTX, mem;
dfafc897 4190 int first_reg_offset, set;
d34c5b80
DE
4191 tree fntype;
4192 int stdarg_p;
4697a36c 4193
d34c5b80
DE
4194 fntype = TREE_TYPE (current_function_decl);
4195 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
4196 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4197 != void_type_node));
4cc833b7 4198
d34c5b80
DE
4199 /* For varargs, we do not want to skip the dummy va_dcl argument.
4200 For stdargs, we do want to skip the last named argument. */
4201 next_cum = *cum;
4202 if (stdarg_p)
4203 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4204
f607bc57 4205 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4206 {
4cc833b7 4207 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4208 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4209 if (! no_rtl)
2c4974b7 4210 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4211 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4212
4213 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4214 }
60e2d0ca 4215 else
4697a36c 4216 {
d34c5b80 4217 first_reg_offset = next_cum.words;
4cc833b7 4218 save_area = virtual_incoming_args_rtx;
00dba523 4219 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4220
4221 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 4222 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 4223 }
4697a36c 4224
dfafc897 4225 set = get_varargs_alias_set ();
c81fc13e 4226 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4227 {
dfafc897
FS
4228 mem = gen_rtx_MEM (BLKmode,
4229 plus_constant (save_area,
4230 first_reg_offset * reg_size)),
ba4828e0 4231 set_mem_alias_set (mem, set);
8ac61af7 4232 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4233
c6b97fac
AM
4234 move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4235 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4236 }
4237
4697a36c 4238 /* Save FP registers if needed. */
f607bc57 4239 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4240 && TARGET_HARD_FLOAT && TARGET_FPRS
4241 && ! no_rtl
4cc833b7 4242 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4243 {
4cc833b7 4244 int fregno = next_cum.fregno;
9ebbca7d 4245 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4246 rtx lab = gen_label_rtx ();
4247 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4248
4cc833b7 4249 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4250 pc_rtx,
39403d82 4251 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4252 gen_rtx_NE (VOIDmode, cr1,
4253 const0_rtx),
39403d82 4254 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4255 pc_rtx)));
4256
4cc833b7
RH
4257 while (fregno <= FP_ARG_V4_MAX_REG)
4258 {
dfafc897 4259 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4260 set_mem_alias_set (mem, set);
dfafc897 4261 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4262 fregno++;
4263 off += 8;
4697a36c 4264 }
4cc833b7
RH
4265
4266 emit_label (lab);
4697a36c 4267 }
4697a36c 4268}
4697a36c 4269
dfafc897 4270/* Create the va_list data type. */
2c4974b7 4271
dfafc897
FS
4272tree
4273rs6000_build_va_list ()
4274{
64c2816f 4275 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4276
9ebbca7d
GK
4277 /* For AIX, prefer 'char *' because that's what the system
4278 header files like. */
f607bc57 4279 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4280 return build_pointer_type (char_type_node);
dfafc897 4281
f1e639b1 4282 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4283 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4284
9ebbca7d
GK
4285 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4286 unsigned_char_type_node);
4287 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4288 unsigned_char_type_node);
64c2816f
DT
4289 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4290 every user file. */
4291 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4292 short_unsigned_type_node);
dfafc897
FS
4293 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4294 ptr_type_node);
4295 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4296 ptr_type_node);
4297
4298 DECL_FIELD_CONTEXT (f_gpr) = record;
4299 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4300 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4301 DECL_FIELD_CONTEXT (f_ovf) = record;
4302 DECL_FIELD_CONTEXT (f_sav) = record;
4303
bab45a51
FS
4304 TREE_CHAIN (record) = type_decl;
4305 TYPE_NAME (record) = type_decl;
dfafc897
FS
4306 TYPE_FIELDS (record) = f_gpr;
4307 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4308 TREE_CHAIN (f_fpr) = f_res;
4309 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4310 TREE_CHAIN (f_ovf) = f_sav;
4311
4312 layout_type (record);
4313
4314 /* The correct type is an array type of one element. */
4315 return build_array_type (record, build_index_type (size_zero_node));
4316}
4317
4318/* Implement va_start. */
4319
4320void
e5faf155 4321rs6000_va_start (valist, nextarg)
dfafc897
FS
4322 tree valist;
4323 rtx nextarg;
4697a36c 4324{
dfafc897 4325 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4326 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4327 tree gpr, fpr, ovf, sav, t;
2c4974b7 4328
dfafc897 4329 /* Only SVR4 needs something special. */
f607bc57 4330 if (DEFAULT_ABI != ABI_V4)
dfafc897 4331 {
e5faf155 4332 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4333 return;
4334 }
4335
973a648b 4336 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4337 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4338 f_res = TREE_CHAIN (f_fpr);
4339 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4340 f_sav = TREE_CHAIN (f_ovf);
4341
8ebecc3b 4342 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4343 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4344 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4345 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4346 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4347
4348 /* Count number of gp and fp argument registers used. */
4cc833b7 4349 words = current_function_args_info.words;
dfafc897
FS
4350 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4351 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4352
4353 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4354 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4355 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4356 words, n_gpr, n_fpr);
dfafc897
FS
4357
4358 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4359 TREE_SIDE_EFFECTS (t) = 1;
4360 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4361
4362 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4363 TREE_SIDE_EFFECTS (t) = 1;
4364 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4365
4366 /* Find the overflow area. */
4367 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4368 if (words != 0)
4369 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4370 build_int_2 (words * UNITS_PER_WORD, 0));
4371 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4372 TREE_SIDE_EFFECTS (t) = 1;
4373 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4374
4375 /* Find the register save area. */
4376 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4377 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4378 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4379 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4380 TREE_SIDE_EFFECTS (t) = 1;
4381 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4382}
4383
4384/* Implement va_arg. */
4385
4386rtx
4387rs6000_va_arg (valist, type)
4388 tree valist, type;
4389{
c566f9bd 4390 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4391 tree gpr, fpr, ovf, sav, reg, t, u;
4392 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4393 rtx lab_false, lab_over, addr_rtx, r;
4394
f607bc57 4395 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4396 {
4397 /* Variable sized types are passed by reference. */
4398 if (int_size_in_bytes (type) <= 0)
4399 {
4400 u = build_pointer_type (type);
4401
4402 /* Args grow upward. */
4403 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4404 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4405 TREE_SIDE_EFFECTS (t) = 1;
4406
4407 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4408 TREE_SIDE_EFFECTS (t) = 1;
4409
4410 t = build1 (INDIRECT_REF, u, t);
4411 TREE_SIDE_EFFECTS (t) = 1;
4412
4413 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4414 }
4415 else
4416 return std_expand_builtin_va_arg (valist, type);
4417 }
dfafc897 4418
973a648b 4419 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4420 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4421 f_res = TREE_CHAIN (f_fpr);
4422 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4423 f_sav = TREE_CHAIN (f_ovf);
4424
8ebecc3b 4425 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4426 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4427 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4428 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4429 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4430
4431 size = int_size_in_bytes (type);
4432 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4433
dfafc897 4434 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4435 {
dfafc897
FS
4436 /* Aggregates and long doubles are passed by reference. */
4437 indirect_p = 1;
4438 reg = gpr;
4439 n_reg = 1;
4440 sav_ofs = 0;
4441 sav_scale = 4;
d3294cd9
FS
4442 size = UNITS_PER_WORD;
4443 rsize = 1;
dfafc897 4444 }
a3170dc6 4445 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4446 {
4447 /* FP args go in FP registers, if present. */
4448 indirect_p = 0;
4449 reg = fpr;
4450 n_reg = 1;
4451 sav_ofs = 8*4;
4452 sav_scale = 8;
4cc833b7 4453 }
dfafc897
FS
4454 else
4455 {
4456 /* Otherwise into GP registers. */
4457 indirect_p = 0;
4458 reg = gpr;
4459 n_reg = rsize;
4460 sav_ofs = 0;
4461 sav_scale = 4;
4462 }
4463
a4f6c312 4464 /* Pull the value out of the saved registers ... */
dfafc897
FS
4465
4466 lab_false = gen_label_rtx ();
4467 lab_over = gen_label_rtx ();
4468 addr_rtx = gen_reg_rtx (Pmode);
4469
16861f33
AH
4470 /* AltiVec vectors never go in registers. */
4471 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4472 {
41daaf0e
AH
4473 TREE_THIS_VOLATILE (reg) = 1;
4474 emit_cmp_and_jump_insns
4475 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4476 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4477 lab_false);
dfafc897 4478
41daaf0e
AH
4479 /* Long long is aligned in the registers. */
4480 if (n_reg > 1)
4481 {
4482 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4483 build_int_2 (n_reg - 1, 0));
4484 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4485 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4486 TREE_SIDE_EFFECTS (u) = 1;
4487 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4488 }
2c4974b7 4489
41daaf0e
AH
4490 if (sav_ofs)
4491 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4492 else
4493 t = sav;
2c4974b7 4494
41daaf0e
AH
4495 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4496 build_int_2 (n_reg, 0));
4497 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4498
41daaf0e
AH
4499 u = build1 (CONVERT_EXPR, integer_type_node, u);
4500 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4501
41daaf0e
AH
4502 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4503 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4504
41daaf0e
AH
4505 t = build (PLUS_EXPR, ptr_type_node, t, u);
4506 TREE_SIDE_EFFECTS (t) = 1;
4507
4508 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4509 if (r != addr_rtx)
4510 emit_move_insn (addr_rtx, r);
4511
4512 emit_jump_insn (gen_jump (lab_over));
4513 emit_barrier ();
4514 }
dfafc897 4515
dfafc897
FS
4516 emit_label (lab_false);
4517
a4f6c312 4518 /* ... otherwise out of the overflow area. */
dfafc897 4519
41daaf0e
AH
4520 /* Make sure we don't find reg 7 for the next int arg.
4521
4522 All AltiVec vectors go in the overflow area. So in the AltiVec
4523 case we need to get the vectors from the overflow area, but
4524 remember where the GPRs and FPRs are. */
16861f33
AH
4525 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
4526 || !TARGET_ALTIVEC))
dfafc897
FS
4527 {
4528 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
4529 TREE_SIDE_EFFECTS (t) = 1;
4530 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4531 }
4532
4533 /* Care for on-stack alignment if needed. */
4534 if (rsize <= 1)
4535 t = ovf;
4536 else
4537 {
41daaf0e
AH
4538 int align;
4539
16861f33
AH
4540 /* AltiVec vectors are 16 byte aligned. */
4541 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
4542 align = 15;
4543 else
4544 align = 7;
4545
4546 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
4547 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
4548 }
4549 t = save_expr (t);
4550
4551 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4552 if (r != addr_rtx)
4553 emit_move_insn (addr_rtx, r);
4554
4555 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
4556 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4557 TREE_SIDE_EFFECTS (t) = 1;
4558 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4559
4560 emit_label (lab_over);
4561
4562 if (indirect_p)
4563 {
4564 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 4565 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
4566 emit_move_insn (addr_rtx, r);
4567 }
4568
4569 return addr_rtx;
4697a36c 4570}
0ac081f6
AH
4571
4572/* Builtins. */
4573
6a2dd09a
RS
4574#define def_builtin(MASK, NAME, TYPE, CODE) \
4575do { \
4576 if ((MASK) & target_flags) \
4577 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
4578 NULL, NULL_TREE); \
0ac081f6
AH
4579} while (0)
4580
24408032
AH
4581/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
4582
2212663f 4583static const struct builtin_description bdesc_3arg[] =
24408032
AH
4584{
4585 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
4586 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
4587 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
4588 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
4589 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
4590 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
4591 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
4592 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
4593 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
4594 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
4595 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
4596 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
4597 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
4598 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
4599 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
4600 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
4601 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
4602 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
4603 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
4604 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
4605 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
4606 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
4607 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
4608};
2212663f 4609
95385cbb
AH
4610/* DST operations: void foo (void *, const int, const char). */
4611
4612static const struct builtin_description bdesc_dst[] =
4613{
4614 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
4615 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
4616 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
4617 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
4618};
4619
2212663f 4620/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 4621
a3170dc6 4622static struct builtin_description bdesc_2arg[] =
0ac081f6 4623{
f18c054f
DB
4624 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
4625 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
4626 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
4627 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
4628 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
4629 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
4630 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
4631 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
4632 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
4633 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
4634 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 4635 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
4636 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
4637 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
4638 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
4639 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
4640 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
4641 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
4642 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
4643 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
4644 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
4645 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
4646 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
4647 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
4648 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
4649 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
4650 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
4651 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
4652 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
4653 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
4654 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
4655 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
4656 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
4657 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
4658 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
4659 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
4660 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
4661 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
4662 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
4663 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
4664 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
4665 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
4666 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
4667 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
4668 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
4669 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
4670 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
4671 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
4672 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
4673 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
4674 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
4675 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
4676 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
4677 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
4678 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
4679 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
4680 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
4681 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
4682 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
4683 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
4684 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
4685 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
4686 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
4687 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
4688 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 4689 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
4690 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
4691 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
4692 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
4693 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
4694 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
4695 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
4696 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
4697 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
4698 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
4699 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
4700 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
4701 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
4702 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
4703 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
4704 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
4705 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
4706 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
4707 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
4708 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
4709 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
4710 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
4711 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 4712 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
4713 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
4714 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
4715 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
4716 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
4717 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
4718 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
4719 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
4720 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
4721 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
4722 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
4723 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
4724 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
4725 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
4726 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
4727 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
4728 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
4729 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
4730 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
4731 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
4732 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
4733 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
4734 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
4735 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 4736 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
4737
4738 /* Place holder, leave as first spe builtin. */
4739 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
4740 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
4741 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
4742 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
4743 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
4744 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
4745 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
4746 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
4747 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
4748 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
4749 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
4750 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
4751 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
4752 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
4753 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
4754 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
4755 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
4756 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
4757 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
4758 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
4759 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
4760 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
4761 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
4762 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
4763 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
4764 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
4765 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
4766 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
4767 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
4768 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
4769 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
4770 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
4771 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
4772 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
4773 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
4774 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
4775 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
4776 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
4777 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
4778 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
4779 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
4780 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
4781 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
4782 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
4783 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
4784 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
4785 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
4786 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
4787 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
4788 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
4789 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
4790 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
4791 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
4792 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
4793 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
4794 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
4795 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
4796 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
4797 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
4798 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
4799 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
4800 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
4801 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
4802 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
4803 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
4804 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
4805 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
4806 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
4807 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
4808 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
4809 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
4810 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
4811 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
4812 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
4813 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
4814 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
4815 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
4816 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
4817 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
4818 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
4819 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
4820 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
4821 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
4822 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
4823 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
4824 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
4825 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
4826 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
4827 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
4828 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
4829 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
4830 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
4831 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
4832 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
4833 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
4834 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
4835 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
4836 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
4837 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
4838 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
4839 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
4840 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
4841 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
4842 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
4843 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
4844 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
4845 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
4846 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
4847 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
4848
4849 /* SPE binary operations expecting a 5-bit unsigned literal. */
4850 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
4851
4852 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
4853 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
4854 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
4855 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
4856 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
4857 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
4858 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
4859 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
4860 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
4861 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
4862 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
4863 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
4864 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
4865 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
4866 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
4867 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
4868 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
4869 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
4870 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
4871 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
4872 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
4873 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
4874 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
4875 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
4876 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
4877 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
4878
4879 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 4880 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
4881};
4882
4883/* AltiVec predicates. */
4884
4885struct builtin_description_predicates
4886{
4887 const unsigned int mask;
4888 const enum insn_code icode;
4889 const char *opcode;
4890 const char *const name;
4891 const enum rs6000_builtins code;
4892};
4893
4894static const struct builtin_description_predicates bdesc_altivec_preds[] =
4895{
4896 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
4897 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
4898 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
4899 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
4900 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
4901 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
4902 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
4903 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
4904 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
4905 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
4906 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
4907 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
4908 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 4909};
24408032 4910
a3170dc6
AH
4911/* SPE predicates. */
4912static struct builtin_description bdesc_spe_predicates[] =
4913{
4914 /* Place-holder. Leave as first. */
4915 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
4916 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
4917 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
4918 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
4919 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
4920 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
4921 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
4922 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
4923 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
4924 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
4925 /* Place-holder. Leave as last. */
4926 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
4927};
4928
4929/* SPE evsel predicates. */
4930static struct builtin_description bdesc_spe_evsel[] =
4931{
4932 /* Place-holder. Leave as first. */
4933 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
4934 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
4935 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
4936 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
4937 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
4938 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
4939 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
4940 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
4941 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
4942 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
4943 /* Place-holder. Leave as last. */
4944 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
4945};
4946
b6d08ca1 4947/* ABS* operations. */
100c4561
AH
4948
4949static const struct builtin_description bdesc_abs[] =
4950{
4951 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
4952 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
4953 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
4954 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
4955 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
4956 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
4957 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
4958};
4959
617e0e1d
DB
4960/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
4961 foo (VECa). */
24408032 4962
a3170dc6 4963static struct builtin_description bdesc_1arg[] =
2212663f 4964{
617e0e1d
DB
4965 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
4966 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
4967 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
4968 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
4969 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
4970 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
4971 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
4972 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
4973 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
4974 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
4975 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
4976 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
4977 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
4978 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
4979 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
4980 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
4981 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
4982
4983 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
4984 end with SPE_BUILTIN_EVSUBFUSIAAW. */
4985 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
4986 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
4987 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
4988 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
4989 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
4990 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
4991 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
4992 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
4993 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
4994 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
4995 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
4996 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
4997 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
4998 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
4999 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5000 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5001 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5002 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5003 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5004 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5005 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5006 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5007 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5008 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5009 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5010 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5011 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5012 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
5013 { 0, CODE_FOR_spe_evsplatfi, "__builtin_spe_evsplatfi", SPE_BUILTIN_EVSPLATFI },
5014 { 0, CODE_FOR_spe_evsplati, "__builtin_spe_evsplati", SPE_BUILTIN_EVSPLATI },
5015
5016 /* Place-holder. Leave as last unary SPE builtin. */
5017 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5018};
5019
5020static rtx
92898235 5021rs6000_expand_unop_builtin (icode, arglist, target)
2212663f
DB
5022 enum insn_code icode;
5023 tree arglist;
5024 rtx target;
5025{
5026 rtx pat;
5027 tree arg0 = TREE_VALUE (arglist);
5028 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5029 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5030 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5031
0559cc77
DE
5032 if (icode == CODE_FOR_nothing)
5033 /* Builtin not supported on this processor. */
5034 return 0;
5035
20e26713
AH
5036 /* If we got invalid arguments bail out before generating bad rtl. */
5037 if (arg0 == error_mark_node)
9a171fcd 5038 return const0_rtx;
20e26713 5039
0559cc77
DE
5040 if (icode == CODE_FOR_altivec_vspltisb
5041 || icode == CODE_FOR_altivec_vspltish
5042 || icode == CODE_FOR_altivec_vspltisw
5043 || icode == CODE_FOR_spe_evsplatfi
5044 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5045 {
5046 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5047 if (GET_CODE (op0) != CONST_INT
5048 || INTVAL (op0) > 0x1f
5049 || INTVAL (op0) < -0x1f)
5050 {
5051 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5052 return const0_rtx;
b44140e7 5053 }
b44140e7
AH
5054 }
5055
c62f2db5 5056 if (target == 0
2212663f
DB
5057 || GET_MODE (target) != tmode
5058 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5059 target = gen_reg_rtx (tmode);
5060
5061 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5062 op0 = copy_to_mode_reg (mode0, op0);
5063
5064 pat = GEN_FCN (icode) (target, op0);
5065 if (! pat)
5066 return 0;
5067 emit_insn (pat);
0ac081f6 5068
2212663f
DB
5069 return target;
5070}
ae4b4a02 5071
100c4561
AH
5072static rtx
5073altivec_expand_abs_builtin (icode, arglist, target)
5074 enum insn_code icode;
5075 tree arglist;
5076 rtx target;
5077{
5078 rtx pat, scratch1, scratch2;
5079 tree arg0 = TREE_VALUE (arglist);
5080 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5081 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5082 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5083
5084 /* If we have invalid arguments, bail out before generating bad rtl. */
5085 if (arg0 == error_mark_node)
9a171fcd 5086 return const0_rtx;
100c4561
AH
5087
5088 if (target == 0
5089 || GET_MODE (target) != tmode
5090 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5091 target = gen_reg_rtx (tmode);
5092
5093 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5094 op0 = copy_to_mode_reg (mode0, op0);
5095
5096 scratch1 = gen_reg_rtx (mode0);
5097 scratch2 = gen_reg_rtx (mode0);
5098
5099 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5100 if (! pat)
5101 return 0;
5102 emit_insn (pat);
5103
5104 return target;
5105}
5106
0ac081f6 5107static rtx
92898235 5108rs6000_expand_binop_builtin (icode, arglist, target)
0ac081f6
AH
5109 enum insn_code icode;
5110 tree arglist;
5111 rtx target;
5112{
5113 rtx pat;
5114 tree arg0 = TREE_VALUE (arglist);
5115 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5116 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5117 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5118 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5119 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5120 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5121
0559cc77
DE
5122 if (icode == CODE_FOR_nothing)
5123 /* Builtin not supported on this processor. */
5124 return 0;
5125
20e26713
AH
5126 /* If we got invalid arguments bail out before generating bad rtl. */
5127 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5128 return const0_rtx;
20e26713 5129
0559cc77
DE
5130 if (icode == CODE_FOR_altivec_vcfux
5131 || icode == CODE_FOR_altivec_vcfsx
5132 || icode == CODE_FOR_altivec_vctsxs
5133 || icode == CODE_FOR_altivec_vctuxs
5134 || icode == CODE_FOR_altivec_vspltb
5135 || icode == CODE_FOR_altivec_vsplth
5136 || icode == CODE_FOR_altivec_vspltw
5137 || icode == CODE_FOR_spe_evaddiw
5138 || icode == CODE_FOR_spe_evldd
5139 || icode == CODE_FOR_spe_evldh
5140 || icode == CODE_FOR_spe_evldw
5141 || icode == CODE_FOR_spe_evlhhesplat
5142 || icode == CODE_FOR_spe_evlhhossplat
5143 || icode == CODE_FOR_spe_evlhhousplat
5144 || icode == CODE_FOR_spe_evlwhe
5145 || icode == CODE_FOR_spe_evlwhos
5146 || icode == CODE_FOR_spe_evlwhou
5147 || icode == CODE_FOR_spe_evlwhsplat
5148 || icode == CODE_FOR_spe_evlwwsplat
5149 || icode == CODE_FOR_spe_evrlwi
5150 || icode == CODE_FOR_spe_evslwi
5151 || icode == CODE_FOR_spe_evsrwis
f5119d10 5152 || icode == CODE_FOR_spe_evsubifw
0559cc77 5153 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5154 {
5155 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
5156 if (TREE_CODE (arg1) != INTEGER_CST
5157 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5158 {
5159 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5160 return const0_rtx;
b44140e7 5161 }
b44140e7
AH
5162 }
5163
c62f2db5 5164 if (target == 0
0ac081f6
AH
5165 || GET_MODE (target) != tmode
5166 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5167 target = gen_reg_rtx (tmode);
5168
5169 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5170 op0 = copy_to_mode_reg (mode0, op0);
5171 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5172 op1 = copy_to_mode_reg (mode1, op1);
5173
5174 pat = GEN_FCN (icode) (target, op0, op1);
5175 if (! pat)
5176 return 0;
5177 emit_insn (pat);
5178
5179 return target;
5180}
6525c0e7 5181
ae4b4a02
AH
5182static rtx
5183altivec_expand_predicate_builtin (icode, opcode, arglist, target)
5184 enum insn_code icode;
5185 const char *opcode;
5186 tree arglist;
5187 rtx target;
5188{
5189 rtx pat, scratch;
5190 tree cr6_form = TREE_VALUE (arglist);
5191 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5192 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5193 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5194 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5195 enum machine_mode tmode = SImode;
5196 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5197 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5198 int cr6_form_int;
5199
5200 if (TREE_CODE (cr6_form) != INTEGER_CST)
5201 {
5202 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5203 return const0_rtx;
ae4b4a02
AH
5204 }
5205 else
5206 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5207
5208 if (mode0 != mode1)
5209 abort ();
5210
5211 /* If we have invalid arguments, bail out before generating bad rtl. */
5212 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5213 return const0_rtx;
ae4b4a02
AH
5214
5215 if (target == 0
5216 || GET_MODE (target) != tmode
5217 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5218 target = gen_reg_rtx (tmode);
5219
5220 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5221 op0 = copy_to_mode_reg (mode0, op0);
5222 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5223 op1 = copy_to_mode_reg (mode1, op1);
5224
5225 scratch = gen_reg_rtx (mode0);
5226
5227 pat = GEN_FCN (icode) (scratch, op0, op1,
5228 gen_rtx (SYMBOL_REF, Pmode, opcode));
5229 if (! pat)
5230 return 0;
5231 emit_insn (pat);
5232
5233 /* The vec_any* and vec_all* predicates use the same opcodes for two
5234 different operations, but the bits in CR6 will be different
5235 depending on what information we want. So we have to play tricks
5236 with CR6 to get the right bits out.
5237
5238 If you think this is disgusting, look at the specs for the
5239 AltiVec predicates. */
5240
5241 switch (cr6_form_int)
5242 {
5243 case 0:
5244 emit_insn (gen_cr6_test_for_zero (target));
5245 break;
5246 case 1:
5247 emit_insn (gen_cr6_test_for_zero_reverse (target));
5248 break;
5249 case 2:
5250 emit_insn (gen_cr6_test_for_lt (target));
5251 break;
5252 case 3:
5253 emit_insn (gen_cr6_test_for_lt_reverse (target));
5254 break;
5255 default:
5256 error ("argument 1 of __builtin_altivec_predicate is out of range");
5257 break;
5258 }
5259
5260 return target;
5261}
5262
6525c0e7
AH
5263static rtx
5264altivec_expand_stv_builtin (icode, arglist)
5265 enum insn_code icode;
5266 tree arglist;
5267{
5268 tree arg0 = TREE_VALUE (arglist);
5269 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5270 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5271 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5272 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5273 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5274 rtx pat;
5275 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
5276 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
5277 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
5278
5279 /* Invalid arguments. Bail before doing anything stoopid! */
5280 if (arg0 == error_mark_node
5281 || arg1 == error_mark_node
5282 || arg2 == error_mark_node)
9a171fcd 5283 return const0_rtx;
6525c0e7
AH
5284
5285 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
5286 op0 = copy_to_mode_reg (mode2, op0);
5287 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
5288 op1 = copy_to_mode_reg (mode0, op1);
5289 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5290 op2 = copy_to_mode_reg (mode1, op2);
5291
5292 pat = GEN_FCN (icode) (op1, op2, op0);
5293 if (pat)
5294 emit_insn (pat);
5295 return NULL_RTX;
5296}
5297
2212663f 5298static rtx
92898235 5299rs6000_expand_ternop_builtin (icode, arglist, target)
2212663f
DB
5300 enum insn_code icode;
5301 tree arglist;
5302 rtx target;
5303{
5304 rtx pat;
5305 tree arg0 = TREE_VALUE (arglist);
5306 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5307 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5308 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5309 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5310 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5311 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5312 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5313 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5314 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5315
774b5662
DE
5316 if (icode == CODE_FOR_nothing)
5317 /* Builtin not supported on this processor. */
5318 return 0;
5319
20e26713
AH
5320 /* If we got invalid arguments bail out before generating bad rtl. */
5321 if (arg0 == error_mark_node
5322 || arg1 == error_mark_node
5323 || arg2 == error_mark_node)
9a171fcd 5324 return const0_rtx;
20e26713 5325
774b5662
DE
5326 if (icode == CODE_FOR_altivec_vsldoi_4sf
5327 || icode == CODE_FOR_altivec_vsldoi_4si
5328 || icode == CODE_FOR_altivec_vsldoi_8hi
5329 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5330 {
5331 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
5332 if (TREE_CODE (arg2) != INTEGER_CST
5333 || TREE_INT_CST_LOW (arg2) & ~0xf)
5334 {
5335 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5336 return const0_rtx;
b44140e7 5337 }
b44140e7
AH
5338 }
5339
c62f2db5 5340 if (target == 0
2212663f
DB
5341 || GET_MODE (target) != tmode
5342 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5343 target = gen_reg_rtx (tmode);
5344
5345 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5346 op0 = copy_to_mode_reg (mode0, op0);
5347 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5348 op1 = copy_to_mode_reg (mode1, op1);
5349 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5350 op2 = copy_to_mode_reg (mode2, op2);
5351
5352 pat = GEN_FCN (icode) (target, op0, op1, op2);
5353 if (! pat)
5354 return 0;
5355 emit_insn (pat);
5356
5357 return target;
5358}
92898235 5359
3a9b8c7e 5360/* Expand the lvx builtins. */
0ac081f6 5361static rtx
3a9b8c7e 5362altivec_expand_ld_builtin (exp, target, expandedp)
0ac081f6
AH
5363 tree exp;
5364 rtx target;
92898235 5365 bool *expandedp;
0ac081f6 5366{
0ac081f6
AH
5367 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5368 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5369 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5370 tree arg0;
5371 enum machine_mode tmode, mode0;
7c3abc73 5372 rtx pat, op0;
3a9b8c7e 5373 enum insn_code icode;
92898235 5374
0ac081f6
AH
5375 switch (fcode)
5376 {
f18c054f
DB
5377 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5378 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5379 break;
f18c054f
DB
5380 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5381 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5382 break;
5383 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5384 icode = CODE_FOR_altivec_lvx_4si;
5385 break;
5386 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5387 icode = CODE_FOR_altivec_lvx_4sf;
5388 break;
5389 default:
5390 *expandedp = false;
5391 return NULL_RTX;
5392 }
0ac081f6 5393
3a9b8c7e 5394 *expandedp = true;
f18c054f 5395
3a9b8c7e
AH
5396 arg0 = TREE_VALUE (arglist);
5397 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5398 tmode = insn_data[icode].operand[0].mode;
5399 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5400
3a9b8c7e
AH
5401 if (target == 0
5402 || GET_MODE (target) != tmode
5403 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5404 target = gen_reg_rtx (tmode);
24408032 5405
3a9b8c7e
AH
5406 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5407 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5408
3a9b8c7e
AH
5409 pat = GEN_FCN (icode) (target, op0);
5410 if (! pat)
5411 return 0;
5412 emit_insn (pat);
5413 return target;
5414}
f18c054f 5415
3a9b8c7e
AH
5416/* Expand the stvx builtins. */
5417static rtx
5418altivec_expand_st_builtin (exp, target, expandedp)
5419 tree exp;
7c3abc73 5420 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
5421 bool *expandedp;
5422{
5423 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5424 tree arglist = TREE_OPERAND (exp, 1);
5425 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5426 tree arg0, arg1;
5427 enum machine_mode mode0, mode1;
7c3abc73 5428 rtx pat, op0, op1;
3a9b8c7e 5429 enum insn_code icode;
f18c054f 5430
3a9b8c7e
AH
5431 switch (fcode)
5432 {
5433 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5434 icode = CODE_FOR_altivec_stvx_16qi;
5435 break;
5436 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5437 icode = CODE_FOR_altivec_stvx_8hi;
5438 break;
5439 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5440 icode = CODE_FOR_altivec_stvx_4si;
5441 break;
5442 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5443 icode = CODE_FOR_altivec_stvx_4sf;
5444 break;
5445 default:
5446 *expandedp = false;
5447 return NULL_RTX;
5448 }
24408032 5449
3a9b8c7e
AH
5450 arg0 = TREE_VALUE (arglist);
5451 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5452 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5453 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5454 mode0 = insn_data[icode].operand[0].mode;
5455 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5456
3a9b8c7e
AH
5457 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5458 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5459 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5460 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5461
3a9b8c7e
AH
5462 pat = GEN_FCN (icode) (op0, op1);
5463 if (pat)
5464 emit_insn (pat);
f18c054f 5465
3a9b8c7e
AH
5466 *expandedp = true;
5467 return NULL_RTX;
5468}
f18c054f 5469
3a9b8c7e
AH
5470/* Expand the dst builtins. */
5471static rtx
5472altivec_expand_dst_builtin (exp, target, expandedp)
5473 tree exp;
7c3abc73 5474 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
5475 bool *expandedp;
5476{
5477 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5478 tree arglist = TREE_OPERAND (exp, 1);
5479 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5480 tree arg0, arg1, arg2;
5481 enum machine_mode mode0, mode1, mode2;
7c3abc73 5482 rtx pat, op0, op1, op2;
3a9b8c7e 5483 struct builtin_description *d;
a3170dc6 5484 size_t i;
f18c054f 5485
3a9b8c7e 5486 *expandedp = false;
f18c054f 5487
3a9b8c7e
AH
5488 /* Handle DST variants. */
5489 d = (struct builtin_description *) bdesc_dst;
5490 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
5491 if (d->code == fcode)
5492 {
5493 arg0 = TREE_VALUE (arglist);
5494 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5495 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5496 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5497 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5498 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5499 mode0 = insn_data[d->icode].operand[0].mode;
5500 mode1 = insn_data[d->icode].operand[1].mode;
5501 mode2 = insn_data[d->icode].operand[2].mode;
24408032 5502
3a9b8c7e
AH
5503 /* Invalid arguments, bail out before generating bad rtl. */
5504 if (arg0 == error_mark_node
5505 || arg1 == error_mark_node
5506 || arg2 == error_mark_node)
5507 return const0_rtx;
f18c054f 5508
3a9b8c7e
AH
5509 if (TREE_CODE (arg2) != INTEGER_CST
5510 || TREE_INT_CST_LOW (arg2) & ~0x3)
5511 {
5512 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
5513 return const0_rtx;
5514 }
f18c054f 5515
3a9b8c7e
AH
5516 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
5517 op0 = copy_to_mode_reg (mode0, op0);
5518 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
5519 op1 = copy_to_mode_reg (mode1, op1);
24408032 5520
3a9b8c7e
AH
5521 pat = GEN_FCN (d->icode) (op0, op1, op2);
5522 if (pat != 0)
5523 emit_insn (pat);
f18c054f 5524
3a9b8c7e
AH
5525 *expandedp = true;
5526 return NULL_RTX;
5527 }
f18c054f 5528
3a9b8c7e
AH
5529 return NULL_RTX;
5530}
24408032 5531
3a9b8c7e
AH
5532/* Expand the builtin in EXP and store the result in TARGET. Store
5533 true in *EXPANDEDP if we found a builtin to expand. */
5534static rtx
5535altivec_expand_builtin (exp, target, expandedp)
5536 tree exp;
5537 rtx target;
5538 bool *expandedp;
5539{
5540 struct builtin_description *d;
5541 struct builtin_description_predicates *dp;
5542 size_t i;
5543 enum insn_code icode;
5544 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5545 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
5546 tree arg0;
5547 rtx op0, pat;
5548 enum machine_mode tmode, mode0;
3a9b8c7e 5549 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 5550
3a9b8c7e
AH
5551 target = altivec_expand_ld_builtin (exp, target, expandedp);
5552 if (*expandedp)
5553 return target;
0ac081f6 5554
3a9b8c7e
AH
5555 target = altivec_expand_st_builtin (exp, target, expandedp);
5556 if (*expandedp)
5557 return target;
5558
5559 target = altivec_expand_dst_builtin (exp, target, expandedp);
5560 if (*expandedp)
5561 return target;
5562
5563 *expandedp = true;
95385cbb 5564
3a9b8c7e
AH
5565 switch (fcode)
5566 {
6525c0e7
AH
5567 case ALTIVEC_BUILTIN_STVX:
5568 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
5569 case ALTIVEC_BUILTIN_STVEBX:
5570 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
5571 case ALTIVEC_BUILTIN_STVEHX:
5572 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
5573 case ALTIVEC_BUILTIN_STVEWX:
5574 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
5575 case ALTIVEC_BUILTIN_STVXL:
5576 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 5577
95385cbb
AH
5578 case ALTIVEC_BUILTIN_MFVSCR:
5579 icode = CODE_FOR_altivec_mfvscr;
5580 tmode = insn_data[icode].operand[0].mode;
5581
5582 if (target == 0
5583 || GET_MODE (target) != tmode
5584 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5585 target = gen_reg_rtx (tmode);
5586
5587 pat = GEN_FCN (icode) (target);
0ac081f6
AH
5588 if (! pat)
5589 return 0;
5590 emit_insn (pat);
95385cbb
AH
5591 return target;
5592
5593 case ALTIVEC_BUILTIN_MTVSCR:
5594 icode = CODE_FOR_altivec_mtvscr;
5595 arg0 = TREE_VALUE (arglist);
5596 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5597 mode0 = insn_data[icode].operand[0].mode;
5598
5599 /* If we got invalid arguments bail out before generating bad rtl. */
5600 if (arg0 == error_mark_node)
9a171fcd 5601 return const0_rtx;
95385cbb
AH
5602
5603 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5604 op0 = copy_to_mode_reg (mode0, op0);
5605
5606 pat = GEN_FCN (icode) (op0);
5607 if (pat)
5608 emit_insn (pat);
5609 return NULL_RTX;
3a9b8c7e 5610
95385cbb
AH
5611 case ALTIVEC_BUILTIN_DSSALL:
5612 emit_insn (gen_altivec_dssall ());
5613 return NULL_RTX;
5614
5615 case ALTIVEC_BUILTIN_DSS:
5616 icode = CODE_FOR_altivec_dss;
5617 arg0 = TREE_VALUE (arglist);
5618 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5619 mode0 = insn_data[icode].operand[0].mode;
5620
5621 /* If we got invalid arguments bail out before generating bad rtl. */
5622 if (arg0 == error_mark_node)
9a171fcd 5623 return const0_rtx;
95385cbb 5624
b44140e7
AH
5625 if (TREE_CODE (arg0) != INTEGER_CST
5626 || TREE_INT_CST_LOW (arg0) & ~0x3)
5627 {
5628 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 5629 return const0_rtx;
b44140e7
AH
5630 }
5631
95385cbb
AH
5632 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5633 op0 = copy_to_mode_reg (mode0, op0);
5634
5635 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
5636 return NULL_RTX;
5637 }
24408032 5638
100c4561
AH
5639 /* Expand abs* operations. */
5640 d = (struct builtin_description *) bdesc_abs;
ca7558fc 5641 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
5642 if (d->code == fcode)
5643 return altivec_expand_abs_builtin (d->icode, arglist, target);
5644
ae4b4a02
AH
5645 /* Expand the AltiVec predicates. */
5646 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 5647 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
5648 if (dp->code == fcode)
5649 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
5650
6525c0e7
AH
5651 /* LV* are funky. We initialized them differently. */
5652 switch (fcode)
5653 {
5654 case ALTIVEC_BUILTIN_LVSL:
92898235 5655 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
5656 arglist, target);
5657 case ALTIVEC_BUILTIN_LVSR:
92898235
AH
5658 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
5659 arglist, target);
6525c0e7 5660 case ALTIVEC_BUILTIN_LVEBX:
92898235
AH
5661 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
5662 arglist, target);
6525c0e7 5663 case ALTIVEC_BUILTIN_LVEHX:
92898235
AH
5664 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
5665 arglist, target);
6525c0e7 5666 case ALTIVEC_BUILTIN_LVEWX:
92898235
AH
5667 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
5668 arglist, target);
6525c0e7 5669 case ALTIVEC_BUILTIN_LVXL:
92898235
AH
5670 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
5671 arglist, target);
6525c0e7 5672 case ALTIVEC_BUILTIN_LVX:
92898235
AH
5673 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
5674 arglist, target);
6525c0e7
AH
5675 default:
5676 break;
5677 /* Fall through. */
5678 }
95385cbb 5679
92898235 5680 *expandedp = false;
0ac081f6
AH
5681 return NULL_RTX;
5682}
5683
a3170dc6
AH
5684/* Binops that need to be initialized manually, but can be expanded
5685 automagically by rs6000_expand_binop_builtin. */
5686static struct builtin_description bdesc_2arg_spe[] =
5687{
5688 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
5689 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
5690 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
5691 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
5692 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
5693 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
5694 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
5695 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
5696 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
5697 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
5698 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
5699 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
5700 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
5701 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
5702 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
5703 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
5704 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
5705 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
5706 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
5707 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
5708 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
5709 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
5710};
5711
5712/* Expand the builtin in EXP and store the result in TARGET. Store
5713 true in *EXPANDEDP if we found a builtin to expand.
5714
5715 This expands the SPE builtins that are not simple unary and binary
5716 operations. */
5717static rtx
5718spe_expand_builtin (exp, target, expandedp)
5719 tree exp;
5720 rtx target;
5721 bool *expandedp;
5722{
5723 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5724 tree arglist = TREE_OPERAND (exp, 1);
5725 tree arg1, arg0;
5726 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5727 enum insn_code icode;
5728 enum machine_mode tmode, mode0;
5729 rtx pat, op0;
5730 struct builtin_description *d;
5731 size_t i;
5732
5733 *expandedp = true;
5734
5735 /* Syntax check for a 5-bit unsigned immediate. */
5736 switch (fcode)
5737 {
5738 case SPE_BUILTIN_EVSTDD:
5739 case SPE_BUILTIN_EVSTDH:
5740 case SPE_BUILTIN_EVSTDW:
5741 case SPE_BUILTIN_EVSTWHE:
5742 case SPE_BUILTIN_EVSTWHO:
5743 case SPE_BUILTIN_EVSTWWE:
5744 case SPE_BUILTIN_EVSTWWO:
5745 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5746 if (TREE_CODE (arg1) != INTEGER_CST
5747 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5748 {
5749 error ("argument 2 must be a 5-bit unsigned literal");
5750 return const0_rtx;
5751 }
5752 break;
5753 default:
5754 break;
5755 }
5756
5757 d = (struct builtin_description *) bdesc_2arg_spe;
5758 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
5759 if (d->code == fcode)
5760 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5761
5762 d = (struct builtin_description *) bdesc_spe_predicates;
5763 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
5764 if (d->code == fcode)
5765 return spe_expand_predicate_builtin (d->icode, arglist, target);
5766
5767 d = (struct builtin_description *) bdesc_spe_evsel;
5768 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
5769 if (d->code == fcode)
5770 return spe_expand_evsel_builtin (d->icode, arglist, target);
5771
5772 switch (fcode)
5773 {
5774 case SPE_BUILTIN_EVSTDDX:
5775 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
5776 case SPE_BUILTIN_EVSTDHX:
5777 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
5778 case SPE_BUILTIN_EVSTDWX:
5779 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
5780 case SPE_BUILTIN_EVSTWHEX:
5781 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
5782 case SPE_BUILTIN_EVSTWHOX:
5783 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
5784 case SPE_BUILTIN_EVSTWWEX:
5785 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
5786 case SPE_BUILTIN_EVSTWWOX:
5787 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
5788 case SPE_BUILTIN_EVSTDD:
5789 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
5790 case SPE_BUILTIN_EVSTDH:
5791 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
5792 case SPE_BUILTIN_EVSTDW:
5793 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
5794 case SPE_BUILTIN_EVSTWHE:
5795 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
5796 case SPE_BUILTIN_EVSTWHO:
5797 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
5798 case SPE_BUILTIN_EVSTWWE:
5799 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
5800 case SPE_BUILTIN_EVSTWWO:
5801 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
5802 case SPE_BUILTIN_MFSPEFSCR:
5803 icode = CODE_FOR_spe_mfspefscr;
5804 tmode = insn_data[icode].operand[0].mode;
5805
5806 if (target == 0
5807 || GET_MODE (target) != tmode
5808 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5809 target = gen_reg_rtx (tmode);
5810
5811 pat = GEN_FCN (icode) (target);
5812 if (! pat)
5813 return 0;
5814 emit_insn (pat);
5815 return target;
5816 case SPE_BUILTIN_MTSPEFSCR:
5817 icode = CODE_FOR_spe_mtspefscr;
5818 arg0 = TREE_VALUE (arglist);
5819 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5820 mode0 = insn_data[icode].operand[0].mode;
5821
5822 if (arg0 == error_mark_node)
5823 return const0_rtx;
5824
5825 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5826 op0 = copy_to_mode_reg (mode0, op0);
5827
5828 pat = GEN_FCN (icode) (op0);
5829 if (pat)
5830 emit_insn (pat);
5831 return NULL_RTX;
5832 default:
5833 break;
5834 }
5835
5836 *expandedp = false;
5837 return NULL_RTX;
5838}
5839
5840static rtx
5841spe_expand_predicate_builtin (icode, arglist, target)
5842 enum insn_code icode;
5843 tree arglist;
5844 rtx target;
5845{
5846 rtx pat, scratch, tmp;
5847 tree form = TREE_VALUE (arglist);
5848 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5849 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5850 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5851 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5852 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5853 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5854 int form_int;
5855 enum rtx_code code;
5856
5857 if (TREE_CODE (form) != INTEGER_CST)
5858 {
5859 error ("argument 1 of __builtin_spe_predicate must be a constant");
5860 return const0_rtx;
5861 }
5862 else
5863 form_int = TREE_INT_CST_LOW (form);
5864
5865 if (mode0 != mode1)
5866 abort ();
5867
5868 if (arg0 == error_mark_node || arg1 == error_mark_node)
5869 return const0_rtx;
5870
5871 if (target == 0
5872 || GET_MODE (target) != SImode
5873 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
5874 target = gen_reg_rtx (SImode);
5875
5876 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5877 op0 = copy_to_mode_reg (mode0, op0);
5878 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5879 op1 = copy_to_mode_reg (mode1, op1);
5880
5881 scratch = gen_reg_rtx (CCmode);
5882
5883 pat = GEN_FCN (icode) (scratch, op0, op1);
5884 if (! pat)
5885 return const0_rtx;
5886 emit_insn (pat);
5887
5888 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
5889 _lower_. We use one compare, but look in different bits of the
5890 CR for each variant.
5891
5892 There are 2 elements in each SPE simd type (upper/lower). The CR
5893 bits are set as follows:
5894
5895 BIT0 | BIT 1 | BIT 2 | BIT 3
5896 U | L | (U | L) | (U & L)
5897
5898 So, for an "all" relationship, BIT 3 would be set.
5899 For an "any" relationship, BIT 2 would be set. Etc.
5900
5901 Following traditional nomenclature, these bits map to:
5902
5903 BIT0 | BIT 1 | BIT 2 | BIT 3
5904 LT | GT | EQ | OV
5905
5906 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
5907 */
5908
5909 switch (form_int)
5910 {
5911 /* All variant. OV bit. */
5912 case 0:
5913 /* We need to get to the OV bit, which is the ORDERED bit. We
5914 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
5915 that's ugly and will trigger a validate_condition_mode abort.
5916 So let's just use another pattern. */
5917 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
5918 return target;
5919 /* Any variant. EQ bit. */
5920 case 1:
5921 code = EQ;
5922 break;
5923 /* Upper variant. LT bit. */
5924 case 2:
5925 code = LT;
5926 break;
5927 /* Lower variant. GT bit. */
5928 case 3:
5929 code = GT;
5930 break;
5931 default:
5932 error ("argument 1 of __builtin_spe_predicate is out of range");
5933 return const0_rtx;
5934 }
5935
5936 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
5937 emit_move_insn (target, tmp);
5938
5939 return target;
5940}
5941
5942/* The evsel builtins look like this:
5943
5944 e = __builtin_spe_evsel_OP (a, b, c, d);
5945
5946 and work like this:
5947
5948 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
5949 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
5950*/
5951
5952static rtx
5953spe_expand_evsel_builtin (icode, arglist, target)
5954 enum insn_code icode;
5955 tree arglist;
5956 rtx target;
5957{
5958 rtx pat, scratch;
5959 tree arg0 = TREE_VALUE (arglist);
5960 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5961 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5962 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
5963 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5964 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5965 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5966 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
5967 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5968 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5969
5970 if (mode0 != mode1)
5971 abort ();
5972
5973 if (arg0 == error_mark_node || arg1 == error_mark_node
5974 || arg2 == error_mark_node || arg3 == error_mark_node)
5975 return const0_rtx;
5976
5977 if (target == 0
5978 || GET_MODE (target) != mode0
5979 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
5980 target = gen_reg_rtx (mode0);
5981
5982 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5983 op0 = copy_to_mode_reg (mode0, op0);
5984 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5985 op1 = copy_to_mode_reg (mode0, op1);
5986 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5987 op2 = copy_to_mode_reg (mode0, op2);
5988 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
5989 op3 = copy_to_mode_reg (mode0, op3);
5990
5991 /* Generate the compare. */
5992 scratch = gen_reg_rtx (CCmode);
5993 pat = GEN_FCN (icode) (scratch, op0, op1);
5994 if (! pat)
5995 return const0_rtx;
5996 emit_insn (pat);
5997
5998 if (mode0 == V2SImode)
5999 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6000 else
6001 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6002
6003 return target;
6004}
6005
0ac081f6
AH
6006/* Expand an expression EXP that calls a built-in function,
6007 with result going to TARGET if that's convenient
6008 (and in mode MODE if that's convenient).
6009 SUBTARGET may be used as the target for computing one of EXP's operands.
6010 IGNORE is nonzero if the value is to be ignored. */
6011
6012static rtx
6013rs6000_expand_builtin (exp, target, subtarget, mode, ignore)
6014 tree exp;
6015 rtx target;
00b960c7
AH
6016 rtx subtarget ATTRIBUTE_UNUSED;
6017 enum machine_mode mode ATTRIBUTE_UNUSED;
6018 int ignore ATTRIBUTE_UNUSED;
0ac081f6 6019{
92898235
AH
6020 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6021 tree arglist = TREE_OPERAND (exp, 1);
6022 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6023 struct builtin_description *d;
6024 size_t i;
6025 rtx ret;
6026 bool success;
6027
0ac081f6 6028 if (TARGET_ALTIVEC)
92898235
AH
6029 {
6030 ret = altivec_expand_builtin (exp, target, &success);
6031
a3170dc6
AH
6032 if (success)
6033 return ret;
6034 }
6035 if (TARGET_SPE)
6036 {
6037 ret = spe_expand_builtin (exp, target, &success);
6038
92898235
AH
6039 if (success)
6040 return ret;
6041 }
6042
0559cc77
DE
6043 if (TARGET_ALTIVEC || TARGET_SPE)
6044 {
6045 /* Handle simple unary operations. */
6046 d = (struct builtin_description *) bdesc_1arg;
6047 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6048 if (d->code == fcode)
6049 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6050
6051 /* Handle simple binary operations. */
6052 d = (struct builtin_description *) bdesc_2arg;
6053 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6054 if (d->code == fcode)
6055 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6056
6057 /* Handle simple ternary operations. */
6058 d = (struct builtin_description *) bdesc_3arg;
6059 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6060 if (d->code == fcode)
6061 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6062 }
0ac081f6
AH
6063
6064 abort ();
92898235 6065 return NULL_RTX;
0ac081f6
AH
6066}
6067
6068static void
6fa3f289 6069rs6000_init_builtins ()
0ac081f6 6070{
3fdaa45a
AH
6071 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6072 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6073 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6074
a3170dc6 6075 if (TARGET_SPE)
3fdaa45a 6076 spe_init_builtins ();
0ac081f6
AH
6077 if (TARGET_ALTIVEC)
6078 altivec_init_builtins ();
0559cc77
DE
6079 if (TARGET_ALTIVEC || TARGET_SPE)
6080 rs6000_common_init_builtins ();
0ac081f6
AH
6081}
6082
a3170dc6
AH
6083/* Search through a set of builtins and enable the mask bits.
6084 DESC is an array of builtins.
b6d08ca1 6085 SIZE is the total number of builtins.
a3170dc6
AH
6086 START is the builtin enum at which to start.
6087 END is the builtin enum at which to end. */
0ac081f6 6088static void
a3170dc6
AH
6089enable_mask_for_builtins (desc, size, start, end)
6090 struct builtin_description *desc;
6091 int size;
6092 enum rs6000_builtins start, end;
6093{
6094 int i;
6095
6096 for (i = 0; i < size; ++i)
6097 if (desc[i].code == start)
6098 break;
6099
6100 if (i == size)
6101 return;
6102
6103 for (; i < size; ++i)
6104 {
6105 /* Flip all the bits on. */
6106 desc[i].mask = target_flags;
6107 if (desc[i].code == end)
6108 break;
6109 }
6110}
6111
6112static void
b24c9d35 6113spe_init_builtins ()
0ac081f6 6114{
a3170dc6
AH
6115 tree endlink = void_list_node;
6116 tree puint_type_node = build_pointer_type (unsigned_type_node);
6117 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6118 struct builtin_description *d;
0ac081f6
AH
6119 size_t i;
6120
a3170dc6
AH
6121 tree v2si_ftype_4_v2si
6122 = build_function_type
3fdaa45a
AH
6123 (opaque_V2SI_type_node,
6124 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6125 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6126 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6127 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6128 endlink)))));
6129
6130 tree v2sf_ftype_4_v2sf
6131 = build_function_type
3fdaa45a
AH
6132 (opaque_V2SF_type_node,
6133 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6134 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6135 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6136 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6137 endlink)))));
6138
6139 tree int_ftype_int_v2si_v2si
6140 = build_function_type
6141 (integer_type_node,
6142 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6143 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6144 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6145 endlink))));
6146
6147 tree int_ftype_int_v2sf_v2sf
6148 = build_function_type
6149 (integer_type_node,
6150 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6151 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6152 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6153 endlink))));
6154
6155 tree void_ftype_v2si_puint_int
6156 = build_function_type (void_type_node,
3fdaa45a 6157 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6158 tree_cons (NULL_TREE, puint_type_node,
6159 tree_cons (NULL_TREE,
6160 integer_type_node,
6161 endlink))));
6162
6163 tree void_ftype_v2si_puint_char
6164 = build_function_type (void_type_node,
3fdaa45a 6165 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6166 tree_cons (NULL_TREE, puint_type_node,
6167 tree_cons (NULL_TREE,
6168 char_type_node,
6169 endlink))));
6170
6171 tree void_ftype_v2si_pv2si_int
6172 = build_function_type (void_type_node,
3fdaa45a 6173 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6174 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6175 tree_cons (NULL_TREE,
6176 integer_type_node,
6177 endlink))));
6178
6179 tree void_ftype_v2si_pv2si_char
6180 = build_function_type (void_type_node,
3fdaa45a 6181 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6182 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6183 tree_cons (NULL_TREE,
6184 char_type_node,
6185 endlink))));
6186
6187 tree void_ftype_int
6188 = build_function_type (void_type_node,
6189 tree_cons (NULL_TREE, integer_type_node, endlink));
6190
6191 tree int_ftype_void
36e8d515 6192 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6193
6194 tree v2si_ftype_pv2si_int
3fdaa45a 6195 = build_function_type (opaque_V2SI_type_node,
6035d635 6196 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6197 tree_cons (NULL_TREE, integer_type_node,
6198 endlink)));
6199
6200 tree v2si_ftype_puint_int
3fdaa45a 6201 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6202 tree_cons (NULL_TREE, puint_type_node,
6203 tree_cons (NULL_TREE, integer_type_node,
6204 endlink)));
6205
6206 tree v2si_ftype_pushort_int
3fdaa45a 6207 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6208 tree_cons (NULL_TREE, pushort_type_node,
6209 tree_cons (NULL_TREE, integer_type_node,
6210 endlink)));
6211
6212 /* The initialization of the simple binary and unary builtins is
6213 done in rs6000_common_init_builtins, but we have to enable the
6214 mask bits here manually because we have run out of `target_flags'
6215 bits. We really need to redesign this mask business. */
6216
6217 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6218 ARRAY_SIZE (bdesc_2arg),
6219 SPE_BUILTIN_EVADDW,
6220 SPE_BUILTIN_EVXOR);
6221 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6222 ARRAY_SIZE (bdesc_1arg),
6223 SPE_BUILTIN_EVABS,
6224 SPE_BUILTIN_EVSUBFUSIAAW);
6225 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6226 ARRAY_SIZE (bdesc_spe_predicates),
6227 SPE_BUILTIN_EVCMPEQ,
6228 SPE_BUILTIN_EVFSTSTLT);
6229 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6230 ARRAY_SIZE (bdesc_spe_evsel),
6231 SPE_BUILTIN_EVSEL_CMPGTS,
6232 SPE_BUILTIN_EVSEL_FSTSTEQ);
6233
36252949
AH
6234 (*lang_hooks.decls.pushdecl)
6235 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6236 opaque_V2SI_type_node));
6237
a3170dc6
AH
6238 /* Initialize irregular SPE builtins. */
6239
6240 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6241 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6242 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6243 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6244 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6245 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6246 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6247 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6248 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6249 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6250 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6251 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6252 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6253 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6254 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6255 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
6256
6257 /* Loads. */
6258 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6259 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6260 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6261 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6262 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6263 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6264 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6265 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6266 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6267 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6268 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6269 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6270 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6271 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6272 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6273 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6274 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6275 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6276 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6277 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6278 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6279 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6280
6281 /* Predicates. */
6282 d = (struct builtin_description *) bdesc_spe_predicates;
6283 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6284 {
6285 tree type;
6286
6287 switch (insn_data[d->icode].operand[1].mode)
6288 {
6289 case V2SImode:
6290 type = int_ftype_int_v2si_v2si;
6291 break;
6292 case V2SFmode:
6293 type = int_ftype_int_v2sf_v2sf;
6294 break;
6295 default:
6296 abort ();
6297 }
6298
6299 def_builtin (d->mask, d->name, type, d->code);
6300 }
6301
6302 /* Evsel predicates. */
6303 d = (struct builtin_description *) bdesc_spe_evsel;
6304 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6305 {
6306 tree type;
6307
6308 switch (insn_data[d->icode].operand[1].mode)
6309 {
6310 case V2SImode:
6311 type = v2si_ftype_4_v2si;
6312 break;
6313 case V2SFmode:
6314 type = v2sf_ftype_4_v2sf;
6315 break;
6316 default:
6317 abort ();
6318 }
6319
6320 def_builtin (d->mask, d->name, type, d->code);
6321 }
6322}
6323
6324static void
b24c9d35 6325altivec_init_builtins ()
a3170dc6
AH
6326{
6327 struct builtin_description *d;
6328 struct builtin_description_predicates *dp;
6329 size_t i;
6330 tree pfloat_type_node = build_pointer_type (float_type_node);
6331 tree pint_type_node = build_pointer_type (integer_type_node);
6332 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6333 tree pchar_type_node = build_pointer_type (char_type_node);
6334
6335 tree pvoid_type_node = build_pointer_type (void_type_node);
6336
0dbc3651
ZW
6337 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6338 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6339 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6340 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6341
6342 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6343
a3170dc6
AH
6344 tree int_ftype_int_v4si_v4si
6345 = build_function_type_list (integer_type_node,
6346 integer_type_node, V4SI_type_node,
6347 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6348 tree v4sf_ftype_pcfloat
6349 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6350 tree void_ftype_pfloat_v4sf
b4de2f7d 6351 = build_function_type_list (void_type_node,
a3170dc6 6352 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6353 tree v4si_ftype_pcint
6354 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6355 tree void_ftype_pint_v4si
b4de2f7d
AH
6356 = build_function_type_list (void_type_node,
6357 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6358 tree v8hi_ftype_pcshort
6359 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6360 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6361 = build_function_type_list (void_type_node,
6362 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6363 tree v16qi_ftype_pcchar
6364 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6365 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6366 = build_function_type_list (void_type_node,
6367 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6368 tree void_ftype_v4si
b4de2f7d 6369 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6370 tree v8hi_ftype_void
6371 = build_function_type (V8HI_type_node, void_list_node);
6372 tree void_ftype_void
6373 = build_function_type (void_type_node, void_list_node);
6374 tree void_ftype_qi
6375 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651
ZW
6376
6377 tree v16qi_ftype_int_pcvoid
a3170dc6 6378 = build_function_type_list (V16QI_type_node,
0dbc3651
ZW
6379 integer_type_node, pcvoid_type_node, NULL_TREE);
6380 tree v8hi_ftype_int_pcvoid
a3170dc6 6381 = build_function_type_list (V8HI_type_node,
0dbc3651
ZW
6382 integer_type_node, pcvoid_type_node, NULL_TREE);
6383 tree v4si_ftype_int_pcvoid
a3170dc6 6384 = build_function_type_list (V4SI_type_node,
0dbc3651
ZW
6385 integer_type_node, pcvoid_type_node, NULL_TREE);
6386
14b32f4e 6387 tree void_ftype_v4si_int_pvoid
b4de2f7d
AH
6388 = build_function_type_list (void_type_node,
6389 V4SI_type_node, integer_type_node,
6390 pvoid_type_node, NULL_TREE);
6525c0e7 6391 tree void_ftype_v16qi_int_pvoid
b4de2f7d
AH
6392 = build_function_type_list (void_type_node,
6393 V16QI_type_node, integer_type_node,
6394 pvoid_type_node, NULL_TREE);
6525c0e7 6395 tree void_ftype_v8hi_int_pvoid
b4de2f7d
AH
6396 = build_function_type_list (void_type_node,
6397 V8HI_type_node, integer_type_node,
6398 pvoid_type_node, NULL_TREE);
a3170dc6
AH
6399 tree int_ftype_int_v8hi_v8hi
6400 = build_function_type_list (integer_type_node,
6401 integer_type_node, V8HI_type_node,
6402 V8HI_type_node, NULL_TREE);
6403 tree int_ftype_int_v16qi_v16qi
6404 = build_function_type_list (integer_type_node,
6405 integer_type_node, V16QI_type_node,
6406 V16QI_type_node, NULL_TREE);
6407 tree int_ftype_int_v4sf_v4sf
6408 = build_function_type_list (integer_type_node,
6409 integer_type_node, V4SF_type_node,
6410 V4SF_type_node, NULL_TREE);
6411 tree v4si_ftype_v4si
6412 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
6413 tree v8hi_ftype_v8hi
6414 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
6415 tree v16qi_ftype_v16qi
6416 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
6417 tree v4sf_ftype_v4sf
6418 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 6419 tree void_ftype_pcvoid_int_char
a3170dc6 6420 = build_function_type_list (void_type_node,
0dbc3651 6421 pcvoid_type_node, integer_type_node,
a3170dc6 6422 char_type_node, NULL_TREE);
0dbc3651
ZW
6423
6424 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
6425 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
6426 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
6427 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
6428 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
6429 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
6430 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
6431 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
6432 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
6433 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
6434 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
6435 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
6436 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
6437 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
6438 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
6439 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
6440 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
6441 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
6442 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
6443 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
0dbc3651
ZW
6444 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL);
6445 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR);
6446 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX);
6447 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX);
6448 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX);
6449 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL);
6450 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX);
a3170dc6
AH
6451 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX);
6452 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX);
6453 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL);
6454 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX);
6455 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX);
6456
6457 /* Add the DST variants. */
6458 d = (struct builtin_description *) bdesc_dst;
6459 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 6460 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
6461
6462 /* Initialize the predicates. */
6463 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
6464 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
6465 {
6466 enum machine_mode mode1;
6467 tree type;
6468
6469 mode1 = insn_data[dp->icode].operand[1].mode;
6470
6471 switch (mode1)
6472 {
6473 case V4SImode:
6474 type = int_ftype_int_v4si_v4si;
6475 break;
6476 case V8HImode:
6477 type = int_ftype_int_v8hi_v8hi;
6478 break;
6479 case V16QImode:
6480 type = int_ftype_int_v16qi_v16qi;
6481 break;
6482 case V4SFmode:
6483 type = int_ftype_int_v4sf_v4sf;
6484 break;
6485 default:
6486 abort ();
6487 }
6488
6489 def_builtin (dp->mask, dp->name, type, dp->code);
6490 }
6491
6492 /* Initialize the abs* operators. */
6493 d = (struct builtin_description *) bdesc_abs;
6494 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
6495 {
6496 enum machine_mode mode0;
6497 tree type;
6498
6499 mode0 = insn_data[d->icode].operand[0].mode;
6500
6501 switch (mode0)
6502 {
6503 case V4SImode:
6504 type = v4si_ftype_v4si;
6505 break;
6506 case V8HImode:
6507 type = v8hi_ftype_v8hi;
6508 break;
6509 case V16QImode:
6510 type = v16qi_ftype_v16qi;
6511 break;
6512 case V4SFmode:
6513 type = v4sf_ftype_v4sf;
6514 break;
6515 default:
6516 abort ();
6517 }
6518
6519 def_builtin (d->mask, d->name, type, d->code);
6520 }
6521}
6522
6523static void
b24c9d35 6524rs6000_common_init_builtins ()
a3170dc6
AH
6525{
6526 struct builtin_description *d;
6527 size_t i;
6528
6529 tree v4sf_ftype_v4sf_v4sf_v16qi
6530 = build_function_type_list (V4SF_type_node,
6531 V4SF_type_node, V4SF_type_node,
6532 V16QI_type_node, NULL_TREE);
6533 tree v4si_ftype_v4si_v4si_v16qi
6534 = build_function_type_list (V4SI_type_node,
6535 V4SI_type_node, V4SI_type_node,
6536 V16QI_type_node, NULL_TREE);
6537 tree v8hi_ftype_v8hi_v8hi_v16qi
6538 = build_function_type_list (V8HI_type_node,
6539 V8HI_type_node, V8HI_type_node,
6540 V16QI_type_node, NULL_TREE);
6541 tree v16qi_ftype_v16qi_v16qi_v16qi
6542 = build_function_type_list (V16QI_type_node,
6543 V16QI_type_node, V16QI_type_node,
6544 V16QI_type_node, NULL_TREE);
6545 tree v4si_ftype_char
6546 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
6547 tree v8hi_ftype_char
6548 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
6549 tree v16qi_ftype_char
6550 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
6551 tree v8hi_ftype_v16qi
6552 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
6553 tree v4sf_ftype_v4sf
6554 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
6555
6556 tree v2si_ftype_v2si_v2si
2abe3e28
AH
6557 = build_function_type_list (opaque_V2SI_type_node,
6558 opaque_V2SI_type_node,
6559 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6560
6561 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
6562 = build_function_type_list (opaque_V2SF_type_node,
6563 opaque_V2SF_type_node,
6564 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6565
6566 tree v2si_ftype_int_int
2abe3e28 6567 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6568 integer_type_node, integer_type_node,
6569 NULL_TREE);
6570
6571 tree v2si_ftype_v2si
2abe3e28
AH
6572 = build_function_type_list (opaque_V2SI_type_node,
6573 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6574
6575 tree v2sf_ftype_v2sf
2abe3e28
AH
6576 = build_function_type_list (opaque_V2SF_type_node,
6577 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6578
6579 tree v2sf_ftype_v2si
2abe3e28
AH
6580 = build_function_type_list (opaque_V2SF_type_node,
6581 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6582
6583 tree v2si_ftype_v2sf
2abe3e28
AH
6584 = build_function_type_list (opaque_V2SI_type_node,
6585 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6586
6587 tree v2si_ftype_v2si_char
2abe3e28
AH
6588 = build_function_type_list (opaque_V2SI_type_node,
6589 opaque_V2SI_type_node,
6590 char_type_node, NULL_TREE);
a3170dc6
AH
6591
6592 tree v2si_ftype_int_char
2abe3e28 6593 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6594 integer_type_node, char_type_node, NULL_TREE);
6595
6596 tree v2si_ftype_char
2abe3e28
AH
6597 = build_function_type_list (opaque_V2SI_type_node,
6598 char_type_node, NULL_TREE);
a3170dc6
AH
6599
6600 tree int_ftype_int_int
6601 = build_function_type_list (integer_type_node,
6602 integer_type_node, integer_type_node,
6603 NULL_TREE);
95385cbb 6604
0ac081f6 6605 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
6606 = build_function_type_list (V4SI_type_node,
6607 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 6608 tree v4sf_ftype_v4si_char
b4de2f7d
AH
6609 = build_function_type_list (V4SF_type_node,
6610 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 6611 tree v4si_ftype_v4sf_char
b4de2f7d
AH
6612 = build_function_type_list (V4SI_type_node,
6613 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 6614 tree v4si_ftype_v4si_char
b4de2f7d
AH
6615 = build_function_type_list (V4SI_type_node,
6616 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 6617 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
6618 = build_function_type_list (V8HI_type_node,
6619 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 6620 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
6621 = build_function_type_list (V16QI_type_node,
6622 V16QI_type_node, char_type_node, NULL_TREE);
24408032 6623 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
6624 = build_function_type_list (V16QI_type_node,
6625 V16QI_type_node, V16QI_type_node,
6626 char_type_node, NULL_TREE);
24408032 6627 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
6628 = build_function_type_list (V8HI_type_node,
6629 V8HI_type_node, V8HI_type_node,
6630 char_type_node, NULL_TREE);
24408032 6631 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
6632 = build_function_type_list (V4SI_type_node,
6633 V4SI_type_node, V4SI_type_node,
6634 char_type_node, NULL_TREE);
24408032 6635 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
6636 = build_function_type_list (V4SF_type_node,
6637 V4SF_type_node, V4SF_type_node,
6638 char_type_node, NULL_TREE);
0ac081f6 6639 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
6640 = build_function_type_list (V4SF_type_node,
6641 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 6642 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
6643 = build_function_type_list (V4SF_type_node,
6644 V4SF_type_node, V4SF_type_node,
6645 V4SI_type_node, NULL_TREE);
2212663f 6646 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
6647 = build_function_type_list (V4SF_type_node,
6648 V4SF_type_node, V4SF_type_node,
6649 V4SF_type_node, NULL_TREE);
617e0e1d 6650 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
6651 = build_function_type_list (V4SI_type_node,
6652 V4SI_type_node, V4SI_type_node,
6653 V4SI_type_node, NULL_TREE);
0ac081f6 6654 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
6655 = build_function_type_list (V8HI_type_node,
6656 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 6657 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
6658 = build_function_type_list (V8HI_type_node,
6659 V8HI_type_node, V8HI_type_node,
6660 V8HI_type_node, NULL_TREE);
2212663f 6661 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
6662 = build_function_type_list (V4SI_type_node,
6663 V8HI_type_node, V8HI_type_node,
6664 V4SI_type_node, NULL_TREE);
2212663f 6665 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
6666 = build_function_type_list (V4SI_type_node,
6667 V16QI_type_node, V16QI_type_node,
6668 V4SI_type_node, NULL_TREE);
0ac081f6 6669 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
6670 = build_function_type_list (V16QI_type_node,
6671 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6672 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
6673 = build_function_type_list (V4SI_type_node,
6674 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 6675 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
6676 = build_function_type_list (V8HI_type_node,
6677 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6678 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
6679 = build_function_type_list (V4SI_type_node,
6680 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6681 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
6682 = build_function_type_list (V8HI_type_node,
6683 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 6684 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
6685 = build_function_type_list (V16QI_type_node,
6686 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6687 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
6688 = build_function_type_list (V4SI_type_node,
6689 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 6690 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
6691 = build_function_type_list (V4SI_type_node,
6692 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6693 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
6694 = build_function_type_list (V4SI_type_node,
6695 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6696 tree v4si_ftype_v8hi
6697 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
6698 tree int_ftype_v4si_v4si
6699 = build_function_type_list (integer_type_node,
6700 V4SI_type_node, V4SI_type_node, NULL_TREE);
6701 tree int_ftype_v4sf_v4sf
6702 = build_function_type_list (integer_type_node,
6703 V4SF_type_node, V4SF_type_node, NULL_TREE);
6704 tree int_ftype_v16qi_v16qi
6705 = build_function_type_list (integer_type_node,
6706 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6707 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
6708 = build_function_type_list (integer_type_node,
6709 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6710
6f317ef3 6711 /* Add the simple ternary operators. */
2212663f 6712 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 6713 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
6714 {
6715
6716 enum machine_mode mode0, mode1, mode2, mode3;
6717 tree type;
6718
0559cc77 6719 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6720 continue;
6721
6722 mode0 = insn_data[d->icode].operand[0].mode;
6723 mode1 = insn_data[d->icode].operand[1].mode;
6724 mode2 = insn_data[d->icode].operand[2].mode;
6725 mode3 = insn_data[d->icode].operand[3].mode;
6726
6727 /* When all four are of the same mode. */
6728 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
6729 {
6730 switch (mode0)
6731 {
617e0e1d
DB
6732 case V4SImode:
6733 type = v4si_ftype_v4si_v4si_v4si;
6734 break;
2212663f
DB
6735 case V4SFmode:
6736 type = v4sf_ftype_v4sf_v4sf_v4sf;
6737 break;
6738 case V8HImode:
6739 type = v8hi_ftype_v8hi_v8hi_v8hi;
6740 break;
6741 case V16QImode:
6742 type = v16qi_ftype_v16qi_v16qi_v16qi;
6743 break;
6744 default:
6745 abort();
6746 }
6747 }
6748 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
6749 {
6750 switch (mode0)
6751 {
6752 case V4SImode:
6753 type = v4si_ftype_v4si_v4si_v16qi;
6754 break;
6755 case V4SFmode:
6756 type = v4sf_ftype_v4sf_v4sf_v16qi;
6757 break;
6758 case V8HImode:
6759 type = v8hi_ftype_v8hi_v8hi_v16qi;
6760 break;
6761 case V16QImode:
6762 type = v16qi_ftype_v16qi_v16qi_v16qi;
6763 break;
6764 default:
6765 abort();
6766 }
6767 }
6768 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
6769 && mode3 == V4SImode)
24408032 6770 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
6771 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
6772 && mode3 == V4SImode)
24408032 6773 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
6774 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
6775 && mode3 == V4SImode)
24408032
AH
6776 type = v4sf_ftype_v4sf_v4sf_v4si;
6777
6778 /* vchar, vchar, vchar, 4 bit literal. */
6779 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
6780 && mode3 == QImode)
6781 type = v16qi_ftype_v16qi_v16qi_char;
6782
6783 /* vshort, vshort, vshort, 4 bit literal. */
6784 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
6785 && mode3 == QImode)
6786 type = v8hi_ftype_v8hi_v8hi_char;
6787
6788 /* vint, vint, vint, 4 bit literal. */
6789 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
6790 && mode3 == QImode)
6791 type = v4si_ftype_v4si_v4si_char;
6792
6793 /* vfloat, vfloat, vfloat, 4 bit literal. */
6794 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
6795 && mode3 == QImode)
6796 type = v4sf_ftype_v4sf_v4sf_char;
6797
2212663f
DB
6798 else
6799 abort ();
6800
6801 def_builtin (d->mask, d->name, type, d->code);
6802 }
6803
0ac081f6 6804 /* Add the simple binary operators. */
00b960c7 6805 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 6806 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
6807 {
6808 enum machine_mode mode0, mode1, mode2;
6809 tree type;
6810
0559cc77 6811 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
6812 continue;
6813
6814 mode0 = insn_data[d->icode].operand[0].mode;
6815 mode1 = insn_data[d->icode].operand[1].mode;
6816 mode2 = insn_data[d->icode].operand[2].mode;
6817
6818 /* When all three operands are of the same mode. */
6819 if (mode0 == mode1 && mode1 == mode2)
6820 {
6821 switch (mode0)
6822 {
6823 case V4SFmode:
6824 type = v4sf_ftype_v4sf_v4sf;
6825 break;
6826 case V4SImode:
6827 type = v4si_ftype_v4si_v4si;
6828 break;
6829 case V16QImode:
6830 type = v16qi_ftype_v16qi_v16qi;
6831 break;
6832 case V8HImode:
6833 type = v8hi_ftype_v8hi_v8hi;
6834 break;
a3170dc6
AH
6835 case V2SImode:
6836 type = v2si_ftype_v2si_v2si;
6837 break;
6838 case V2SFmode:
6839 type = v2sf_ftype_v2sf_v2sf;
6840 break;
6841 case SImode:
6842 type = int_ftype_int_int;
6843 break;
0ac081f6
AH
6844 default:
6845 abort ();
6846 }
6847 }
6848
6849 /* A few other combos we really don't want to do manually. */
6850
6851 /* vint, vfloat, vfloat. */
6852 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
6853 type = v4si_ftype_v4sf_v4sf;
6854
6855 /* vshort, vchar, vchar. */
6856 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
6857 type = v8hi_ftype_v16qi_v16qi;
6858
6859 /* vint, vshort, vshort. */
6860 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
6861 type = v4si_ftype_v8hi_v8hi;
6862
6863 /* vshort, vint, vint. */
6864 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
6865 type = v8hi_ftype_v4si_v4si;
6866
6867 /* vchar, vshort, vshort. */
6868 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
6869 type = v16qi_ftype_v8hi_v8hi;
6870
6871 /* vint, vchar, vint. */
6872 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
6873 type = v4si_ftype_v16qi_v4si;
6874
fa066a23
AH
6875 /* vint, vchar, vchar. */
6876 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
6877 type = v4si_ftype_v16qi_v16qi;
6878
0ac081f6
AH
6879 /* vint, vshort, vint. */
6880 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
6881 type = v4si_ftype_v8hi_v4si;
2212663f
DB
6882
6883 /* vint, vint, 5 bit literal. */
6884 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
6885 type = v4si_ftype_v4si_char;
6886
6887 /* vshort, vshort, 5 bit literal. */
6888 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
6889 type = v8hi_ftype_v8hi_char;
6890
6891 /* vchar, vchar, 5 bit literal. */
6892 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
6893 type = v16qi_ftype_v16qi_char;
0ac081f6 6894
617e0e1d
DB
6895 /* vfloat, vint, 5 bit literal. */
6896 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
6897 type = v4sf_ftype_v4si_char;
6898
6899 /* vint, vfloat, 5 bit literal. */
6900 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
6901 type = v4si_ftype_v4sf_char;
6902
a3170dc6
AH
6903 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
6904 type = v2si_ftype_int_int;
6905
6906 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
6907 type = v2si_ftype_v2si_char;
6908
6909 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
6910 type = v2si_ftype_int_char;
6911
0ac081f6
AH
6912 /* int, x, x. */
6913 else if (mode0 == SImode)
6914 {
6915 switch (mode1)
6916 {
6917 case V4SImode:
6918 type = int_ftype_v4si_v4si;
6919 break;
6920 case V4SFmode:
6921 type = int_ftype_v4sf_v4sf;
6922 break;
6923 case V16QImode:
6924 type = int_ftype_v16qi_v16qi;
6925 break;
6926 case V8HImode:
6927 type = int_ftype_v8hi_v8hi;
6928 break;
6929 default:
6930 abort ();
6931 }
6932 }
6933
6934 else
6935 abort ();
6936
2212663f
DB
6937 def_builtin (d->mask, d->name, type, d->code);
6938 }
24408032 6939
2212663f
DB
6940 /* Add the simple unary operators. */
6941 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 6942 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
6943 {
6944 enum machine_mode mode0, mode1;
6945 tree type;
6946
0559cc77 6947 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6948 continue;
6949
6950 mode0 = insn_data[d->icode].operand[0].mode;
6951 mode1 = insn_data[d->icode].operand[1].mode;
6952
6953 if (mode0 == V4SImode && mode1 == QImode)
6954 type = v4si_ftype_char;
6955 else if (mode0 == V8HImode && mode1 == QImode)
6956 type = v8hi_ftype_char;
6957 else if (mode0 == V16QImode && mode1 == QImode)
6958 type = v16qi_ftype_char;
617e0e1d
DB
6959 else if (mode0 == V4SFmode && mode1 == V4SFmode)
6960 type = v4sf_ftype_v4sf;
20e26713
AH
6961 else if (mode0 == V8HImode && mode1 == V16QImode)
6962 type = v8hi_ftype_v16qi;
6963 else if (mode0 == V4SImode && mode1 == V8HImode)
6964 type = v4si_ftype_v8hi;
a3170dc6
AH
6965 else if (mode0 == V2SImode && mode1 == V2SImode)
6966 type = v2si_ftype_v2si;
6967 else if (mode0 == V2SFmode && mode1 == V2SFmode)
6968 type = v2sf_ftype_v2sf;
6969 else if (mode0 == V2SFmode && mode1 == V2SImode)
6970 type = v2sf_ftype_v2si;
6971 else if (mode0 == V2SImode && mode1 == V2SFmode)
6972 type = v2si_ftype_v2sf;
6973 else if (mode0 == V2SImode && mode1 == QImode)
6974 type = v2si_ftype_char;
2212663f
DB
6975 else
6976 abort ();
6977
0ac081f6
AH
6978 def_builtin (d->mask, d->name, type, d->code);
6979 }
6980}
6981
35aff10b 6982\f
7e69e155
MM
6983/* Expand a block move operation, and return 1 if successful. Return 0
6984 if we should let the compiler generate normal code.
6985
6986 operands[0] is the destination
6987 operands[1] is the source
6988 operands[2] is the length
6989 operands[3] is the alignment */
6990
3933e0e1
MM
6991#define MAX_MOVE_REG 4
6992
7e69e155
MM
6993int
6994expand_block_move (operands)
6995 rtx operands[];
6996{
b6c9286a
MM
6997 rtx orig_dest = operands[0];
6998 rtx orig_src = operands[1];
7e69e155 6999 rtx bytes_rtx = operands[2];
7e69e155 7000 rtx align_rtx = operands[3];
3933e0e1 7001 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7002 int align;
3933e0e1
MM
7003 int bytes;
7004 int offset;
7e69e155 7005 int move_bytes;
cabfd258
GK
7006 rtx stores[MAX_MOVE_REG];
7007 int num_reg = 0;
7e69e155 7008
3933e0e1 7009 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7010 if (! constp)
3933e0e1
MM
7011 return 0;
7012
5ee95df6
FS
7013 /* If this is not a fixed size alignment, abort */
7014 if (GET_CODE (align_rtx) != CONST_INT)
7015 abort ();
7016 align = INTVAL (align_rtx);
7017
7e69e155 7018 /* Anything to move? */
3933e0e1
MM
7019 bytes = INTVAL (bytes_rtx);
7020 if (bytes <= 0)
7e69e155
MM
7021 return 1;
7022
ea9982a8 7023 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7024 reg_parm_stack_space. */
ea9982a8 7025 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7026 return 0;
7027
cabfd258 7028 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7029 {
cabfd258
GK
7030 union {
7031 rtx (*movstrsi) PARAMS ((rtx, rtx, rtx, rtx));
7032 rtx (*mov) PARAMS ((rtx, rtx));
7033 } gen_func;
7034 enum machine_mode mode = BLKmode;
7035 rtx src, dest;
7036
7037 if (TARGET_STRING
7038 && bytes > 24 /* move up to 32 bytes at a time */
7039 && ! fixed_regs[5]
7040 && ! fixed_regs[6]
7041 && ! fixed_regs[7]
7042 && ! fixed_regs[8]
7043 && ! fixed_regs[9]
7044 && ! fixed_regs[10]
7045 && ! fixed_regs[11]
7046 && ! fixed_regs[12])
7e69e155 7047 {
cabfd258
GK
7048 move_bytes = (bytes > 32) ? 32 : bytes;
7049 gen_func.movstrsi = gen_movstrsi_8reg;
7050 }
7051 else if (TARGET_STRING
7052 && bytes > 16 /* move up to 24 bytes at a time */
7053 && ! fixed_regs[5]
7054 && ! fixed_regs[6]
7055 && ! fixed_regs[7]
7056 && ! fixed_regs[8]
7057 && ! fixed_regs[9]
7058 && ! fixed_regs[10])
7059 {
7060 move_bytes = (bytes > 24) ? 24 : bytes;
7061 gen_func.movstrsi = gen_movstrsi_6reg;
7062 }
7063 else if (TARGET_STRING
7064 && bytes > 8 /* move up to 16 bytes at a time */
7065 && ! fixed_regs[5]
7066 && ! fixed_regs[6]
7067 && ! fixed_regs[7]
7068 && ! fixed_regs[8])
7069 {
7070 move_bytes = (bytes > 16) ? 16 : bytes;
7071 gen_func.movstrsi = gen_movstrsi_4reg;
7072 }
7073 else if (bytes >= 8 && TARGET_POWERPC64
7074 /* 64-bit loads and stores require word-aligned
7075 displacements. */
7076 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7077 {
7078 move_bytes = 8;
7079 mode = DImode;
7080 gen_func.mov = gen_movdi;
7081 }
7082 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7083 { /* move up to 8 bytes at a time */
7084 move_bytes = (bytes > 8) ? 8 : bytes;
7085 gen_func.movstrsi = gen_movstrsi_2reg;
7086 }
7087 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7088 { /* move 4 bytes */
7089 move_bytes = 4;
7090 mode = SImode;
7091 gen_func.mov = gen_movsi;
7092 }
7093 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7094 { /* move 2 bytes */
7095 move_bytes = 2;
7096 mode = HImode;
7097 gen_func.mov = gen_movhi;
7098 }
7099 else if (TARGET_STRING && bytes > 1)
7100 { /* move up to 4 bytes at a time */
7101 move_bytes = (bytes > 4) ? 4 : bytes;
7102 gen_func.movstrsi = gen_movstrsi_1reg;
7103 }
7104 else /* move 1 byte at a time */
7105 {
7106 move_bytes = 1;
7107 mode = QImode;
7108 gen_func.mov = gen_movqi;
7109 }
7110
7111 src = adjust_address (orig_src, mode, offset);
7112 dest = adjust_address (orig_dest, mode, offset);
7113
7114 if (mode != BLKmode)
7115 {
7116 rtx tmp_reg = gen_reg_rtx (mode);
7117
7118 emit_insn ((*gen_func.mov) (tmp_reg, src));
7119 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7120 }
3933e0e1 7121
cabfd258
GK
7122 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7123 {
7124 int i;
7125 for (i = 0; i < num_reg; i++)
7126 emit_insn (stores[i]);
7127 num_reg = 0;
7128 }
35aff10b 7129
cabfd258 7130 if (mode == BLKmode)
7e69e155 7131 {
cabfd258
GK
7132 /* Move the address into scratch registers. The movstrsi
7133 patterns require zero offset. */
7134 if (!REG_P (XEXP (src, 0)))
b6c9286a 7135 {
cabfd258
GK
7136 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7137 src = replace_equiv_address (src, src_reg);
b6c9286a 7138 }
cabfd258
GK
7139 set_mem_size (src, GEN_INT (move_bytes));
7140
7141 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7142 {
cabfd258
GK
7143 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7144 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7145 }
cabfd258
GK
7146 set_mem_size (dest, GEN_INT (move_bytes));
7147
7148 emit_insn ((*gen_func.movstrsi) (dest, src,
7149 GEN_INT (move_bytes & 31),
7150 align_rtx));
7e69e155 7151 }
7e69e155
MM
7152 }
7153
7154 return 1;
7155}
7156
9878760c
RK
7157\f
7158/* Return 1 if OP is a load multiple operation. It is known to be a
7159 PARALLEL and the first section will be tested. */
7160
7161int
7162load_multiple_operation (op, mode)
7163 rtx op;
296b8152 7164 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7165{
7166 int count = XVECLEN (op, 0);
e2c953b6 7167 unsigned int dest_regno;
9878760c
RK
7168 rtx src_addr;
7169 int i;
7170
7171 /* Perform a quick check so we don't blow up below. */
7172 if (count <= 1
7173 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7174 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7175 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7176 return 0;
7177
7178 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7179 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7180
7181 for (i = 1; i < count; i++)
7182 {
7183 rtx elt = XVECEXP (op, 0, i);
7184
7185 if (GET_CODE (elt) != SET
7186 || GET_CODE (SET_DEST (elt)) != REG
7187 || GET_MODE (SET_DEST (elt)) != SImode
7188 || REGNO (SET_DEST (elt)) != dest_regno + i
7189 || GET_CODE (SET_SRC (elt)) != MEM
7190 || GET_MODE (SET_SRC (elt)) != SImode
7191 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7192 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7193 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7194 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7195 return 0;
7196 }
7197
7198 return 1;
7199}
7200
7201/* Similar, but tests for store multiple. Here, the second vector element
7202 is a CLOBBER. It will be tested later. */
7203
7204int
7205store_multiple_operation (op, mode)
7206 rtx op;
296b8152 7207 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7208{
7209 int count = XVECLEN (op, 0) - 1;
e2c953b6 7210 unsigned int src_regno;
9878760c
RK
7211 rtx dest_addr;
7212 int i;
7213
7214 /* Perform a quick check so we don't blow up below. */
7215 if (count <= 1
7216 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7217 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7218 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7219 return 0;
7220
7221 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7222 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7223
7224 for (i = 1; i < count; i++)
7225 {
7226 rtx elt = XVECEXP (op, 0, i + 1);
7227
7228 if (GET_CODE (elt) != SET
7229 || GET_CODE (SET_SRC (elt)) != REG
7230 || GET_MODE (SET_SRC (elt)) != SImode
7231 || REGNO (SET_SRC (elt)) != src_regno + i
7232 || GET_CODE (SET_DEST (elt)) != MEM
7233 || GET_MODE (SET_DEST (elt)) != SImode
7234 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7235 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7236 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7237 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7238 return 0;
7239 }
7240
7241 return 1;
7242}
9ebbca7d 7243
9caa3eb2
DE
7244/* Return a string to perform a load_multiple operation.
7245 operands[0] is the vector.
7246 operands[1] is the source address.
7247 operands[2] is the first destination register. */
7248
7249const char *
7250rs6000_output_load_multiple (operands)
ebe637e3 7251 rtx operands[3];
9caa3eb2
DE
7252{
7253 /* We have to handle the case where the pseudo used to contain the address
7254 is assigned to one of the output registers. */
7255 int i, j;
7256 int words = XVECLEN (operands[0], 0);
7257 rtx xop[10];
7258
7259 if (XVECLEN (operands[0], 0) == 1)
7260 return "{l|lwz} %2,0(%1)";
7261
7262 for (i = 0; i < words; i++)
7263 if (refers_to_regno_p (REGNO (operands[2]) + i,
7264 REGNO (operands[2]) + i + 1, operands[1], 0))
7265 {
7266 if (i == words-1)
7267 {
7268 xop[0] = GEN_INT (4 * (words-1));
7269 xop[1] = operands[1];
7270 xop[2] = operands[2];
7271 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7272 return "";
7273 }
7274 else if (i == 0)
7275 {
7276 xop[0] = GEN_INT (4 * (words-1));
7277 xop[1] = operands[1];
7278 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7279 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);
7280 return "";
7281 }
7282 else
7283 {
7284 for (j = 0; j < words; j++)
7285 if (j != i)
7286 {
7287 xop[0] = GEN_INT (j * 4);
7288 xop[1] = operands[1];
7289 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7290 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7291 }
7292 xop[0] = GEN_INT (i * 4);
7293 xop[1] = operands[1];
7294 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7295 return "";
7296 }
7297 }
7298
7299 return "{lsi|lswi} %2,%1,%N0";
7300}
7301
00b960c7
AH
7302/* Return 1 for a parallel vrsave operation. */
7303
7304int
7305vrsave_operation (op, mode)
7306 rtx op;
7307 enum machine_mode mode ATTRIBUTE_UNUSED;
7308{
7309 int count = XVECLEN (op, 0);
7310 unsigned int dest_regno, src_regno;
7311 int i;
7312
7313 if (count <= 1
7314 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7315 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7316 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7317 return 0;
7318
7319 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7320 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7321
7322 if (dest_regno != VRSAVE_REGNO
7323 && src_regno != VRSAVE_REGNO)
7324 return 0;
7325
7326 for (i = 1; i < count; i++)
7327 {
7328 rtx elt = XVECEXP (op, 0, i);
7329
9aa86737
AH
7330 if (GET_CODE (elt) != CLOBBER
7331 && GET_CODE (elt) != SET)
00b960c7
AH
7332 return 0;
7333 }
7334
7335 return 1;
7336}
7337
2c4a9cff
DE
7338/* Return 1 for an PARALLEL suitable for mfcr. */
7339
7340int
7341mfcr_operation (op, mode)
7342 rtx op;
7343 enum machine_mode mode ATTRIBUTE_UNUSED;
7344{
7345 int count = XVECLEN (op, 0);
7346 int i;
7347
7348 /* Perform a quick check so we don't blow up below. */
7349 if (count < 1
7350 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7351 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7352 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
7353 return 0;
7354
7355 for (i = 0; i < count; i++)
7356 {
7357 rtx exp = XVECEXP (op, 0, i);
7358 rtx unspec;
7359 int maskval;
7360 rtx src_reg;
7361
7362 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
7363
7364 if (GET_CODE (src_reg) != REG
7365 || GET_MODE (src_reg) != CCmode
7366 || ! CR_REGNO_P (REGNO (src_reg)))
7367 return 0;
7368
7369 if (GET_CODE (exp) != SET
7370 || GET_CODE (SET_DEST (exp)) != REG
7371 || GET_MODE (SET_DEST (exp)) != SImode
7372 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
7373 return 0;
7374 unspec = SET_SRC (exp);
7375 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
7376
7377 if (GET_CODE (unspec) != UNSPEC
7378 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
7379 || XVECLEN (unspec, 0) != 2
7380 || XVECEXP (unspec, 0, 0) != src_reg
7381 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7382 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7383 return 0;
7384 }
7385 return 1;
7386}
7387
a4f6c312 7388/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
7389
7390int
7391mtcrf_operation (op, mode)
7392 rtx op;
7393 enum machine_mode mode ATTRIBUTE_UNUSED;
7394{
7395 int count = XVECLEN (op, 0);
7396 int i;
9ebbca7d
GK
7397 rtx src_reg;
7398
7399 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
7400 if (count < 1
7401 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7402 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7403 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 7404 return 0;
e35b9579 7405 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
7406
7407 if (GET_CODE (src_reg) != REG
7408 || GET_MODE (src_reg) != SImode
7409 || ! INT_REGNO_P (REGNO (src_reg)))
7410 return 0;
7411
e35b9579 7412 for (i = 0; i < count; i++)
9ebbca7d
GK
7413 {
7414 rtx exp = XVECEXP (op, 0, i);
7415 rtx unspec;
7416 int maskval;
7417
7418 if (GET_CODE (exp) != SET
7419 || GET_CODE (SET_DEST (exp)) != REG
7420 || GET_MODE (SET_DEST (exp)) != CCmode
7421 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
7422 return 0;
7423 unspec = SET_SRC (exp);
7424 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
7425
7426 if (GET_CODE (unspec) != UNSPEC
615158e2 7427 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
7428 || XVECLEN (unspec, 0) != 2
7429 || XVECEXP (unspec, 0, 0) != src_reg
7430 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7431 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7432 return 0;
7433 }
e35b9579 7434 return 1;
9ebbca7d
GK
7435}
7436
a4f6c312 7437/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
7438
7439int
7440lmw_operation (op, mode)
7441 rtx op;
7442 enum machine_mode mode ATTRIBUTE_UNUSED;
7443{
7444 int count = XVECLEN (op, 0);
e2c953b6 7445 unsigned int dest_regno;
9ebbca7d 7446 rtx src_addr;
e2c953b6 7447 unsigned int base_regno;
9ebbca7d
GK
7448 HOST_WIDE_INT offset;
7449 int i;
7450
7451 /* Perform a quick check so we don't blow up below. */
7452 if (count <= 1
7453 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7454 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7455 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7456 return 0;
7457
7458 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7459 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7460
7461 if (dest_regno > 31
e2c953b6 7462 || count != 32 - (int) dest_regno)
9ebbca7d
GK
7463 return 0;
7464
4d588c14 7465 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
7466 {
7467 offset = 0;
7468 base_regno = REGNO (src_addr);
7469 if (base_regno == 0)
7470 return 0;
7471 }
4d588c14 7472 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
7473 {
7474 offset = INTVAL (XEXP (src_addr, 1));
7475 base_regno = REGNO (XEXP (src_addr, 0));
7476 }
7477 else
7478 return 0;
7479
7480 for (i = 0; i < count; i++)
7481 {
7482 rtx elt = XVECEXP (op, 0, i);
7483 rtx newaddr;
7484 rtx addr_reg;
7485 HOST_WIDE_INT newoffset;
7486
7487 if (GET_CODE (elt) != SET
7488 || GET_CODE (SET_DEST (elt)) != REG
7489 || GET_MODE (SET_DEST (elt)) != SImode
7490 || REGNO (SET_DEST (elt)) != dest_regno + i
7491 || GET_CODE (SET_SRC (elt)) != MEM
7492 || GET_MODE (SET_SRC (elt)) != SImode)
7493 return 0;
7494 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 7495 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7496 {
7497 newoffset = 0;
7498 addr_reg = newaddr;
7499 }
4d588c14 7500 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7501 {
7502 addr_reg = XEXP (newaddr, 0);
7503 newoffset = INTVAL (XEXP (newaddr, 1));
7504 }
7505 else
7506 return 0;
7507 if (REGNO (addr_reg) != base_regno
7508 || newoffset != offset + 4 * i)
7509 return 0;
7510 }
7511
7512 return 1;
7513}
7514
a4f6c312 7515/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
7516
7517int
7518stmw_operation (op, mode)
7519 rtx op;
7520 enum machine_mode mode ATTRIBUTE_UNUSED;
7521{
7522 int count = XVECLEN (op, 0);
e2c953b6 7523 unsigned int src_regno;
9ebbca7d 7524 rtx dest_addr;
e2c953b6 7525 unsigned int base_regno;
9ebbca7d
GK
7526 HOST_WIDE_INT offset;
7527 int i;
7528
7529 /* Perform a quick check so we don't blow up below. */
7530 if (count <= 1
7531 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7532 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7533 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7534 return 0;
7535
7536 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7537 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7538
7539 if (src_regno > 31
e2c953b6 7540 || count != 32 - (int) src_regno)
9ebbca7d
GK
7541 return 0;
7542
4d588c14 7543 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
7544 {
7545 offset = 0;
7546 base_regno = REGNO (dest_addr);
7547 if (base_regno == 0)
7548 return 0;
7549 }
4d588c14 7550 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
7551 {
7552 offset = INTVAL (XEXP (dest_addr, 1));
7553 base_regno = REGNO (XEXP (dest_addr, 0));
7554 }
7555 else
7556 return 0;
7557
7558 for (i = 0; i < count; i++)
7559 {
7560 rtx elt = XVECEXP (op, 0, i);
7561 rtx newaddr;
7562 rtx addr_reg;
7563 HOST_WIDE_INT newoffset;
7564
7565 if (GET_CODE (elt) != SET
7566 || GET_CODE (SET_SRC (elt)) != REG
7567 || GET_MODE (SET_SRC (elt)) != SImode
7568 || REGNO (SET_SRC (elt)) != src_regno + i
7569 || GET_CODE (SET_DEST (elt)) != MEM
7570 || GET_MODE (SET_DEST (elt)) != SImode)
7571 return 0;
7572 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 7573 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7574 {
7575 newoffset = 0;
7576 addr_reg = newaddr;
7577 }
4d588c14 7578 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7579 {
7580 addr_reg = XEXP (newaddr, 0);
7581 newoffset = INTVAL (XEXP (newaddr, 1));
7582 }
7583 else
7584 return 0;
7585 if (REGNO (addr_reg) != base_regno
7586 || newoffset != offset + 4 * i)
7587 return 0;
7588 }
7589
7590 return 1;
7591}
9878760c 7592\f
a4f6c312
SS
7593/* A validation routine: say whether CODE, a condition code, and MODE
7594 match. The other alternatives either don't make sense or should
7595 never be generated. */
39a10a29 7596
39a10a29
GK
7597static void
7598validate_condition_mode (code, mode)
7599 enum rtx_code code;
7600 enum machine_mode mode;
7601{
7602 if (GET_RTX_CLASS (code) != '<'
7603 || GET_MODE_CLASS (mode) != MODE_CC)
7604 abort ();
7605
7606 /* These don't make sense. */
7607 if ((code == GT || code == LT || code == GE || code == LE)
7608 && mode == CCUNSmode)
7609 abort ();
7610
7611 if ((code == GTU || code == LTU || code == GEU || code == LEU)
7612 && mode != CCUNSmode)
7613 abort ();
7614
7615 if (mode != CCFPmode
7616 && (code == ORDERED || code == UNORDERED
7617 || code == UNEQ || code == LTGT
7618 || code == UNGT || code == UNLT
7619 || code == UNGE || code == UNLE))
a4f6c312 7620 abort ();
39a10a29 7621
de6c5979 7622 /* These should never be generated except for
bc9ec0e0 7623 flag_finite_math_only. */
39a10a29 7624 if (mode == CCFPmode
ad72b533 7625 && ! flag_finite_math_only
39a10a29
GK
7626 && (code == LE || code == GE
7627 || code == UNEQ || code == LTGT
7628 || code == UNGT || code == UNLT))
7629 abort ();
7630
7631 /* These are invalid; the information is not there. */
7632 if (mode == CCEQmode
7633 && code != EQ && code != NE)
7634 abort ();
7635}
7636
9878760c
RK
7637/* Return 1 if OP is a comparison operation that is valid for a branch insn.
7638 We only check the opcode against the mode of the CC value here. */
7639
7640int
7641branch_comparison_operator (op, mode)
592696dd 7642 rtx op;
296b8152 7643 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7644{
7645 enum rtx_code code = GET_CODE (op);
7646 enum machine_mode cc_mode;
7647
7648 if (GET_RTX_CLASS (code) != '<')
7649 return 0;
7650
7651 cc_mode = GET_MODE (XEXP (op, 0));
7652 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
7653 return 0;
7654
39a10a29 7655 validate_condition_mode (code, cc_mode);
9878760c 7656
39a10a29
GK
7657 return 1;
7658}
7659
7660/* Return 1 if OP is a comparison operation that is valid for a branch
7661 insn and which is true if the corresponding bit in the CC register
7662 is set. */
7663
7664int
7665branch_positive_comparison_operator (op, mode)
592696dd 7666 rtx op;
39a10a29
GK
7667 enum machine_mode mode;
7668{
7669 enum rtx_code code;
7670
7671 if (! branch_comparison_operator (op, mode))
9878760c
RK
7672 return 0;
7673
39a10a29
GK
7674 code = GET_CODE (op);
7675 return (code == EQ || code == LT || code == GT
993f19a8 7676 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
7677 || code == LTU || code == GTU
7678 || code == UNORDERED);
9878760c
RK
7679}
7680
b7053a3f
GK
7681/* Return 1 if OP is a comparison operation that is valid for an scc
7682 insn: it must be a positive comparison. */
9878760c
RK
7683
7684int
7685scc_comparison_operator (op, mode)
592696dd 7686 rtx op;
9878760c
RK
7687 enum machine_mode mode;
7688{
b7053a3f 7689 return branch_positive_comparison_operator (op, mode);
9878760c 7690}
e0cd0770
JC
7691
7692int
7693trap_comparison_operator (op, mode)
7694 rtx op;
7695 enum machine_mode mode;
7696{
7697 if (mode != VOIDmode && mode != GET_MODE (op))
7698 return 0;
39a10a29 7699 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 7700}
dfbdccdb
GK
7701
7702int
7703boolean_operator (op, mode)
7704 rtx op;
7705 enum machine_mode mode ATTRIBUTE_UNUSED;
7706{
7707 enum rtx_code code = GET_CODE (op);
7708 return (code == AND || code == IOR || code == XOR);
7709}
1d328b19
GK
7710
7711int
7712boolean_or_operator (op, mode)
7713 rtx op;
7714 enum machine_mode mode ATTRIBUTE_UNUSED;
7715{
7716 enum rtx_code code = GET_CODE (op);
7717 return (code == IOR || code == XOR);
7718}
50a0b056
GK
7719
7720int
7721min_max_operator (op, mode)
7722 rtx op;
7723 enum machine_mode mode ATTRIBUTE_UNUSED;
7724{
7725 enum rtx_code code = GET_CODE (op);
7726 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
7727}
9878760c
RK
7728\f
7729/* Return 1 if ANDOP is a mask that has no bits on that are not in the
7730 mask required to convert the result of a rotate insn into a shift
b1765bde 7731 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
7732
7733int
7734includes_lshift_p (shiftop, andop)
592696dd
SS
7735 rtx shiftop;
7736 rtx andop;
9878760c 7737{
e2c953b6
DE
7738 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
7739
7740 shift_mask <<= INTVAL (shiftop);
9878760c 7741
b1765bde 7742 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
7743}
7744
7745/* Similar, but for right shift. */
7746
7747int
7748includes_rshift_p (shiftop, andop)
592696dd
SS
7749 rtx shiftop;
7750 rtx andop;
9878760c 7751{
a7653a2c 7752 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
7753
7754 shift_mask >>= INTVAL (shiftop);
7755
b1765bde 7756 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
7757}
7758
c5059423
AM
7759/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
7760 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 7761 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
7762
7763int
c5059423 7764includes_rldic_lshift_p (shiftop, andop)
592696dd
SS
7765 rtx shiftop;
7766 rtx andop;
e2c953b6 7767{
c5059423
AM
7768 if (GET_CODE (andop) == CONST_INT)
7769 {
02071907 7770 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 7771
c5059423 7772 c = INTVAL (andop);
02071907 7773 if (c == 0 || c == ~0)
c5059423 7774 return 0;
e2c953b6 7775
02071907 7776 shift_mask = ~0;
c5059423
AM
7777 shift_mask <<= INTVAL (shiftop);
7778
b6d08ca1 7779 /* Find the least significant one bit. */
c5059423
AM
7780 lsb = c & -c;
7781
7782 /* It must coincide with the LSB of the shift mask. */
7783 if (-lsb != shift_mask)
7784 return 0;
e2c953b6 7785
c5059423
AM
7786 /* Invert to look for the next transition (if any). */
7787 c = ~c;
7788
7789 /* Remove the low group of ones (originally low group of zeros). */
7790 c &= -lsb;
7791
7792 /* Again find the lsb, and check we have all 1's above. */
7793 lsb = c & -c;
7794 return c == -lsb;
7795 }
7796 else if (GET_CODE (andop) == CONST_DOUBLE
7797 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7798 {
02071907
AM
7799 HOST_WIDE_INT low, high, lsb;
7800 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
7801
7802 low = CONST_DOUBLE_LOW (andop);
7803 if (HOST_BITS_PER_WIDE_INT < 64)
7804 high = CONST_DOUBLE_HIGH (andop);
7805
7806 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 7807 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
7808 return 0;
7809
7810 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7811 {
02071907 7812 shift_mask_high = ~0;
c5059423
AM
7813 if (INTVAL (shiftop) > 32)
7814 shift_mask_high <<= INTVAL (shiftop) - 32;
7815
7816 lsb = high & -high;
7817
7818 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
7819 return 0;
7820
7821 high = ~high;
7822 high &= -lsb;
7823
7824 lsb = high & -high;
7825 return high == -lsb;
7826 }
7827
02071907 7828 shift_mask_low = ~0;
c5059423
AM
7829 shift_mask_low <<= INTVAL (shiftop);
7830
7831 lsb = low & -low;
7832
7833 if (-lsb != shift_mask_low)
7834 return 0;
7835
7836 if (HOST_BITS_PER_WIDE_INT < 64)
7837 high = ~high;
7838 low = ~low;
7839 low &= -lsb;
7840
7841 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7842 {
7843 lsb = high & -high;
7844 return high == -lsb;
7845 }
7846
7847 lsb = low & -low;
7848 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
7849 }
7850 else
7851 return 0;
7852}
e2c953b6 7853
c5059423
AM
7854/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
7855 to perform a left shift. It must have SHIFTOP or more least
c1207243 7856 significant 0's, with the remainder of the word 1's. */
e2c953b6 7857
c5059423
AM
7858int
7859includes_rldicr_lshift_p (shiftop, andop)
592696dd
SS
7860 rtx shiftop;
7861 rtx andop;
c5059423 7862{
e2c953b6 7863 if (GET_CODE (andop) == CONST_INT)
c5059423 7864 {
02071907 7865 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 7866
02071907 7867 shift_mask = ~0;
c5059423
AM
7868 shift_mask <<= INTVAL (shiftop);
7869 c = INTVAL (andop);
7870
c1207243 7871 /* Find the least significant one bit. */
c5059423
AM
7872 lsb = c & -c;
7873
7874 /* It must be covered by the shift mask.
a4f6c312 7875 This test also rejects c == 0. */
c5059423
AM
7876 if ((lsb & shift_mask) == 0)
7877 return 0;
7878
7879 /* Check we have all 1's above the transition, and reject all 1's. */
7880 return c == -lsb && lsb != 1;
7881 }
7882 else if (GET_CODE (andop) == CONST_DOUBLE
7883 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7884 {
02071907 7885 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
7886
7887 low = CONST_DOUBLE_LOW (andop);
7888
7889 if (HOST_BITS_PER_WIDE_INT < 64)
7890 {
02071907 7891 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
7892
7893 high = CONST_DOUBLE_HIGH (andop);
7894
7895 if (low == 0)
7896 {
02071907 7897 shift_mask_high = ~0;
c5059423
AM
7898 if (INTVAL (shiftop) > 32)
7899 shift_mask_high <<= INTVAL (shiftop) - 32;
7900
7901 lsb = high & -high;
7902
7903 if ((lsb & shift_mask_high) == 0)
7904 return 0;
7905
7906 return high == -lsb;
7907 }
7908 if (high != ~0)
7909 return 0;
7910 }
7911
02071907 7912 shift_mask_low = ~0;
c5059423
AM
7913 shift_mask_low <<= INTVAL (shiftop);
7914
7915 lsb = low & -low;
7916
7917 if ((lsb & shift_mask_low) == 0)
7918 return 0;
7919
7920 return low == -lsb && lsb != 1;
7921 }
e2c953b6 7922 else
c5059423 7923 return 0;
9878760c 7924}
35068b43
RK
7925
7926/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
7927 for lfq and stfq insns.
7928
7929 Note reg1 and reg2 *must* be hard registers. To be sure we will
7930 abort if we are passed pseudo registers. */
7931
7932int
7933registers_ok_for_quad_peep (reg1, reg2)
7934 rtx reg1, reg2;
7935{
7936 /* We might have been passed a SUBREG. */
7937 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7938 return 0;
7939
7940 return (REGNO (reg1) == REGNO (reg2) - 1);
7941}
7942
a4f6c312
SS
7943/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
7944 addr1 and addr2 must be in consecutive memory locations
7945 (addr2 == addr1 + 8). */
35068b43
RK
7946
7947int
7948addrs_ok_for_quad_peep (addr1, addr2)
592696dd
SS
7949 rtx addr1;
7950 rtx addr2;
35068b43 7951{
e2c953b6 7952 unsigned int reg1;
35068b43
RK
7953 int offset1;
7954
7955 /* Extract an offset (if used) from the first addr. */
7956 if (GET_CODE (addr1) == PLUS)
7957 {
7958 /* If not a REG, return zero. */
7959 if (GET_CODE (XEXP (addr1, 0)) != REG)
7960 return 0;
7961 else
7962 {
7963 reg1 = REGNO (XEXP (addr1, 0));
7964 /* The offset must be constant! */
7965 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7966 return 0;
7967 offset1 = INTVAL (XEXP (addr1, 1));
7968 }
7969 }
7970 else if (GET_CODE (addr1) != REG)
7971 return 0;
7972 else
7973 {
7974 reg1 = REGNO (addr1);
7975 /* This was a simple (mem (reg)) expression. Offset is 0. */
7976 offset1 = 0;
7977 }
7978
984e25ac
DE
7979/* Make sure the second address is a (mem (plus (reg) (const_int)))
7980 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
7981 register as addr1. */
7982 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
7983 return 1;
35068b43
RK
7984 if (GET_CODE (addr2) != PLUS)
7985 return 0;
7986
7987 if (GET_CODE (XEXP (addr2, 0)) != REG
7988 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7989 return 0;
7990
7991 if (reg1 != REGNO (XEXP (addr2, 0)))
7992 return 0;
7993
7994 /* The offset for the second addr must be 8 more than the first addr. */
7995 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
7996 return 0;
7997
7998 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
7999 instructions. */
8000 return 1;
8001}
9878760c
RK
8002\f
8003/* Return the register class of a scratch register needed to copy IN into
8004 or out of a register in CLASS in MODE. If it can be done directly,
8005 NO_REGS is returned. */
8006
8007enum reg_class
8008secondary_reload_class (class, mode, in)
8009 enum reg_class class;
296b8152 8010 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
8011 rtx in;
8012{
5accd822 8013 int regno;
9878760c 8014
ab82a49f
AP
8015 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8016#if TARGET_MACHO
8017 && MACHOPIC_INDIRECT
8018#endif
8019 ))
46fad5b7
DJ
8020 {
8021 /* We cannot copy a symbolic operand directly into anything
8022 other than BASE_REGS for TARGET_ELF. So indicate that a
8023 register from BASE_REGS is needed as an intermediate
8024 register.
8025
8026 On Darwin, pic addresses require a load from memory, which
8027 needs a base register. */
8028 if (class != BASE_REGS
8029 && (GET_CODE (in) == SYMBOL_REF
8030 || GET_CODE (in) == HIGH
8031 || GET_CODE (in) == LABEL_REF
8032 || GET_CODE (in) == CONST))
8033 return BASE_REGS;
8034 }
e7b7998a 8035
5accd822
DE
8036 if (GET_CODE (in) == REG)
8037 {
8038 regno = REGNO (in);
8039 if (regno >= FIRST_PSEUDO_REGISTER)
8040 {
8041 regno = true_regnum (in);
8042 if (regno >= FIRST_PSEUDO_REGISTER)
8043 regno = -1;
8044 }
8045 }
8046 else if (GET_CODE (in) == SUBREG)
8047 {
8048 regno = true_regnum (in);
8049 if (regno >= FIRST_PSEUDO_REGISTER)
8050 regno = -1;
8051 }
8052 else
8053 regno = -1;
8054
9878760c
RK
8055 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8056 into anything. */
8057 if (class == GENERAL_REGS || class == BASE_REGS
8058 || (regno >= 0 && INT_REGNO_P (regno)))
8059 return NO_REGS;
8060
8061 /* Constants, memory, and FP registers can go into FP registers. */
8062 if ((regno == -1 || FP_REGNO_P (regno))
8063 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8064 return NO_REGS;
8065
0ac081f6
AH
8066 /* Memory, and AltiVec registers can go into AltiVec registers. */
8067 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8068 && class == ALTIVEC_REGS)
8069 return NO_REGS;
8070
9878760c
RK
8071 /* We can copy among the CR registers. */
8072 if ((class == CR_REGS || class == CR0_REGS)
8073 && regno >= 0 && CR_REGNO_P (regno))
8074 return NO_REGS;
8075
8076 /* Otherwise, we need GENERAL_REGS. */
8077 return GENERAL_REGS;
8078}
8079\f
8080/* Given a comparison operation, return the bit number in CCR to test. We
8081 know this is a valid comparison.
8082
8083 SCC_P is 1 if this is for an scc. That means that %D will have been
8084 used instead of %C, so the bits will be in different places.
8085
b4ac57ab 8086 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8087
8088int
8089ccr_bit (op, scc_p)
592696dd 8090 rtx op;
9878760c
RK
8091 int scc_p;
8092{
8093 enum rtx_code code = GET_CODE (op);
8094 enum machine_mode cc_mode;
8095 int cc_regnum;
8096 int base_bit;
9ebbca7d 8097 rtx reg;
9878760c
RK
8098
8099 if (GET_RTX_CLASS (code) != '<')
8100 return -1;
8101
9ebbca7d
GK
8102 reg = XEXP (op, 0);
8103
8104 if (GET_CODE (reg) != REG
8105 || ! CR_REGNO_P (REGNO (reg)))
8106 abort ();
8107
8108 cc_mode = GET_MODE (reg);
8109 cc_regnum = REGNO (reg);
8110 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8111
39a10a29 8112 validate_condition_mode (code, cc_mode);
c5defebb 8113
b7053a3f
GK
8114 /* When generating a sCOND operation, only positive conditions are
8115 allowed. */
8116 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8117 && code != GTU && code != LTU)
8118 abort ();
8119
9878760c
RK
8120 switch (code)
8121 {
8122 case NE:
993f19a8
AH
8123 if (TARGET_E500 && !TARGET_FPRS
8124 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8125 return base_bit + 1;
9878760c
RK
8126 return scc_p ? base_bit + 3 : base_bit + 2;
8127 case EQ:
993f19a8
AH
8128 if (TARGET_E500 && !TARGET_FPRS
8129 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8130 return base_bit + 1;
9878760c 8131 return base_bit + 2;
1c882ea4 8132 case GT: case GTU: case UNLE:
9878760c 8133 return base_bit + 1;
1c882ea4 8134 case LT: case LTU: case UNGE:
9878760c 8135 return base_bit;
1c882ea4
GK
8136 case ORDERED: case UNORDERED:
8137 return base_bit + 3;
9878760c
RK
8138
8139 case GE: case GEU:
39a10a29 8140 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8141 unordered position. So test that bit. For integer, this is ! LT
8142 unless this is an scc insn. */
39a10a29 8143 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8144
8145 case LE: case LEU:
39a10a29 8146 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8147
9878760c
RK
8148 default:
8149 abort ();
8150 }
8151}
1ff7789b 8152\f
8d30c4ee 8153/* Return the GOT register. */
1ff7789b
MM
8154
8155struct rtx_def *
8156rs6000_got_register (value)
5f59ecb7 8157 rtx value ATTRIBUTE_UNUSED;
1ff7789b 8158{
a4f6c312
SS
8159 /* The second flow pass currently (June 1999) can't update
8160 regs_ever_live without disturbing other parts of the compiler, so
8161 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8162 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8163 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8164
8d30c4ee 8165 current_function_uses_pic_offset_table = 1;
3cb999d8 8166
1ff7789b
MM
8167 return pic_offset_table_rtx;
8168}
a7df97e6 8169\f
e2500fed
GK
8170/* Function to init struct machine_function.
8171 This will be called, via a pointer variable,
8172 from push_function_context. */
a7df97e6 8173
e2500fed
GK
8174static struct machine_function *
8175rs6000_init_machine_status ()
a7df97e6 8176{
e2500fed 8177 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8178}
9878760c 8179\f
0ba1b2ff
AM
8180/* These macros test for integers and extract the low-order bits. */
8181#define INT_P(X) \
8182((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8183 && GET_MODE (X) == VOIDmode)
8184
8185#define INT_LOWPART(X) \
8186 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8187
8188int
8189extract_MB (op)
8190 rtx op;
8191{
8192 int i;
8193 unsigned long val = INT_LOWPART (op);
8194
8195 /* If the high bit is zero, the value is the first 1 bit we find
8196 from the left. */
8197 if ((val & 0x80000000) == 0)
8198 {
8199 if ((val & 0xffffffff) == 0)
8200 abort ();
8201
8202 i = 1;
8203 while (((val <<= 1) & 0x80000000) == 0)
8204 ++i;
8205 return i;
8206 }
8207
8208 /* If the high bit is set and the low bit is not, or the mask is all
8209 1's, the value is zero. */
8210 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8211 return 0;
8212
8213 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8214 from the right. */
8215 i = 31;
8216 while (((val >>= 1) & 1) != 0)
8217 --i;
8218
8219 return i;
8220}
8221
8222int
8223extract_ME (op)
8224 rtx op;
8225{
8226 int i;
8227 unsigned long val = INT_LOWPART (op);
8228
8229 /* If the low bit is zero, the value is the first 1 bit we find from
8230 the right. */
8231 if ((val & 1) == 0)
8232 {
8233 if ((val & 0xffffffff) == 0)
8234 abort ();
8235
8236 i = 30;
8237 while (((val >>= 1) & 1) == 0)
8238 --i;
8239
8240 return i;
8241 }
8242
8243 /* If the low bit is set and the high bit is not, or the mask is all
8244 1's, the value is 31. */
8245 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8246 return 31;
8247
8248 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8249 from the left. */
8250 i = 0;
8251 while (((val <<= 1) & 0x80000000) != 0)
8252 ++i;
8253
8254 return i;
8255}
8256
c4501e62
JJ
8257/* Locate some local-dynamic symbol still in use by this function
8258 so that we can print its name in some tls_ld pattern. */
8259
8260static const char *
8261rs6000_get_some_local_dynamic_name ()
8262{
8263 rtx insn;
8264
8265 if (cfun->machine->some_ld_name)
8266 return cfun->machine->some_ld_name;
8267
8268 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8269 if (INSN_P (insn)
8270 && for_each_rtx (&PATTERN (insn),
8271 rs6000_get_some_local_dynamic_name_1, 0))
8272 return cfun->machine->some_ld_name;
8273
8274 abort ();
8275}
8276
8277/* Helper function for rs6000_get_some_local_dynamic_name. */
8278
8279static int
8280rs6000_get_some_local_dynamic_name_1 (px, data)
8281 rtx *px;
8282 void *data ATTRIBUTE_UNUSED;
8283{
8284 rtx x = *px;
8285
8286 if (GET_CODE (x) == SYMBOL_REF)
8287 {
8288 const char *str = XSTR (x, 0);
8289 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8290 {
8291 cfun->machine->some_ld_name = str;
8292 return 1;
8293 }
8294 }
8295
8296 return 0;
8297}
8298
9878760c
RK
8299/* Print an operand. Recognize special options, documented below. */
8300
38c1f2d7 8301#if TARGET_ELF
d9407988 8302#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8303#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8304#else
8305#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8306#define SMALL_DATA_REG 0
ba5e43aa
MM
8307#endif
8308
9878760c
RK
8309void
8310print_operand (file, x, code)
8311 FILE *file;
8312 rtx x;
9ebbca7d 8313 int code;
9878760c
RK
8314{
8315 int i;
a260abc9 8316 HOST_WIDE_INT val;
0ba1b2ff 8317 unsigned HOST_WIDE_INT uval;
9878760c
RK
8318
8319 switch (code)
8320 {
a8b3aeda 8321 case '.':
a85d226b
RK
8322 /* Write out an instruction after the call which may be replaced
8323 with glue code by the loader. This depends on the AIX version. */
8324 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8325 return;
8326
81eace42
GK
8327 /* %a is output_address. */
8328
9854d9ed
RK
8329 case 'A':
8330 /* If X is a constant integer whose low-order 5 bits are zero,
8331 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8332 in the AIX assembler where "sri" with a zero shift count
20e26713 8333 writes a trash instruction. */
9854d9ed 8334 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8335 putc ('l', file);
9854d9ed 8336 else
76229ac8 8337 putc ('r', file);
9854d9ed
RK
8338 return;
8339
8340 case 'b':
e2c953b6
DE
8341 /* If constant, low-order 16 bits of constant, unsigned.
8342 Otherwise, write normally. */
8343 if (INT_P (x))
8344 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8345 else
8346 print_operand (file, x, 0);
cad12a8d
RK
8347 return;
8348
a260abc9
DE
8349 case 'B':
8350 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8351 for 64-bit mask direction. */
296b8152 8352 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8353 return;
a260abc9 8354
81eace42
GK
8355 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8356 output_operand. */
8357
9854d9ed 8358 case 'E':
39a10a29 8359 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8360 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8361 output_operand_lossage ("invalid %%E value");
78fbdbf7 8362 else
39a10a29 8363 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8364 return;
9854d9ed
RK
8365
8366 case 'f':
8367 /* X is a CR register. Print the shift count needed to move it
8368 to the high-order four bits. */
8369 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8370 output_operand_lossage ("invalid %%f value");
8371 else
9ebbca7d 8372 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8373 return;
8374
8375 case 'F':
8376 /* Similar, but print the count for the rotate in the opposite
8377 direction. */
8378 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8379 output_operand_lossage ("invalid %%F value");
8380 else
9ebbca7d 8381 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8382 return;
8383
8384 case 'G':
8385 /* X is a constant integer. If it is negative, print "m",
43aa4e05 8386 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
8387 if (GET_CODE (x) != CONST_INT)
8388 output_operand_lossage ("invalid %%G value");
8389 else if (INTVAL (x) >= 0)
76229ac8 8390 putc ('z', file);
9854d9ed 8391 else
76229ac8 8392 putc ('m', file);
9854d9ed 8393 return;
e2c953b6 8394
9878760c 8395 case 'h':
a4f6c312
SS
8396 /* If constant, output low-order five bits. Otherwise, write
8397 normally. */
9878760c 8398 if (INT_P (x))
5f59ecb7 8399 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
8400 else
8401 print_operand (file, x, 0);
8402 return;
8403
64305719 8404 case 'H':
a4f6c312
SS
8405 /* If constant, output low-order six bits. Otherwise, write
8406 normally. */
64305719 8407 if (INT_P (x))
5f59ecb7 8408 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
8409 else
8410 print_operand (file, x, 0);
8411 return;
8412
9854d9ed
RK
8413 case 'I':
8414 /* Print `i' if this is a constant, else nothing. */
9878760c 8415 if (INT_P (x))
76229ac8 8416 putc ('i', file);
9878760c
RK
8417 return;
8418
9854d9ed
RK
8419 case 'j':
8420 /* Write the bit number in CCR for jump. */
8421 i = ccr_bit (x, 0);
8422 if (i == -1)
8423 output_operand_lossage ("invalid %%j code");
9878760c 8424 else
9854d9ed 8425 fprintf (file, "%d", i);
9878760c
RK
8426 return;
8427
9854d9ed
RK
8428 case 'J':
8429 /* Similar, but add one for shift count in rlinm for scc and pass
8430 scc flag to `ccr_bit'. */
8431 i = ccr_bit (x, 1);
8432 if (i == -1)
8433 output_operand_lossage ("invalid %%J code");
8434 else
a0466a68
RK
8435 /* If we want bit 31, write a shift count of zero, not 32. */
8436 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
8437 return;
8438
9854d9ed
RK
8439 case 'k':
8440 /* X must be a constant. Write the 1's complement of the
8441 constant. */
9878760c 8442 if (! INT_P (x))
9854d9ed 8443 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
8444 else
8445 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
8446 return;
8447
81eace42 8448 case 'K':
9ebbca7d
GK
8449 /* X must be a symbolic constant on ELF. Write an
8450 expression suitable for an 'addi' that adds in the low 16
8451 bits of the MEM. */
8452 if (GET_CODE (x) != CONST)
8453 {
8454 print_operand_address (file, x);
8455 fputs ("@l", file);
8456 }
8457 else
8458 {
8459 if (GET_CODE (XEXP (x, 0)) != PLUS
8460 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
8461 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
8462 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 8463 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
8464 print_operand_address (file, XEXP (XEXP (x, 0), 0));
8465 fputs ("@l", file);
ed8d2920
MM
8466 /* For GNU as, there must be a non-alphanumeric character
8467 between 'l' and the number. The '-' is added by
8468 print_operand() already. */
8469 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
8470 fputs ("+", file);
9ebbca7d
GK
8471 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
8472 }
81eace42
GK
8473 return;
8474
8475 /* %l is output_asm_label. */
9ebbca7d 8476
9854d9ed
RK
8477 case 'L':
8478 /* Write second word of DImode or DFmode reference. Works on register
8479 or non-indexed memory only. */
8480 if (GET_CODE (x) == REG)
5ebfb2ba 8481 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
8482 else if (GET_CODE (x) == MEM)
8483 {
8484 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 8485 we have already done it, we can just use an offset of word. */
9854d9ed
RK
8486 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8487 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
8488 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
8489 UNITS_PER_WORD));
9854d9ed 8490 else
d7624dc0
RK
8491 output_address (XEXP (adjust_address_nv (x, SImode,
8492 UNITS_PER_WORD),
8493 0));
ed8908e7 8494
ba5e43aa 8495 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8496 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8497 reg_names[SMALL_DATA_REG]);
9854d9ed 8498 }
9878760c 8499 return;
9854d9ed 8500
9878760c
RK
8501 case 'm':
8502 /* MB value for a mask operand. */
b1765bde 8503 if (! mask_operand (x, SImode))
9878760c
RK
8504 output_operand_lossage ("invalid %%m value");
8505
0ba1b2ff 8506 fprintf (file, "%d", extract_MB (x));
9878760c
RK
8507 return;
8508
8509 case 'M':
8510 /* ME value for a mask operand. */
b1765bde 8511 if (! mask_operand (x, SImode))
a260abc9 8512 output_operand_lossage ("invalid %%M value");
9878760c 8513
0ba1b2ff 8514 fprintf (file, "%d", extract_ME (x));
9878760c
RK
8515 return;
8516
81eace42
GK
8517 /* %n outputs the negative of its operand. */
8518
9878760c
RK
8519 case 'N':
8520 /* Write the number of elements in the vector times 4. */
8521 if (GET_CODE (x) != PARALLEL)
8522 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
8523 else
8524 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
8525 return;
8526
8527 case 'O':
8528 /* Similar, but subtract 1 first. */
8529 if (GET_CODE (x) != PARALLEL)
1427100a 8530 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
8531 else
8532 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
8533 return;
8534
9854d9ed
RK
8535 case 'p':
8536 /* X is a CONST_INT that is a power of two. Output the logarithm. */
8537 if (! INT_P (x)
2bfcf297 8538 || INT_LOWPART (x) < 0
9854d9ed
RK
8539 || (i = exact_log2 (INT_LOWPART (x))) < 0)
8540 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
8541 else
8542 fprintf (file, "%d", i);
9854d9ed
RK
8543 return;
8544
9878760c
RK
8545 case 'P':
8546 /* The operand must be an indirect memory reference. The result
a4f6c312 8547 is the register number. */
9878760c
RK
8548 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
8549 || REGNO (XEXP (x, 0)) >= 32)
8550 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
8551 else
8552 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
8553 return;
8554
dfbdccdb
GK
8555 case 'q':
8556 /* This outputs the logical code corresponding to a boolean
8557 expression. The expression may have one or both operands
39a10a29
GK
8558 negated (if one, only the first one). For condition register
8559 logical operations, it will also treat the negated
8560 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 8561 {
63bc1d05 8562 const char *const *t = 0;
dfbdccdb
GK
8563 const char *s;
8564 enum rtx_code code = GET_CODE (x);
8565 static const char * const tbl[3][3] = {
8566 { "and", "andc", "nor" },
8567 { "or", "orc", "nand" },
8568 { "xor", "eqv", "xor" } };
8569
8570 if (code == AND)
8571 t = tbl[0];
8572 else if (code == IOR)
8573 t = tbl[1];
8574 else if (code == XOR)
8575 t = tbl[2];
8576 else
8577 output_operand_lossage ("invalid %%q value");
8578
8579 if (GET_CODE (XEXP (x, 0)) != NOT)
8580 s = t[0];
8581 else
8582 {
8583 if (GET_CODE (XEXP (x, 1)) == NOT)
8584 s = t[2];
8585 else
8586 s = t[1];
8587 }
8588
8589 fputs (s, file);
8590 }
8591 return;
8592
2c4a9cff
DE
8593 case 'Q':
8594 if (TARGET_MFCRF)
8595 fputc (',',file);
8596 /* FALLTHRU */
8597 else
8598 return;
8599
9854d9ed
RK
8600 case 'R':
8601 /* X is a CR register. Print the mask for `mtcrf'. */
8602 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8603 output_operand_lossage ("invalid %%R value");
8604 else
9ebbca7d 8605 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 8606 return;
9854d9ed
RK
8607
8608 case 's':
8609 /* Low 5 bits of 32 - value */
8610 if (! INT_P (x))
8611 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
8612 else
8613 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 8614 return;
9854d9ed 8615
a260abc9 8616 case 'S':
0ba1b2ff 8617 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
8618 CONST_INT 32-bit mask is considered sign-extended so any
8619 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 8620 if (! mask64_operand (x, DImode))
a260abc9
DE
8621 output_operand_lossage ("invalid %%S value");
8622
0ba1b2ff 8623 uval = INT_LOWPART (x);
a260abc9 8624
0ba1b2ff 8625 if (uval & 1) /* Clear Left */
a260abc9 8626 {
f099d360
GK
8627#if HOST_BITS_PER_WIDE_INT > 64
8628 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
8629#endif
0ba1b2ff 8630 i = 64;
a260abc9 8631 }
0ba1b2ff 8632 else /* Clear Right */
a260abc9 8633 {
0ba1b2ff 8634 uval = ~uval;
f099d360
GK
8635#if HOST_BITS_PER_WIDE_INT > 64
8636 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
8637#endif
0ba1b2ff 8638 i = 63;
a260abc9 8639 }
0ba1b2ff
AM
8640 while (uval != 0)
8641 --i, uval >>= 1;
8642 if (i < 0)
8643 abort ();
8644 fprintf (file, "%d", i);
8645 return;
a260abc9 8646
a3170dc6
AH
8647 case 't':
8648 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
8649 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
8650 abort ();
8651
8652 /* Bit 3 is OV bit. */
8653 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
8654
8655 /* If we want bit 31, write a shift count of zero, not 32. */
8656 fprintf (file, "%d", i == 31 ? 0 : i + 1);
8657 return;
8658
cccf3bdc
DE
8659 case 'T':
8660 /* Print the symbolic name of a branch target register. */
8661 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
8662 && REGNO (x) != COUNT_REGISTER_REGNUM))
8663 output_operand_lossage ("invalid %%T value");
e2c953b6 8664 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
8665 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
8666 else
8667 fputs ("ctr", file);
8668 return;
8669
9854d9ed 8670 case 'u':
802a0058 8671 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
8672 if (! INT_P (x))
8673 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
8674 else
8675 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
8676 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
8677 return;
8678
802a0058
MM
8679 case 'v':
8680 /* High-order 16 bits of constant for use in signed operand. */
8681 if (! INT_P (x))
8682 output_operand_lossage ("invalid %%v value");
e2c953b6 8683 else
134c32f6
DE
8684 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
8685 (INT_LOWPART (x) >> 16) & 0xffff);
8686 return;
802a0058 8687
9854d9ed
RK
8688 case 'U':
8689 /* Print `u' if this has an auto-increment or auto-decrement. */
8690 if (GET_CODE (x) == MEM
8691 && (GET_CODE (XEXP (x, 0)) == PRE_INC
8692 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 8693 putc ('u', file);
9854d9ed 8694 return;
9878760c 8695
e0cd0770
JC
8696 case 'V':
8697 /* Print the trap code for this operand. */
8698 switch (GET_CODE (x))
8699 {
8700 case EQ:
8701 fputs ("eq", file); /* 4 */
8702 break;
8703 case NE:
8704 fputs ("ne", file); /* 24 */
8705 break;
8706 case LT:
8707 fputs ("lt", file); /* 16 */
8708 break;
8709 case LE:
8710 fputs ("le", file); /* 20 */
8711 break;
8712 case GT:
8713 fputs ("gt", file); /* 8 */
8714 break;
8715 case GE:
8716 fputs ("ge", file); /* 12 */
8717 break;
8718 case LTU:
8719 fputs ("llt", file); /* 2 */
8720 break;
8721 case LEU:
8722 fputs ("lle", file); /* 6 */
8723 break;
8724 case GTU:
8725 fputs ("lgt", file); /* 1 */
8726 break;
8727 case GEU:
8728 fputs ("lge", file); /* 5 */
8729 break;
8730 default:
8731 abort ();
8732 }
8733 break;
8734
9854d9ed
RK
8735 case 'w':
8736 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
8737 normally. */
8738 if (INT_P (x))
5f59ecb7
DE
8739 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
8740 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
8741 else
8742 print_operand (file, x, 0);
9878760c
RK
8743 return;
8744
9854d9ed 8745 case 'W':
e2c953b6 8746 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
8747 val = (GET_CODE (x) == CONST_INT
8748 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
8749
8750 if (val < 0)
8751 i = -1;
9854d9ed 8752 else
e2c953b6
DE
8753 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
8754 if ((val <<= 1) < 0)
8755 break;
8756
8757#if HOST_BITS_PER_WIDE_INT == 32
8758 if (GET_CODE (x) == CONST_INT && i >= 0)
8759 i += 32; /* zero-extend high-part was all 0's */
8760 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
8761 {
8762 val = CONST_DOUBLE_LOW (x);
8763
8764 if (val == 0)
a4f6c312 8765 abort ();
e2c953b6
DE
8766 else if (val < 0)
8767 --i;
8768 else
8769 for ( ; i < 64; i++)
8770 if ((val <<= 1) < 0)
8771 break;
8772 }
8773#endif
8774
8775 fprintf (file, "%d", i + 1);
9854d9ed 8776 return;
9878760c 8777
9854d9ed
RK
8778 case 'X':
8779 if (GET_CODE (x) == MEM
4d588c14 8780 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 8781 putc ('x', file);
9854d9ed 8782 return;
9878760c 8783
9854d9ed
RK
8784 case 'Y':
8785 /* Like 'L', for third word of TImode */
8786 if (GET_CODE (x) == REG)
5ebfb2ba 8787 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 8788 else if (GET_CODE (x) == MEM)
9878760c 8789 {
9854d9ed
RK
8790 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8791 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8792 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 8793 else
d7624dc0 8794 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 8795 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8796 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8797 reg_names[SMALL_DATA_REG]);
9878760c
RK
8798 }
8799 return;
9854d9ed 8800
9878760c 8801 case 'z':
b4ac57ab
RS
8802 /* X is a SYMBOL_REF. Write out the name preceded by a
8803 period and without any trailing data in brackets. Used for function
4d30c363
MM
8804 names. If we are configured for System V (or the embedded ABI) on
8805 the PowerPC, do not emit the period, since those systems do not use
8806 TOCs and the like. */
9878760c
RK
8807 if (GET_CODE (x) != SYMBOL_REF)
8808 abort ();
8809
b6c9286a
MM
8810 if (XSTR (x, 0)[0] != '.')
8811 {
8812 switch (DEFAULT_ABI)
8813 {
8814 default:
8815 abort ();
8816
8817 case ABI_AIX:
8818 putc ('.', file);
8819 break;
8820
8821 case ABI_V4:
ee890fe2 8822 case ABI_DARWIN:
b6c9286a 8823 break;
b6c9286a
MM
8824 }
8825 }
9739c90c
JJ
8826 if (TARGET_AIX)
8827 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
8828 else
8829 assemble_name (file, XSTR (x, 0));
9878760c
RK
8830 return;
8831
9854d9ed
RK
8832 case 'Z':
8833 /* Like 'L', for last word of TImode. */
8834 if (GET_CODE (x) == REG)
5ebfb2ba 8835 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
8836 else if (GET_CODE (x) == MEM)
8837 {
8838 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8839 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8840 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 8841 else
d7624dc0 8842 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 8843 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8844 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8845 reg_names[SMALL_DATA_REG]);
9854d9ed 8846 }
5c23c401 8847 return;
0ac081f6 8848
a3170dc6 8849 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
8850 case 'y':
8851 {
8852 rtx tmp;
8853
8854 if (GET_CODE (x) != MEM)
8855 abort ();
8856
8857 tmp = XEXP (x, 0);
8858
993f19a8 8859 if (TARGET_E500)
a3170dc6
AH
8860 {
8861 /* Handle [reg]. */
8862 if (GET_CODE (tmp) == REG)
8863 {
8864 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
8865 break;
8866 }
8867 /* Handle [reg+UIMM]. */
8868 else if (GET_CODE (tmp) == PLUS &&
8869 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
8870 {
8871 int x;
8872
8873 if (GET_CODE (XEXP (tmp, 0)) != REG)
8874 abort ();
8875
8876 x = INTVAL (XEXP (tmp, 1));
8877 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
8878 break;
8879 }
8880
8881 /* Fall through. Must be [reg+reg]. */
8882 }
0ac081f6 8883 if (GET_CODE (tmp) == REG)
c62f2db5 8884 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
8885 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
8886 {
8887 if (REGNO (XEXP (tmp, 0)) == 0)
8888 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
8889 reg_names[ REGNO (XEXP (tmp, 0)) ]);
8890 else
8891 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
8892 reg_names[ REGNO (XEXP (tmp, 1)) ]);
8893 }
8894 else
8895 abort ();
8896 break;
8897 }
9854d9ed 8898
9878760c
RK
8899 case 0:
8900 if (GET_CODE (x) == REG)
8901 fprintf (file, "%s", reg_names[REGNO (x)]);
8902 else if (GET_CODE (x) == MEM)
8903 {
8904 /* We need to handle PRE_INC and PRE_DEC here, since we need to
8905 know the width from the mode. */
8906 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
8907 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
8908 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8909 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
8910 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
8911 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8912 else
a54d04b7 8913 output_address (XEXP (x, 0));
9878760c
RK
8914 }
8915 else
a54d04b7 8916 output_addr_const (file, x);
a85d226b 8917 return;
9878760c 8918
c4501e62
JJ
8919 case '&':
8920 assemble_name (file, rs6000_get_some_local_dynamic_name ());
8921 return;
8922
9878760c
RK
8923 default:
8924 output_operand_lossage ("invalid %%xn code");
8925 }
8926}
8927\f
8928/* Print the address of an operand. */
8929
8930void
8931print_operand_address (file, x)
8932 FILE *file;
592696dd 8933 rtx x;
9878760c
RK
8934{
8935 if (GET_CODE (x) == REG)
4697a36c 8936 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
8937 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
8938 || GET_CODE (x) == LABEL_REF)
9878760c
RK
8939 {
8940 output_addr_const (file, x);
ba5e43aa 8941 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8942 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8943 reg_names[SMALL_DATA_REG]);
9ebbca7d 8944 else if (TARGET_TOC)
a4f6c312 8945 abort ();
9878760c
RK
8946 }
8947 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
8948 {
8949 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
8950 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
8951 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 8952 else
4697a36c
MM
8953 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
8954 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
8955 }
8956 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
8957 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
8958 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
8959#if TARGET_ELF
8960 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8961 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
8962 {
8963 output_addr_const (file, XEXP (x, 1));
8964 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8965 }
c859cda6
DJ
8966#endif
8967#if TARGET_MACHO
8968 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8969 && CONSTANT_P (XEXP (x, 1)))
8970 {
8971 fprintf (file, "lo16(");
8972 output_addr_const (file, XEXP (x, 1));
8973 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8974 }
3cb999d8 8975#endif
4d588c14 8976 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 8977 {
2bfcf297 8978 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 8979 {
2bfcf297
DB
8980 rtx contains_minus = XEXP (x, 1);
8981 rtx minus, symref;
8982 const char *name;
9ebbca7d
GK
8983
8984 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 8985 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
8986 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
8987 contains_minus = XEXP (contains_minus, 0);
8988
2bfcf297
DB
8989 minus = XEXP (contains_minus, 0);
8990 symref = XEXP (minus, 0);
8991 XEXP (contains_minus, 0) = symref;
8992 if (TARGET_ELF)
8993 {
8994 char *newname;
8995
8996 name = XSTR (symref, 0);
8997 newname = alloca (strlen (name) + sizeof ("@toc"));
8998 strcpy (newname, name);
8999 strcat (newname, "@toc");
9000 XSTR (symref, 0) = newname;
9001 }
9002 output_addr_const (file, XEXP (x, 1));
9003 if (TARGET_ELF)
9004 XSTR (symref, 0) = name;
9ebbca7d
GK
9005 XEXP (contains_minus, 0) = minus;
9006 }
9007 else
9008 output_addr_const (file, XEXP (x, 1));
9009
9010 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9011 }
9878760c
RK
9012 else
9013 abort ();
9014}
9015\f
88cad84b 9016/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9017 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9018 is defined. It also needs to handle DI-mode objects on 64-bit
9019 targets. */
9020
9021static bool
9022rs6000_assemble_integer (x, size, aligned_p)
9023 rtx x;
9024 unsigned int size;
9025 int aligned_p;
9026{
9027#ifdef RELOCATABLE_NEEDS_FIXUP
9028 /* Special handling for SI values. */
9029 if (size == 4 && aligned_p)
9030 {
9031 extern int in_toc_section PARAMS ((void));
9032 static int recurse = 0;
9033
9034 /* For -mrelocatable, we mark all addresses that need to be fixed up
9035 in the .fixup section. */
9036 if (TARGET_RELOCATABLE
9037 && !in_toc_section ()
9038 && !in_text_section ()
9039 && !recurse
9040 && GET_CODE (x) != CONST_INT
9041 && GET_CODE (x) != CONST_DOUBLE
9042 && CONSTANT_P (x))
9043 {
9044 char buf[256];
9045
9046 recurse = 1;
9047 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9048 fixuplabelno++;
9049 ASM_OUTPUT_LABEL (asm_out_file, buf);
9050 fprintf (asm_out_file, "\t.long\t(");
9051 output_addr_const (asm_out_file, x);
9052 fprintf (asm_out_file, ")@fixup\n");
9053 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9054 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9055 fprintf (asm_out_file, "\t.long\t");
9056 assemble_name (asm_out_file, buf);
9057 fprintf (asm_out_file, "\n\t.previous\n");
9058 recurse = 0;
9059 return true;
9060 }
9061 /* Remove initial .'s to turn a -mcall-aixdesc function
9062 address into the address of the descriptor, not the function
9063 itself. */
9064 else if (GET_CODE (x) == SYMBOL_REF
9065 && XSTR (x, 0)[0] == '.'
9066 && DEFAULT_ABI == ABI_AIX)
9067 {
9068 const char *name = XSTR (x, 0);
9069 while (*name == '.')
9070 name++;
9071
9072 fprintf (asm_out_file, "\t.long\t%s\n", name);
9073 return true;
9074 }
9075 }
9076#endif /* RELOCATABLE_NEEDS_FIXUP */
9077 return default_assemble_integer (x, size, aligned_p);
9078}
93638d7a
AM
9079
9080#ifdef HAVE_GAS_HIDDEN
9081/* Emit an assembler directive to set symbol visibility for DECL to
9082 VISIBILITY_TYPE. */
9083
5add3202 9084static void
25fdb4dc 9085rs6000_assemble_visibility (decl, vis)
93638d7a 9086 tree decl;
25fdb4dc 9087 int vis;
93638d7a 9088{
93638d7a
AM
9089 /* Functions need to have their entry point symbol visibility set as
9090 well as their descriptor symbol visibility. */
9091 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9092 {
25fdb4dc
RH
9093 static const char * const visibility_types[] = {
9094 NULL, "internal", "hidden", "protected"
9095 };
9096
9097 const char *name, *type;
93638d7a
AM
9098
9099 name = ((* targetm.strip_name_encoding)
9100 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9101 type = visibility_types[vis];
93638d7a 9102
25fdb4dc
RH
9103 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9104 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9105 }
25fdb4dc
RH
9106 else
9107 default_assemble_visibility (decl, vis);
93638d7a
AM
9108}
9109#endif
301d03af 9110\f
39a10a29
GK
9111enum rtx_code
9112rs6000_reverse_condition (mode, code)
9113 enum machine_mode mode;
9114 enum rtx_code code;
9115{
9116 /* Reversal of FP compares takes care -- an ordered compare
9117 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9118 if (mode == CCFPmode
9119 && (!flag_finite_math_only
9120 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9121 || code == UNEQ || code == LTGT))
bab6226b 9122 return reverse_condition_maybe_unordered (code);
39a10a29 9123 else
bab6226b 9124 return reverse_condition (code);
39a10a29
GK
9125}
9126
39a10a29
GK
9127/* Generate a compare for CODE. Return a brand-new rtx that
9128 represents the result of the compare. */
a4f6c312 9129
39a10a29
GK
9130static rtx
9131rs6000_generate_compare (code)
9132 enum rtx_code code;
9133{
9134 enum machine_mode comp_mode;
9135 rtx compare_result;
9136
9137 if (rs6000_compare_fp_p)
9138 comp_mode = CCFPmode;
9139 else if (code == GTU || code == LTU
9140 || code == GEU || code == LEU)
9141 comp_mode = CCUNSmode;
9142 else
9143 comp_mode = CCmode;
9144
9145 /* First, the compare. */
9146 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9147
9148 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9149 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9150 && rs6000_compare_fp_p)
a3170dc6
AH
9151 {
9152 rtx cmp, or1, or2, or_result, compare_result2;
9153
9154 switch (code)
9155 {
9156 case EQ:
9157 case UNEQ:
9158 case NE:
9159 case LTGT:
bc9ec0e0 9160 cmp = flag_finite_math_only
a3170dc6
AH
9161 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9162 rs6000_compare_op1)
9163 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9164 rs6000_compare_op1);
9165 break;
9166 case GT:
9167 case GTU:
9168 case UNGT:
9169 case UNGE:
9170 case GE:
9171 case GEU:
bc9ec0e0 9172 cmp = flag_finite_math_only
a3170dc6
AH
9173 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9174 rs6000_compare_op1)
9175 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9176 rs6000_compare_op1);
9177 break;
9178 case LT:
9179 case LTU:
9180 case UNLT:
9181 case UNLE:
9182 case LE:
9183 case LEU:
bc9ec0e0 9184 cmp = flag_finite_math_only
a3170dc6
AH
9185 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9186 rs6000_compare_op1)
9187 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9188 rs6000_compare_op1);
9189 break;
9190 default:
9191 abort ();
9192 }
9193
9194 /* Synthesize LE and GE from LT/GT || EQ. */
9195 if (code == LE || code == GE || code == LEU || code == GEU)
9196 {
9197 /* Synthesize GE/LE frome GT/LT || EQ. */
9198
9199 emit_insn (cmp);
9200
9201 switch (code)
9202 {
9203 case LE: code = LT; break;
9204 case GE: code = GT; break;
9205 case LEU: code = LT; break;
9206 case GEU: code = GT; break;
9207 default: abort ();
9208 }
9209
9210 or1 = gen_reg_rtx (SImode);
9211 or2 = gen_reg_rtx (SImode);
9212 or_result = gen_reg_rtx (CCEQmode);
9213 compare_result2 = gen_reg_rtx (CCFPmode);
9214
9215 /* Do the EQ. */
bc9ec0e0 9216 cmp = flag_finite_math_only
a3170dc6
AH
9217 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9218 rs6000_compare_op1)
9219 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9220 rs6000_compare_op1);
9221 emit_insn (cmp);
9222
9223 /* The MC8540 FP compare instructions set the CR bits
9224 differently than other PPC compare instructions. For
9225 that matter, there is no generic test instruction, but a
9226 testgt, testlt, and testeq. For a true condition, bit 2
9227 is set (x1xx) in the CR. Following the traditional CR
9228 values:
9229
9230 LT GT EQ OV
9231 bit3 bit2 bit1 bit0
9232
9233 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9234 look in the GT bits for the branch instructions.
a3170dc6
AH
9235 However, we must be careful to emit correct RTL in
9236 the meantime, so optimizations don't get confused. */
9237
9238 or1 = gen_rtx (NE, SImode, compare_result, const0_rtx);
9239 or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx);
9240
9241 /* OR them together. */
9242 cmp = gen_rtx_SET (VOIDmode, or_result,
9243 gen_rtx_COMPARE (CCEQmode,
9244 gen_rtx_IOR (SImode, or1, or2),
9245 const_true_rtx));
9246 compare_result = or_result;
9247 code = EQ;
9248 }
9249 else
9250 {
9251 /* We only care about 1 bit (x1xx), so map everything to NE to
9252 maintain rtl sanity. We'll get to the right bit (x1xx) at
9253 code output time. */
9254 if (code == NE || code == LTGT)
9255 /* Do the inverse here because we have no cmpne
9256 instruction. We use the cmpeq instruction and expect
9257 to get a 0 instead. */
9258 code = EQ;
9259 else
9260 code = NE;
9261 }
9262
9263 emit_insn (cmp);
9264 }
9265 else
9266 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9267 gen_rtx_COMPARE (comp_mode,
9268 rs6000_compare_op0,
9269 rs6000_compare_op1)));
39a10a29 9270
ca5adc63 9271 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9272 under flag_finite_math_only we don't bother. */
39a10a29 9273 if (rs6000_compare_fp_p
bc9ec0e0 9274 && ! flag_finite_math_only
993f19a8 9275 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9276 && (code == LE || code == GE
9277 || code == UNEQ || code == LTGT
9278 || code == UNGT || code == UNLT))
9279 {
9280 enum rtx_code or1, or2;
9281 rtx or1_rtx, or2_rtx, compare2_rtx;
9282 rtx or_result = gen_reg_rtx (CCEQmode);
9283
9284 switch (code)
9285 {
9286 case LE: or1 = LT; or2 = EQ; break;
9287 case GE: or1 = GT; or2 = EQ; break;
9288 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9289 case LTGT: or1 = LT; or2 = GT; break;
9290 case UNGT: or1 = UNORDERED; or2 = GT; break;
9291 case UNLT: or1 = UNORDERED; or2 = LT; break;
9292 default: abort ();
9293 }
9294 validate_condition_mode (or1, comp_mode);
9295 validate_condition_mode (or2, comp_mode);
9296 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
9297 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
9298 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9299 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9300 const_true_rtx);
9301 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9302
9303 compare_result = or_result;
9304 code = EQ;
9305 }
9306
9307 validate_condition_mode (code, GET_MODE (compare_result));
9308
9309 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
9310}
9311
9312
9313/* Emit the RTL for an sCOND pattern. */
9314
9315void
9316rs6000_emit_sCOND (code, result)
9317 enum rtx_code code;
9318 rtx result;
9319{
9320 rtx condition_rtx;
9321 enum machine_mode op_mode;
b7053a3f 9322 enum rtx_code cond_code;
39a10a29
GK
9323
9324 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9325 cond_code = GET_CODE (condition_rtx);
9326
9327 if (cond_code == NE
9328 || cond_code == GE || cond_code == LE
9329 || cond_code == GEU || cond_code == LEU
9330 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9331 {
9332 rtx not_result = gen_reg_rtx (CCEQmode);
9333 rtx not_op, rev_cond_rtx;
9334 enum machine_mode cc_mode;
9335
9336 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9337
9338 rev_cond_rtx = gen_rtx (rs6000_reverse_condition (cc_mode, cond_code),
9339 SImode, XEXP (condition_rtx, 0), const0_rtx);
9340 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9341 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9342 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9343 }
39a10a29
GK
9344
9345 op_mode = GET_MODE (rs6000_compare_op0);
9346 if (op_mode == VOIDmode)
9347 op_mode = GET_MODE (rs6000_compare_op1);
9348
9349 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9350 {
9351 PUT_MODE (condition_rtx, DImode);
9352 convert_move (result, condition_rtx, 0);
9353 }
9354 else
9355 {
9356 PUT_MODE (condition_rtx, SImode);
9357 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9358 }
9359}
9360
39a10a29
GK
9361/* Emit a branch of kind CODE to location LOC. */
9362
9363void
9364rs6000_emit_cbranch (code, loc)
9365 enum rtx_code code;
9366 rtx loc;
9367{
9368 rtx condition_rtx, loc_ref;
9369
9370 condition_rtx = rs6000_generate_compare (code);
9371 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9372 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9373 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9374 loc_ref, pc_rtx)));
9375}
9376
12a4e8c5
GK
9377/* Return the string to output a conditional branch to LABEL, which is
9378 the operand number of the label, or -1 if the branch is really a
9379 conditional return.
9380
9381 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9382 condition code register and its mode specifies what kind of
9383 comparison we made.
9384
a0ab749a 9385 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9386
9387 INSN is the insn. */
9388
9389char *
9390output_cbranch (op, label, reversed, insn)
9391 rtx op;
9392 const char * label;
9393 int reversed;
9394 rtx insn;
9395{
9396 static char string[64];
9397 enum rtx_code code = GET_CODE (op);
9398 rtx cc_reg = XEXP (op, 0);
9399 enum machine_mode mode = GET_MODE (cc_reg);
9400 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 9401 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
9402 int really_reversed = reversed ^ need_longbranch;
9403 char *s = string;
9404 const char *ccode;
9405 const char *pred;
9406 rtx note;
9407
39a10a29
GK
9408 validate_condition_mode (code, mode);
9409
9410 /* Work out which way this really branches. We could use
9411 reverse_condition_maybe_unordered here always but this
9412 makes the resulting assembler clearer. */
12a4e8c5 9413 if (really_reversed)
de40e1df
DJ
9414 {
9415 /* Reversal of FP compares takes care -- an ordered compare
9416 becomes an unordered compare and vice versa. */
9417 if (mode == CCFPmode)
9418 code = reverse_condition_maybe_unordered (code);
9419 else
9420 code = reverse_condition (code);
9421 }
12a4e8c5 9422
993f19a8 9423 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
9424 {
9425 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
9426 to the GT bit. */
9427 if (code == EQ)
9428 /* Opposite of GT. */
9429 code = UNLE;
9430 else if (code == NE)
9431 code = GT;
9432 else
9433 abort ();
9434 }
9435
39a10a29 9436 switch (code)
12a4e8c5
GK
9437 {
9438 /* Not all of these are actually distinct opcodes, but
9439 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
9440 case NE: case LTGT:
9441 ccode = "ne"; break;
9442 case EQ: case UNEQ:
9443 ccode = "eq"; break;
9444 case GE: case GEU:
9445 ccode = "ge"; break;
9446 case GT: case GTU: case UNGT:
9447 ccode = "gt"; break;
9448 case LE: case LEU:
9449 ccode = "le"; break;
9450 case LT: case LTU: case UNLT:
9451 ccode = "lt"; break;
12a4e8c5
GK
9452 case UNORDERED: ccode = "un"; break;
9453 case ORDERED: ccode = "nu"; break;
9454 case UNGE: ccode = "nl"; break;
9455 case UNLE: ccode = "ng"; break;
9456 default:
a4f6c312 9457 abort ();
12a4e8c5
GK
9458 }
9459
94a54f47
GK
9460 /* Maybe we have a guess as to how likely the branch is.
9461 The old mnemonics don't have a way to specify this information. */
f4857b9b 9462 pred = "";
12a4e8c5
GK
9463 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
9464 if (note != NULL_RTX)
9465 {
9466 /* PROB is the difference from 50%. */
9467 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
9468 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
9469
9470 /* Only hint for highly probable/improbable branches on newer
9471 cpus as static prediction overrides processor dynamic
9472 prediction. For older cpus we may as well always hint, but
9473 assume not taken for branches that are very close to 50% as a
9474 mispredicted taken branch is more expensive than a
9475 mispredicted not-taken branch. */
9476 if (always_hint
9477 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
9478 {
9479 if (abs (prob) > REG_BR_PROB_BASE / 20
9480 && ((prob > 0) ^ need_longbranch))
7f3d8013 9481 pred = "+";
f4857b9b
AM
9482 else
9483 pred = "-";
9484 }
12a4e8c5 9485 }
12a4e8c5
GK
9486
9487 if (label == NULL)
94a54f47 9488 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 9489 else
94a54f47 9490 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 9491
37c67319
GK
9492 /* We need to escape any '%' characters in the reg_names string.
9493 Assume they'd only be the first character... */
9494 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
9495 *s++ = '%';
94a54f47 9496 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
9497
9498 if (label != NULL)
9499 {
9500 /* If the branch distance was too far, we may have to use an
9501 unconditional branch to go the distance. */
9502 if (need_longbranch)
44518ddd 9503 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
9504 else
9505 s += sprintf (s, ",%s", label);
9506 }
9507
9508 return string;
9509}
50a0b056
GK
9510
9511/* Emit a conditional move: move TRUE_COND to DEST if OP of the
9512 operands of the last comparison is nonzero/true, FALSE_COND if it
9513 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 9514
50a0b056
GK
9515int
9516rs6000_emit_cmove (dest, op, true_cond, false_cond)
9517 rtx dest;
9518 rtx op;
9519 rtx true_cond;
9520 rtx false_cond;
9521{
9522 enum rtx_code code = GET_CODE (op);
9523 rtx op0 = rs6000_compare_op0;
9524 rtx op1 = rs6000_compare_op1;
9525 REAL_VALUE_TYPE c1;
3148ad6d
DJ
9526 enum machine_mode compare_mode = GET_MODE (op0);
9527 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
9528 rtx temp;
9529
3148ad6d 9530 /* These modes should always match. */
a3170dc6
AH
9531 if (GET_MODE (op1) != compare_mode
9532 /* In the isel case however, we can use a compare immediate, so
9533 op1 may be a small constant. */
9534 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 9535 return 0;
178c3eff 9536 if (GET_MODE (true_cond) != result_mode)
3148ad6d 9537 return 0;
178c3eff 9538 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
9539 return 0;
9540
50a0b056
GK
9541 /* First, work out if the hardware can do this at all, or
9542 if it's too slow... */
50a0b056 9543 if (! rs6000_compare_fp_p)
a3170dc6
AH
9544 {
9545 if (TARGET_ISEL)
9546 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
9547 return 0;
9548 }
50a0b056
GK
9549
9550 /* Eliminate half of the comparisons by switching operands, this
9551 makes the remaining code simpler. */
9552 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 9553 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
9554 {
9555 code = reverse_condition_maybe_unordered (code);
9556 temp = true_cond;
9557 true_cond = false_cond;
9558 false_cond = temp;
9559 }
9560
9561 /* UNEQ and LTGT take four instructions for a comparison with zero,
9562 it'll probably be faster to use a branch here too. */
bc9ec0e0 9563 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
9564 return 0;
9565
9566 if (GET_CODE (op1) == CONST_DOUBLE)
9567 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
9568
b6d08ca1 9569 /* We're going to try to implement comparisons by performing
50a0b056
GK
9570 a subtract, then comparing against zero. Unfortunately,
9571 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 9572 know that the operand is finite and the comparison
50a0b056 9573 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 9574 if (HONOR_INFINITIES (compare_mode)
50a0b056 9575 && code != GT && code != UNGE
045572c7 9576 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
9577 /* Constructs of the form (a OP b ? a : b) are safe. */
9578 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
9579 || (! rtx_equal_p (op0, true_cond)
9580 && ! rtx_equal_p (op1, true_cond))))
9581 return 0;
9582 /* At this point we know we can use fsel. */
9583
9584 /* Reduce the comparison to a comparison against zero. */
3148ad6d 9585 temp = gen_reg_rtx (compare_mode);
50a0b056 9586 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9587 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 9588 op0 = temp;
3148ad6d 9589 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
9590
9591 /* If we don't care about NaNs we can reduce some of the comparisons
9592 down to faster ones. */
bc9ec0e0 9593 if (! HONOR_NANS (compare_mode))
50a0b056
GK
9594 switch (code)
9595 {
9596 case GT:
9597 code = LE;
9598 temp = true_cond;
9599 true_cond = false_cond;
9600 false_cond = temp;
9601 break;
9602 case UNGE:
9603 code = GE;
9604 break;
9605 case UNEQ:
9606 code = EQ;
9607 break;
9608 default:
9609 break;
9610 }
9611
9612 /* Now, reduce everything down to a GE. */
9613 switch (code)
9614 {
9615 case GE:
9616 break;
9617
9618 case LE:
3148ad6d
DJ
9619 temp = gen_reg_rtx (compare_mode);
9620 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9621 op0 = temp;
9622 break;
9623
9624 case ORDERED:
3148ad6d
DJ
9625 temp = gen_reg_rtx (compare_mode);
9626 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
9627 op0 = temp;
9628 break;
9629
9630 case EQ:
3148ad6d 9631 temp = gen_reg_rtx (compare_mode);
50a0b056 9632 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
9633 gen_rtx_NEG (compare_mode,
9634 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
9635 op0 = temp;
9636 break;
9637
9638 case UNGE:
bc9ec0e0 9639 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 9640 temp = gen_reg_rtx (result_mode);
50a0b056 9641 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9642 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9643 gen_rtx_GE (VOIDmode,
9644 op0, op1),
9645 true_cond, false_cond)));
bc9ec0e0
GK
9646 false_cond = true_cond;
9647 true_cond = temp;
50a0b056 9648
3148ad6d
DJ
9649 temp = gen_reg_rtx (compare_mode);
9650 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9651 op0 = temp;
9652 break;
9653
9654 case GT:
bc9ec0e0 9655 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 9656 temp = gen_reg_rtx (result_mode);
50a0b056 9657 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9658 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9659 gen_rtx_GE (VOIDmode,
9660 op0, op1),
9661 true_cond, false_cond)));
bc9ec0e0
GK
9662 true_cond = false_cond;
9663 false_cond = temp;
50a0b056 9664
3148ad6d
DJ
9665 temp = gen_reg_rtx (compare_mode);
9666 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9667 op0 = temp;
9668 break;
9669
9670 default:
9671 abort ();
9672 }
9673
9674 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 9675 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9676 gen_rtx_GE (VOIDmode,
9677 op0, op1),
9678 true_cond, false_cond)));
9679 return 1;
9680}
9681
a3170dc6
AH
9682/* Same as above, but for ints (isel). */
9683
9684static int
9685rs6000_emit_int_cmove (dest, op, true_cond, false_cond)
9686 rtx dest;
9687 rtx op;
9688 rtx true_cond;
9689 rtx false_cond;
9690{
9691 rtx condition_rtx, cr;
9692
9693 /* All isel implementations thus far are 32-bits. */
9694 if (GET_MODE (rs6000_compare_op0) != SImode)
9695 return 0;
9696
9697 /* We still have to do the compare, because isel doesn't do a
9698 compare, it just looks at the CRx bits set by a previous compare
9699 instruction. */
9700 condition_rtx = rs6000_generate_compare (GET_CODE (op));
9701 cr = XEXP (condition_rtx, 0);
9702
9703 if (GET_MODE (cr) == CCmode)
9704 emit_insn (gen_isel_signed (dest, condition_rtx,
9705 true_cond, false_cond, cr));
9706 else
9707 emit_insn (gen_isel_unsigned (dest, condition_rtx,
9708 true_cond, false_cond, cr));
9709
9710 return 1;
9711}
9712
9713const char *
9714output_isel (operands)
9715 rtx *operands;
9716{
9717 enum rtx_code code;
9718
9719 code = GET_CODE (operands[1]);
9720 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
9721 {
9722 PUT_CODE (operands[1], reverse_condition (code));
9723 return "isel %0,%3,%2,%j1";
9724 }
9725 else
9726 return "isel %0,%2,%3,%j1";
9727}
9728
50a0b056
GK
9729void
9730rs6000_emit_minmax (dest, code, op0, op1)
9731 rtx dest;
9732 enum rtx_code code;
9733 rtx op0;
9734 rtx op1;
9735{
9736 enum machine_mode mode = GET_MODE (op0);
5dc8d536 9737 enum rtx_code c;
50a0b056 9738 rtx target;
5dc8d536
AH
9739
9740 if (code == SMAX || code == SMIN)
9741 c = GE;
9742 else
9743 c = GEU;
9744
50a0b056 9745 if (code == SMAX || code == UMAX)
5dc8d536 9746 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
9747 op0, op1, mode, 0);
9748 else
5dc8d536 9749 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
9750 op1, op0, mode, 0);
9751 if (target == NULL_RTX)
9752 abort ();
9753 if (target != dest)
9754 emit_move_insn (dest, target);
9755}
46c07df8
HP
9756
9757/* Called by altivec splitter.
9758 Input:
9759 operands[0] : Destination of move
9760 operands[1] : Source of move
9761 noperands : Size of operands vector
9762 Output:
9763 operands[2-5] ([2-3] in 64 bit) : Destination slots
9764 operands[6-9] ([4-5] in 64 bit) : Source slots
9765
9766 Splits the move of operands[1] to operands[0].
9767 This is done, if GPRs are one of the operands. In this case
9768 a sequence of simple move insns has to be issued. The sequence of these
9769 move insns has to be done in correct order to avoid early clobber of the
9770 base register or destructive overlap of registers.
9771*/
9772
9773void
9774rs6000_split_altivec_in_gprs (rtx *operands)
9775{
9776 int nregs, reg, i, j;
9777 enum machine_mode mode;
9778
9779 /* Calculate number to move (2/4 for 32/64 bit mode). */
9780
9781 reg = REG_P (operands[0]) ? REGNO (operands[0]) : REGNO (operands[1]);
9782 mode = GET_MODE (operands[0]);
9783 nregs = HARD_REGNO_NREGS (reg, mode);
9784
9785 if (REG_P (operands[1])
9786 && REG_P (operands[0])
9787 && (REGNO (operands[1]) < REGNO (operands[0])))
9788 {
9789 /* Move register range backwards, if we have destructive overlap. */
9790
9791 j = nregs;
9792 for (i = 0; i < nregs; i++)
9793 {
9794 j--;
9795 operands[i + 2] = operand_subword (operands[0], j, 0, mode);
9796 operands[i + 2 + nregs] =
9797 operand_subword (operands[1], j, 0, mode);
9798 }
9799 }
9800 else
9801 {
9802 j = -1;
9803
9804 if (GET_CODE (operands[1]) == MEM)
9805 {
9806 rtx breg;
9807 /* We have offsettable addresses only. If we use one of the
9808 registers to address memory, we have change that register last. */
9809 breg = GET_CODE (XEXP (operands[1], 0)) == PLUS ?
9810 XEXP (XEXP (operands[1], 0), 0) :
9811 XEXP (operands[1], 0);
9812
9813 if (REGNO (breg) >= REGNO (operands[0])
9814 && REGNO (breg) < REGNO (operands[0]) + nregs)
9815 j = REGNO (breg) - REGNO (operands[0]);
9816 }
9817
9818 for (i = 0; i < nregs; i++)
9819 {
9820 /* Calculate index to next subword. */
9821 j++;
9822 if (j == nregs)
9823 j = 0;
9824
9825 operands[i + 2] = operand_subword (operands[0], j, 0, mode);
9826 operands[i + 2 + nregs] =
9827 operand_subword (operands[1], j, 0, mode);
9828
9829 }
9830 }
9831}
9832
12a4e8c5 9833\f
a4f6c312
SS
9834/* This page contains routines that are used to determine what the
9835 function prologue and epilogue code will do and write them out. */
9878760c 9836
a4f6c312
SS
9837/* Return the first fixed-point register that is required to be
9838 saved. 32 if none. */
9878760c
RK
9839
9840int
9841first_reg_to_save ()
9842{
9843 int first_reg;
9844
9845 /* Find lowest numbered live register. */
9846 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
9847 if (regs_ever_live[first_reg]
9848 && (! call_used_regs[first_reg]
1db02437 9849 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 9850 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 9851 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
9852 break;
9853
ee890fe2 9854#if TARGET_MACHO
93638d7a
AM
9855 if (flag_pic
9856 && current_function_uses_pic_offset_table
9857 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 9858 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
9859#endif
9860
9878760c
RK
9861 return first_reg;
9862}
9863
9864/* Similar, for FP regs. */
9865
9866int
9867first_fp_reg_to_save ()
9868{
9869 int first_reg;
9870
9871 /* Find lowest numbered live register. */
9872 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
9873 if (regs_ever_live[first_reg])
9874 break;
9875
9876 return first_reg;
9877}
00b960c7
AH
9878
9879/* Similar, for AltiVec regs. */
9880
9881static int
9882first_altivec_reg_to_save ()
9883{
9884 int i;
9885
9886 /* Stack frame remains as is unless we are in AltiVec ABI. */
9887 if (! TARGET_ALTIVEC_ABI)
9888 return LAST_ALTIVEC_REGNO + 1;
9889
9890 /* Find lowest numbered live register. */
9891 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
9892 if (regs_ever_live[i])
9893 break;
9894
9895 return i;
9896}
9897
9898/* Return a 32-bit mask of the AltiVec registers we need to set in
9899 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
9900 the 32-bit word is 0. */
9901
9902static unsigned int
9903compute_vrsave_mask ()
9904{
9905 unsigned int i, mask = 0;
9906
9907 /* First, find out if we use _any_ altivec registers. */
9908 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9909 if (regs_ever_live[i])
9910 mask |= ALTIVEC_REG_BIT (i);
9911
9912 if (mask == 0)
9913 return mask;
9914
00b960c7
AH
9915 /* Next, remove the argument registers from the set. These must
9916 be in the VRSAVE mask set by the caller, so we don't need to add
9917 them in again. More importantly, the mask we compute here is
9918 used to generate CLOBBERs in the set_vrsave insn, and we do not
9919 wish the argument registers to die. */
9920 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
9921 mask &= ~ALTIVEC_REG_BIT (i);
9922
9923 /* Similarly, remove the return value from the set. */
9924 {
9925 bool yes = false;
9926 diddle_return_value (is_altivec_return_reg, &yes);
9927 if (yes)
9928 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
9929 }
9930
9931 return mask;
9932}
9933
9934static void
9935is_altivec_return_reg (reg, xyes)
9936 rtx reg;
9937 void *xyes;
9938{
9939 bool *yes = (bool *) xyes;
9940 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
9941 *yes = true;
9942}
9943
4697a36c
MM
9944\f
9945/* Calculate the stack information for the current function. This is
9946 complicated by having two separate calling sequences, the AIX calling
9947 sequence and the V.4 calling sequence.
9948
592696dd 9949 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 9950 32-bit 64-bit
4697a36c 9951 SP----> +---------------------------------------+
a260abc9 9952 | back chain to caller | 0 0
4697a36c 9953 +---------------------------------------+
a260abc9 9954 | saved CR | 4 8 (8-11)
4697a36c 9955 +---------------------------------------+
a260abc9 9956 | saved LR | 8 16
4697a36c 9957 +---------------------------------------+
a260abc9 9958 | reserved for compilers | 12 24
4697a36c 9959 +---------------------------------------+
a260abc9 9960 | reserved for binders | 16 32
4697a36c 9961 +---------------------------------------+
a260abc9 9962 | saved TOC pointer | 20 40
4697a36c 9963 +---------------------------------------+
a260abc9 9964 | Parameter save area (P) | 24 48
4697a36c 9965 +---------------------------------------+
a260abc9 9966 | Alloca space (A) | 24+P etc.
802a0058 9967 +---------------------------------------+
a7df97e6 9968 | Local variable space (L) | 24+P+A
4697a36c 9969 +---------------------------------------+
a7df97e6 9970 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 9971 +---------------------------------------+
00b960c7
AH
9972 | Save area for AltiVec registers (W) | 24+P+A+L+X
9973 +---------------------------------------+
9974 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
9975 +---------------------------------------+
9976 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 9977 +---------------------------------------+
00b960c7
AH
9978 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
9979 +---------------------------------------+
9980 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
9981 +---------------------------------------+
9982 old SP->| back chain to caller's caller |
9983 +---------------------------------------+
9984
5376a30c
KR
9985 The required alignment for AIX configurations is two words (i.e., 8
9986 or 16 bytes).
9987
9988
4697a36c
MM
9989 V.4 stack frames look like:
9990
9991 SP----> +---------------------------------------+
9992 | back chain to caller | 0
9993 +---------------------------------------+
5eb387b8 9994 | caller's saved LR | 4
4697a36c
MM
9995 +---------------------------------------+
9996 | Parameter save area (P) | 8
9997 +---------------------------------------+
a7df97e6
MM
9998 | Alloca space (A) | 8+P
9999 +---------------------------------------+
10000 | Varargs save area (V) | 8+P+A
10001 +---------------------------------------+
10002 | Local variable space (L) | 8+P+A+V
10003 +---------------------------------------+
10004 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10005 +---------------------------------------+
00b960c7
AH
10006 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10007 +---------------------------------------+
10008 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10009 +---------------------------------------+
10010 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10011 +---------------------------------------+
a3170dc6
AH
10012 | SPE: area for 64-bit GP registers |
10013 +---------------------------------------+
10014 | SPE alignment padding |
10015 +---------------------------------------+
00b960c7 10016 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10017 +---------------------------------------+
00b960c7 10018 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10019 +---------------------------------------+
00b960c7 10020 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10021 +---------------------------------------+
10022 old SP->| back chain to caller's caller |
10023 +---------------------------------------+
b6c9286a 10024
5376a30c
KR
10025 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10026 given. (But note below and in sysv4.h that we require only 8 and
10027 may round up the size of our stack frame anyways. The historical
10028 reason is early versions of powerpc-linux which didn't properly
10029 align the stack at program startup. A happy side-effect is that
10030 -mno-eabi libraries can be used with -meabi programs.)
10031
50d440bc 10032 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10033 the stack alignment requirements may differ. If -mno-eabi is not
10034 given, the required stack alignment is 8 bytes; if -mno-eabi is
10035 given, the required alignment is 16 bytes. (But see V.4 comment
10036 above.) */
4697a36c 10037
61b2fbe7
MM
10038#ifndef ABI_STACK_BOUNDARY
10039#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10040#endif
10041
4697a36c
MM
10042rs6000_stack_t *
10043rs6000_stack_info ()
10044{
10045 static rs6000_stack_t info, zero_info;
10046 rs6000_stack_t *info_ptr = &info;
9ebbca7d 10047 int reg_size = TARGET_POWERPC64 ? 8 : 4;
83720594 10048 int ehrd_size;
b6c9286a 10049 int total_raw_size;
4697a36c 10050
a4f6c312 10051 /* Zero all fields portably. */
4697a36c
MM
10052 info = zero_info;
10053
c19de7aa
AH
10054 if (TARGET_SPE)
10055 {
10056 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10057 if (cfun->machine->insn_chain_scanned_p == 0)
10058 {
10059 cfun->machine->insn_chain_scanned_p = 1;
10060 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10061 }
c19de7aa
AH
10062 }
10063
a4f6c312 10064 /* Select which calling sequence. */
178274da 10065 info_ptr->abi = DEFAULT_ABI;
9878760c 10066
a4f6c312 10067 /* Calculate which registers need to be saved & save area size. */
4697a36c 10068 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10069 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10070 even if it currently looks like we won't. */
2bfcf297 10071 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10072 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10073 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10074 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10075 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10076 else
10077 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10078
a3170dc6
AH
10079 /* For the SPE, we have an additional upper 32-bits on each GPR.
10080 Ideally we should save the entire 64-bits only when the upper
10081 half is used in SIMD instructions. Since we only record
10082 registers live (not the size they are used in), this proves
10083 difficult because we'd have to traverse the instruction chain at
10084 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10085 so we opt to save the GPRs in 64-bits always if but one register
10086 gets used in 64-bits. Otherwise, all the registers in the frame
10087 get saved in 32-bits.
a3170dc6 10088
c19de7aa 10089 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10090 traditional GP save area will be empty. */
c19de7aa 10091 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10092 info_ptr->gp_size = 0;
10093
4697a36c
MM
10094 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10095 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10096
00b960c7
AH
10097 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10098 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10099 - info_ptr->first_altivec_reg_save);
10100
592696dd 10101 /* Does this function call anything? */
71f123ca
FS
10102 info_ptr->calls_p = (! current_function_is_leaf
10103 || cfun->machine->ra_needs_full_frame);
b6c9286a 10104
a4f6c312 10105 /* Determine if we need to save the link register. */
71f123ca 10106 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10107 || (DEFAULT_ABI == ABI_AIX
10108 && current_function_profile
10109 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10110#ifdef TARGET_RELOCATABLE
10111 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10112#endif
10113 || (info_ptr->first_fp_reg_save != 64
10114 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10115 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10116 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10117 || (DEFAULT_ABI == ABI_DARWIN
10118 && flag_pic
10119 && current_function_uses_pic_offset_table)
4697a36c
MM
10120 || info_ptr->calls_p)
10121 {
10122 info_ptr->lr_save_p = 1;
9ebbca7d 10123 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10124 }
10125
9ebbca7d
GK
10126 /* Determine if we need to save the condition code registers. */
10127 if (regs_ever_live[CR2_REGNO]
10128 || regs_ever_live[CR3_REGNO]
10129 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10130 {
10131 info_ptr->cr_save_p = 1;
178274da 10132 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10133 info_ptr->cr_size = reg_size;
10134 }
10135
83720594
RH
10136 /* If the current function calls __builtin_eh_return, then we need
10137 to allocate stack space for registers that will hold data for
10138 the exception handler. */
10139 if (current_function_calls_eh_return)
10140 {
10141 unsigned int i;
10142 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10143 continue;
a3170dc6
AH
10144
10145 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10146 ehrd_size = i * (TARGET_SPE_ABI
10147 && info_ptr->spe_64bit_regs_used != 0
10148 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10149 }
10150 else
10151 ehrd_size = 0;
10152
592696dd 10153 /* Determine various sizes. */
4697a36c
MM
10154 info_ptr->reg_size = reg_size;
10155 info_ptr->fixed_size = RS6000_SAVE_AREA;
10156 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10157 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
10158 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
10159 8);
00b960c7 10160
c19de7aa 10161 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10162 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10163 else
10164 info_ptr->spe_gp_size = 0;
10165
08b57fb3 10166 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE)
00b960c7
AH
10167 {
10168 info_ptr->vrsave_mask = compute_vrsave_mask ();
10169 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
10170 }
10171 else
10172 {
10173 info_ptr->vrsave_mask = 0;
10174 info_ptr->vrsave_size = 0;
10175 }
b6c9286a 10176
592696dd 10177 /* Calculate the offsets. */
178274da 10178 switch (DEFAULT_ABI)
4697a36c 10179 {
b6c9286a 10180 case ABI_NONE:
24d304eb 10181 default:
b6c9286a
MM
10182 abort ();
10183
10184 case ABI_AIX:
ee890fe2 10185 case ABI_DARWIN:
b6c9286a
MM
10186 info_ptr->fp_save_offset = - info_ptr->fp_size;
10187 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10188
10189 if (TARGET_ALTIVEC_ABI)
10190 {
10191 info_ptr->vrsave_save_offset
10192 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10193
10194 /* Align stack so vector save area is on a quadword boundary. */
10195 if (info_ptr->altivec_size != 0)
10196 info_ptr->altivec_padding_size
10197 = 16 - (-info_ptr->vrsave_save_offset % 16);
10198 else
10199 info_ptr->altivec_padding_size = 0;
10200
10201 info_ptr->altivec_save_offset
10202 = info_ptr->vrsave_save_offset
10203 - info_ptr->altivec_padding_size
10204 - info_ptr->altivec_size;
10205
10206 /* Adjust for AltiVec case. */
10207 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10208 }
10209 else
10210 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10211 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10212 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10213 break;
10214
10215 case ABI_V4:
b6c9286a
MM
10216 info_ptr->fp_save_offset = - info_ptr->fp_size;
10217 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10218 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10219
c19de7aa 10220 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10221 {
10222 /* Align stack so SPE GPR save area is aligned on a
10223 double-word boundary. */
10224 if (info_ptr->spe_gp_size != 0)
10225 info_ptr->spe_padding_size
10226 = 8 - (-info_ptr->cr_save_offset % 8);
10227 else
10228 info_ptr->spe_padding_size = 0;
10229
10230 info_ptr->spe_gp_save_offset
10231 = info_ptr->cr_save_offset
10232 - info_ptr->spe_padding_size
10233 - info_ptr->spe_gp_size;
10234
10235 /* Adjust for SPE case. */
10236 info_ptr->toc_save_offset
10237 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10238 }
10239 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10240 {
10241 info_ptr->vrsave_save_offset
10242 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10243
10244 /* Align stack so vector save area is on a quadword boundary. */
10245 if (info_ptr->altivec_size != 0)
10246 info_ptr->altivec_padding_size
10247 = 16 - (-info_ptr->vrsave_save_offset % 16);
10248 else
10249 info_ptr->altivec_padding_size = 0;
10250
10251 info_ptr->altivec_save_offset
10252 = info_ptr->vrsave_save_offset
10253 - info_ptr->altivec_padding_size
10254 - info_ptr->altivec_size;
10255
10256 /* Adjust for AltiVec case. */
10257 info_ptr->toc_save_offset
10258 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10259 }
10260 else
10261 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10262 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10263 info_ptr->lr_save_offset = reg_size;
10264 break;
4697a36c
MM
10265 }
10266
00b960c7
AH
10267 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10268 + info_ptr->gp_size
10269 + info_ptr->altivec_size
10270 + info_ptr->altivec_padding_size
a3170dc6
AH
10271 + info_ptr->spe_gp_size
10272 + info_ptr->spe_padding_size
00b960c7
AH
10273 + ehrd_size
10274 + info_ptr->cr_size
10275 + info_ptr->lr_size
10276 + info_ptr->vrsave_size
10277 + info_ptr->toc_size,
10278 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10279 ? 16 : 8);
10280
ff381587
MM
10281 total_raw_size = (info_ptr->vars_size
10282 + info_ptr->parm_size
ff381587
MM
10283 + info_ptr->save_size
10284 + info_ptr->varargs_size
10285 + info_ptr->fixed_size);
10286
a4f6c312
SS
10287 info_ptr->total_size =
10288 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10289
10290 /* Determine if we need to allocate any stack frame:
10291
a4f6c312
SS
10292 For AIX we need to push the stack if a frame pointer is needed
10293 (because the stack might be dynamically adjusted), if we are
10294 debugging, if we make calls, or if the sum of fp_save, gp_save,
10295 and local variables are more than the space needed to save all
10296 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10297 + 18*8 = 288 (GPR13 reserved).
ff381587 10298
a4f6c312
SS
10299 For V.4 we don't have the stack cushion that AIX uses, but assume
10300 that the debugger can handle stackless frames. */
ff381587
MM
10301
10302 if (info_ptr->calls_p)
10303 info_ptr->push_p = 1;
10304
178274da 10305 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10306 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10307
178274da
AM
10308 else if (frame_pointer_needed)
10309 info_ptr->push_p = 1;
10310
10311 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10312 info_ptr->push_p = 1;
10313
ff381587 10314 else
178274da
AM
10315 info_ptr->push_p
10316 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10317
a4f6c312 10318 /* Zero offsets if we're not saving those registers. */
8dda1a21 10319 if (info_ptr->fp_size == 0)
4697a36c
MM
10320 info_ptr->fp_save_offset = 0;
10321
8dda1a21 10322 if (info_ptr->gp_size == 0)
4697a36c
MM
10323 info_ptr->gp_save_offset = 0;
10324
00b960c7
AH
10325 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10326 info_ptr->altivec_save_offset = 0;
10327
10328 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10329 info_ptr->vrsave_save_offset = 0;
10330
c19de7aa
AH
10331 if (! TARGET_SPE_ABI
10332 || info_ptr->spe_64bit_regs_used == 0
10333 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10334 info_ptr->spe_gp_save_offset = 0;
10335
c81fc13e 10336 if (! info_ptr->lr_save_p)
4697a36c
MM
10337 info_ptr->lr_save_offset = 0;
10338
c81fc13e 10339 if (! info_ptr->cr_save_p)
4697a36c
MM
10340 info_ptr->cr_save_offset = 0;
10341
c81fc13e 10342 if (! info_ptr->toc_save_p)
b6c9286a
MM
10343 info_ptr->toc_save_offset = 0;
10344
4697a36c
MM
10345 return info_ptr;
10346}
10347
c19de7aa
AH
10348/* Return true if the current function uses any GPRs in 64-bit SIMD
10349 mode. */
10350
10351static bool
10352spe_func_has_64bit_regs_p ()
10353{
10354 rtx insns, insn;
10355
10356 /* Functions that save and restore all the call-saved registers will
10357 need to save/restore the registers in 64-bits. */
10358 if (current_function_calls_eh_return
10359 || current_function_calls_setjmp
10360 || current_function_has_nonlocal_goto)
10361 return true;
10362
10363 insns = get_insns ();
10364
10365 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
10366 {
10367 if (INSN_P (insn))
10368 {
10369 rtx i;
10370
10371 i = PATTERN (insn);
10372 if (GET_CODE (i) == SET
10373 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
10374 return true;
10375 }
10376 }
10377
10378 return false;
10379}
10380
4697a36c
MM
10381void
10382debug_stack_info (info)
10383 rs6000_stack_t *info;
9878760c 10384{
d330fd93 10385 const char *abi_string;
24d304eb 10386
c81fc13e 10387 if (! info)
4697a36c
MM
10388 info = rs6000_stack_info ();
10389
10390 fprintf (stderr, "\nStack information for function %s:\n",
10391 ((current_function_decl && DECL_NAME (current_function_decl))
10392 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
10393 : "<unknown>"));
10394
24d304eb
RK
10395 switch (info->abi)
10396 {
b6c9286a
MM
10397 default: abi_string = "Unknown"; break;
10398 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 10399 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 10400 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 10401 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
10402 }
10403
10404 fprintf (stderr, "\tABI = %5s\n", abi_string);
10405
00b960c7
AH
10406 if (TARGET_ALTIVEC_ABI)
10407 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
10408
a3170dc6
AH
10409 if (TARGET_SPE_ABI)
10410 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
10411
4697a36c
MM
10412 if (info->first_gp_reg_save != 32)
10413 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
10414
10415 if (info->first_fp_reg_save != 64)
10416 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 10417
00b960c7
AH
10418 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
10419 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
10420 info->first_altivec_reg_save);
10421
4697a36c
MM
10422 if (info->lr_save_p)
10423 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 10424
4697a36c
MM
10425 if (info->cr_save_p)
10426 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
10427
b6c9286a
MM
10428 if (info->toc_save_p)
10429 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
10430
00b960c7
AH
10431 if (info->vrsave_mask)
10432 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
10433
4697a36c
MM
10434 if (info->push_p)
10435 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
10436
10437 if (info->calls_p)
10438 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
10439
4697a36c
MM
10440 if (info->gp_save_offset)
10441 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
10442
10443 if (info->fp_save_offset)
10444 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
10445
00b960c7
AH
10446 if (info->altivec_save_offset)
10447 fprintf (stderr, "\taltivec_save_offset = %5d\n",
10448 info->altivec_save_offset);
10449
a3170dc6
AH
10450 if (info->spe_gp_save_offset)
10451 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
10452 info->spe_gp_save_offset);
10453
00b960c7
AH
10454 if (info->vrsave_save_offset)
10455 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
10456 info->vrsave_save_offset);
10457
4697a36c
MM
10458 if (info->lr_save_offset)
10459 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
10460
10461 if (info->cr_save_offset)
10462 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
10463
b6c9286a
MM
10464 if (info->toc_save_offset)
10465 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
10466
4697a36c
MM
10467 if (info->varargs_save_offset)
10468 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
10469
10470 if (info->total_size)
10471 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
10472
10473 if (info->varargs_size)
10474 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
10475
10476 if (info->vars_size)
10477 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
10478
10479 if (info->parm_size)
10480 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
10481
10482 if (info->fixed_size)
10483 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
10484
10485 if (info->gp_size)
10486 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
10487
a3170dc6
AH
10488 if (info->spe_gp_size)
10489 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
10490
4697a36c
MM
10491 if (info->fp_size)
10492 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
10493
00b960c7
AH
10494 if (info->altivec_size)
10495 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
10496
10497 if (info->vrsave_size)
10498 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
10499
10500 if (info->altivec_padding_size)
10501 fprintf (stderr, "\taltivec_padding_size= %5d\n",
10502 info->altivec_padding_size);
10503
a3170dc6
AH
10504 if (info->spe_padding_size)
10505 fprintf (stderr, "\tspe_padding_size = %5d\n",
10506 info->spe_padding_size);
10507
a4f6c312 10508 if (info->lr_size)
ed947a96 10509 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 10510
4697a36c
MM
10511 if (info->cr_size)
10512 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
10513
a4f6c312 10514 if (info->toc_size)
b6c9286a
MM
10515 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
10516
4697a36c
MM
10517 if (info->save_size)
10518 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
10519
10520 if (info->reg_size != 4)
10521 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
10522
10523 fprintf (stderr, "\n");
9878760c 10524}
71f123ca
FS
10525
10526rtx
10527rs6000_return_addr (count, frame)
10528 int count;
10529 rtx frame;
10530{
a4f6c312
SS
10531 /* Currently we don't optimize very well between prolog and body
10532 code and for PIC code the code can be actually quite bad, so
10533 don't try to be too clever here. */
f1384257 10534 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
10535 {
10536 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
10537
10538 return
10539 gen_rtx_MEM
10540 (Pmode,
10541 memory_address
10542 (Pmode,
10543 plus_constant (copy_to_reg
10544 (gen_rtx_MEM (Pmode,
10545 memory_address (Pmode, frame))),
10546 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
10547 }
10548
8c29550d 10549 cfun->machine->ra_need_lr = 1;
9e2f7ec7 10550 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
10551}
10552
5e1bf043
DJ
10553/* Say whether a function is a candidate for sibcall handling or not.
10554 We do not allow indirect calls to be optimized into sibling calls.
10555 Also, we can't do it if there are any vector parameters; there's
10556 nowhere to put the VRsave code so it works; note that functions with
10557 vector parameters are required to have a prototype, so the argument
10558 type info must be available here. (The tail recursion case can work
10559 with vector parameters, but there's no way to distinguish here.) */
4977bab6
ZW
10560static bool
10561rs6000_function_ok_for_sibcall (decl, exp)
10562 tree decl;
10563 tree exp ATTRIBUTE_UNUSED;
5e1bf043
DJ
10564{
10565 tree type;
4977bab6 10566 if (decl)
5e1bf043
DJ
10567 {
10568 if (TARGET_ALTIVEC_VRSAVE)
10569 {
4977bab6 10570 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
10571 type; type = TREE_CHAIN (type))
10572 {
c15b529f 10573 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 10574 return false;
5e1bf043
DJ
10575 }
10576 }
10577 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 10578 || (*targetm.binds_local_p) (decl))
2bcc50d0 10579 {
4977bab6 10580 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
10581
10582 if (!lookup_attribute ("longcall", attr_list)
10583 || lookup_attribute ("shortcall", attr_list))
4977bab6 10584 return true;
2bcc50d0 10585 }
5e1bf043 10586 }
4977bab6 10587 return false;
5e1bf043
DJ
10588}
10589
71f123ca
FS
10590static int
10591rs6000_ra_ever_killed ()
10592{
10593 rtx top;
5e1bf043
DJ
10594 rtx reg;
10595 rtx insn;
71f123ca 10596
3961e8fe
RH
10597 /* Irritatingly, there are two kinds of thunks -- those created with
10598 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
10599 through the regular part of the compiler. This is a very hacky
10600 way to tell them apart. */
10601 if (current_function_is_thunk && !no_new_pseudos)
71f123ca 10602 return 0;
eb0424da 10603
36f7e964
AH
10604 /* regs_ever_live has LR marked as used if any sibcalls are present,
10605 but this should not force saving and restoring in the
10606 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
10607 clobbers LR, so that is inappropriate. */
10608
5e1bf043
DJ
10609 /* Also, the prologue can generate a store into LR that
10610 doesn't really count, like this:
36f7e964 10611
5e1bf043
DJ
10612 move LR->R0
10613 bcl to set PIC register
10614 move LR->R31
10615 move R0->LR
36f7e964
AH
10616
10617 When we're called from the epilogue, we need to avoid counting
10618 this as a store. */
5e1bf043 10619
71f123ca
FS
10620 push_topmost_sequence ();
10621 top = get_insns ();
10622 pop_topmost_sequence ();
5e1bf043 10623 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 10624
5e1bf043
DJ
10625 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
10626 {
10627 if (INSN_P (insn))
10628 {
10629 if (FIND_REG_INC_NOTE (insn, reg))
10630 return 1;
10631 else if (GET_CODE (insn) == CALL_INSN
c15b529f 10632 && !SIBLING_CALL_P (insn))
5e1bf043 10633 return 1;
36f7e964
AH
10634 else if (set_of (reg, insn) != NULL_RTX
10635 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
10636 return 1;
10637 }
10638 }
10639 return 0;
71f123ca 10640}
4697a36c 10641\f
8cd8f856
GK
10642/* Add a REG_MAYBE_DEAD note to the insn. */
10643static void
10644rs6000_maybe_dead (insn)
10645 rtx insn;
10646{
10647 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
10648 const0_rtx,
10649 REG_NOTES (insn));
10650}
10651
9ebbca7d 10652/* Emit instructions needed to load the TOC register.
c7ca610e 10653 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 10654 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
10655
10656void
9ebbca7d
GK
10657rs6000_emit_load_toc_table (fromprolog)
10658 int fromprolog;
c7ca610e 10659{
027fbf43 10660 rtx dest, insn;
1db02437 10661 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 10662
20b71b17
AM
10663 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10664 {
10665 rtx temp = (fromprolog
10666 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
10667 : gen_reg_rtx (Pmode));
027fbf43
JJ
10668 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
10669 if (fromprolog)
10670 rs6000_maybe_dead (insn);
10671 insn = emit_move_insn (dest, temp);
10672 if (fromprolog)
10673 rs6000_maybe_dead (insn);
20b71b17
AM
10674 }
10675 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
10676 {
10677 char buf[30];
10678 rtx tempLR = (fromprolog
10679 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
10680 : gen_reg_rtx (Pmode));
10681 rtx temp0 = (fromprolog
10682 ? gen_rtx_REG (Pmode, 0)
10683 : gen_reg_rtx (Pmode));
10684 rtx symF;
10685
10686 /* possibly create the toc section */
10687 if (! toc_initialized)
38c1f2d7 10688 {
20b71b17
AM
10689 toc_section ();
10690 function_section (current_function_decl);
38c1f2d7 10691 }
9ebbca7d 10692
20b71b17
AM
10693 if (fromprolog)
10694 {
10695 rtx symL;
38c1f2d7 10696
20b71b17
AM
10697 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
10698 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 10699
20b71b17
AM
10700 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
10701 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10702
10703 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
10704 symF)));
10705 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
10706 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
10707 symL,
10708 symF)));
9ebbca7d
GK
10709 }
10710 else
20b71b17
AM
10711 {
10712 rtx tocsym;
10713 static int reload_toc_labelno = 0;
10714
10715 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
10716
10717 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
10718 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10719
027fbf43
JJ
10720 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
10721 emit_move_insn (dest, tempLR);
10722 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 10723 }
027fbf43
JJ
10724 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
10725 if (fromprolog)
10726 rs6000_maybe_dead (insn);
9ebbca7d 10727 }
20b71b17
AM
10728 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
10729 {
10730 /* This is for AIX code running in non-PIC ELF32. */
10731 char buf[30];
10732 rtx realsym;
10733 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
10734 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10735
027fbf43
JJ
10736 insn = emit_insn (gen_elf_high (dest, realsym));
10737 if (fromprolog)
10738 rs6000_maybe_dead (insn);
10739 insn = emit_insn (gen_elf_low (dest, dest, realsym));
10740 if (fromprolog)
10741 rs6000_maybe_dead (insn);
20b71b17
AM
10742 }
10743 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
10744 {
10745 if (TARGET_32BIT)
027fbf43 10746 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 10747 else
027fbf43
JJ
10748 insn = emit_insn (gen_load_toc_aix_di (dest));
10749 if (fromprolog)
10750 rs6000_maybe_dead (insn);
9ebbca7d 10751 }
20b71b17
AM
10752 else
10753 abort ();
9ebbca7d
GK
10754}
10755
10756int
10757get_TOC_alias_set ()
10758{
10759 static int set = -1;
10760 if (set == -1)
10761 set = new_alias_set ();
10762 return set;
10763}
10764
c1207243 10765/* This returns nonzero if the current function uses the TOC. This is
c4501e62
JJ
10766 determined by the presence of (unspec ... UNSPEC_TOC) or
10767 use (unspec ... UNSPEC_TOC), which are generated by the various
10768 load_toc_* patterns. */
a4f6c312 10769
9ebbca7d
GK
10770int
10771uses_TOC ()
10772{
c4501e62 10773 rtx insn;
38c1f2d7 10774
c4501e62
JJ
10775 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
10776 if (INSN_P (insn))
10777 {
10778 rtx pat = PATTERN (insn);
10779 int i;
9ebbca7d 10780
c4501e62
JJ
10781 if (GET_CODE (pat) == PARALLEL)
10782 for (i = 0; i < XVECLEN (pat, 0); i++)
10783 {
10784 rtx sub = XVECEXP (pat, 0, i);
10785 if (GET_CODE (sub) == USE)
10786 {
10787 sub = XEXP (sub, 0);
10788 if (GET_CODE (sub) == UNSPEC
10789 && XINT (sub, 1) == UNSPEC_TOC)
10790 return 1;
10791 }
10792 }
10793 }
10794 return 0;
9ebbca7d 10795}
38c1f2d7 10796
9ebbca7d 10797rtx
a4f6c312 10798create_TOC_reference (symbol)
9ebbca7d
GK
10799 rtx symbol;
10800{
a8a05998
ZW
10801 return gen_rtx_PLUS (Pmode,
10802 gen_rtx_REG (Pmode, TOC_REGISTER),
10803 gen_rtx_CONST (Pmode,
10804 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 10805 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 10806}
38c1f2d7 10807
fc4767bb
JJ
10808/* If _Unwind_* has been called from within the same module,
10809 toc register is not guaranteed to be saved to 40(1) on function
10810 entry. Save it there in that case. */
c7ca610e 10811
9ebbca7d
GK
10812void
10813rs6000_aix_emit_builtin_unwind_init ()
10814{
10815 rtx mem;
10816 rtx stack_top = gen_reg_rtx (Pmode);
10817 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
10818 rtx opcode = gen_reg_rtx (SImode);
10819 rtx tocompare = gen_reg_rtx (SImode);
10820 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
10821
10822 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
10823 emit_move_insn (stack_top, mem);
10824
fc4767bb
JJ
10825 mem = gen_rtx_MEM (Pmode,
10826 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
10827 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
10828 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
10829 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
10830 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 10831 : 0xE8410028, SImode));
9ebbca7d 10832
fc4767bb 10833 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 10834 SImode, NULL_RTX, NULL_RTX,
fc4767bb 10835 no_toc_save_needed);
9ebbca7d 10836
fc4767bb
JJ
10837 mem = gen_rtx_MEM (Pmode,
10838 gen_rtx_PLUS (Pmode, stack_top,
10839 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
10840 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
10841 emit_label (no_toc_save_needed);
9ebbca7d 10842}
38c1f2d7 10843\f
ba4828e0
RK
10844/* This ties together stack memory (MEM with an alias set of
10845 rs6000_sr_alias_set) and the change to the stack pointer. */
10846
9ebbca7d
GK
10847static void
10848rs6000_emit_stack_tie ()
10849{
ba4828e0
RK
10850 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
10851
10852 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10853 emit_insn (gen_stack_tie (mem));
10854}
38c1f2d7 10855
9ebbca7d
GK
10856/* Emit the correct code for allocating stack space, as insns.
10857 If COPY_R12, make sure a copy of the old frame is left in r12.
10858 The generated code may use hard register 0 as a temporary. */
10859
10860static void
10861rs6000_emit_allocate_stack (size, copy_r12)
10862 HOST_WIDE_INT size;
38c1f2d7
MM
10863 int copy_r12;
10864{
9ebbca7d
GK
10865 rtx insn;
10866 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10867 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
10868 rtx todec = GEN_INT (-size);
a157febd
GK
10869
10870 if (current_function_limit_stack)
10871 {
10872 if (REG_P (stack_limit_rtx)
10873 && REGNO (stack_limit_rtx) > 1
10874 && REGNO (stack_limit_rtx) <= 31)
10875 {
5b71a4e7 10876 emit_insn (TARGET_32BIT
9ebbca7d
GK
10877 ? gen_addsi3 (tmp_reg,
10878 stack_limit_rtx,
10879 GEN_INT (size))
10880 : gen_adddi3 (tmp_reg,
10881 stack_limit_rtx,
10882 GEN_INT (size)));
5b71a4e7 10883
9ebbca7d
GK
10884 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10885 const0_rtx));
a157febd
GK
10886 }
10887 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 10888 && TARGET_32BIT
f607bc57 10889 && DEFAULT_ABI == ABI_V4)
a157febd 10890 {
9ebbca7d
GK
10891 rtx toload = gen_rtx_CONST (VOIDmode,
10892 gen_rtx_PLUS (Pmode,
10893 stack_limit_rtx,
10894 GEN_INT (size)));
5b71a4e7 10895
9ebbca7d
GK
10896 emit_insn (gen_elf_high (tmp_reg, toload));
10897 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
10898 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10899 const0_rtx));
a157febd
GK
10900 }
10901 else
10902 warning ("stack limit expression is not supported");
10903 }
10904
9ebbca7d
GK
10905 if (copy_r12 || ! TARGET_UPDATE)
10906 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
10907
38c1f2d7
MM
10908 if (TARGET_UPDATE)
10909 {
9ebbca7d 10910 if (size > 32767)
38c1f2d7 10911 {
9ebbca7d
GK
10912 /* Need a note here so that try_split doesn't get confused. */
10913 if (get_last_insn() == NULL_RTX)
2e040219 10914 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
10915 insn = emit_move_insn (tmp_reg, todec);
10916 try_split (PATTERN (insn), insn, 0);
10917 todec = tmp_reg;
38c1f2d7 10918 }
5b71a4e7
DE
10919
10920 insn = emit_insn (TARGET_32BIT
10921 ? gen_movsi_update (stack_reg, stack_reg,
10922 todec, stack_reg)
10923 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 10924 todec, stack_reg));
38c1f2d7
MM
10925 }
10926 else
10927 {
5b71a4e7
DE
10928 insn = emit_insn (TARGET_32BIT
10929 ? gen_addsi3 (stack_reg, stack_reg, todec)
10930 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
10931 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
10932 gen_rtx_REG (Pmode, 12));
10933 }
5b71a4e7 10934
9ebbca7d
GK
10935 RTX_FRAME_RELATED_P (insn) = 1;
10936 REG_NOTES (insn) =
10937 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10938 gen_rtx_SET (VOIDmode, stack_reg,
10939 gen_rtx_PLUS (Pmode, stack_reg,
10940 GEN_INT (-size))),
10941 REG_NOTES (insn));
10942}
10943
a4f6c312
SS
10944/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
10945 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
10946 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
10947 deduce these equivalences by itself so it wasn't necessary to hold
10948 its hand so much. */
9ebbca7d
GK
10949
10950static void
10951rs6000_frame_related (insn, reg, val, reg2, rreg)
10952 rtx insn;
10953 rtx reg;
10954 HOST_WIDE_INT val;
10955 rtx reg2;
10956 rtx rreg;
10957{
10958 rtx real, temp;
10959
e56c4463
JL
10960 /* copy_rtx will not make unique copies of registers, so we need to
10961 ensure we don't have unwanted sharing here. */
10962 if (reg == reg2)
10963 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10964
10965 if (reg == rreg)
10966 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10967
9ebbca7d
GK
10968 real = copy_rtx (PATTERN (insn));
10969
89e7058f
AH
10970 if (reg2 != NULL_RTX)
10971 real = replace_rtx (real, reg2, rreg);
10972
9ebbca7d
GK
10973 real = replace_rtx (real, reg,
10974 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
10975 STACK_POINTER_REGNUM),
10976 GEN_INT (val)));
10977
10978 /* We expect that 'real' is either a SET or a PARALLEL containing
10979 SETs (and possibly other stuff). In a PARALLEL, all the SETs
10980 are important so they all have to be marked RTX_FRAME_RELATED_P. */
10981
10982 if (GET_CODE (real) == SET)
10983 {
10984 rtx set = real;
10985
10986 temp = simplify_rtx (SET_SRC (set));
10987 if (temp)
10988 SET_SRC (set) = temp;
10989 temp = simplify_rtx (SET_DEST (set));
10990 if (temp)
10991 SET_DEST (set) = temp;
10992 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 10993 {
9ebbca7d
GK
10994 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10995 if (temp)
10996 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 10997 }
38c1f2d7 10998 }
9ebbca7d
GK
10999 else if (GET_CODE (real) == PARALLEL)
11000 {
11001 int i;
11002 for (i = 0; i < XVECLEN (real, 0); i++)
11003 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11004 {
11005 rtx set = XVECEXP (real, 0, i);
11006
11007 temp = simplify_rtx (SET_SRC (set));
11008 if (temp)
11009 SET_SRC (set) = temp;
11010 temp = simplify_rtx (SET_DEST (set));
11011 if (temp)
11012 SET_DEST (set) = temp;
11013 if (GET_CODE (SET_DEST (set)) == MEM)
11014 {
11015 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11016 if (temp)
11017 XEXP (SET_DEST (set), 0) = temp;
11018 }
11019 RTX_FRAME_RELATED_P (set) = 1;
11020 }
11021 }
11022 else
a4f6c312 11023 abort ();
c19de7aa
AH
11024
11025 if (TARGET_SPE)
11026 real = spe_synthesize_frame_save (real);
11027
9ebbca7d
GK
11028 RTX_FRAME_RELATED_P (insn) = 1;
11029 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11030 real,
11031 REG_NOTES (insn));
38c1f2d7
MM
11032}
11033
c19de7aa
AH
11034/* Given an SPE frame note, return a PARALLEL of SETs with the
11035 original note, plus a synthetic register save. */
11036
11037static rtx
11038spe_synthesize_frame_save (real)
11039 rtx real;
11040{
11041 rtx synth, offset, reg, real2;
11042
11043 if (GET_CODE (real) != SET
11044 || GET_MODE (SET_SRC (real)) != V2SImode)
11045 return real;
11046
11047 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11048 frame related note. The parallel contains a set of the register
41f3a930 11049 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11050 This is so we can differentiate between 64-bit and 32-bit saves.
11051 Words cannot describe this nastiness. */
11052
11053 if (GET_CODE (SET_DEST (real)) != MEM
11054 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11055 || GET_CODE (SET_SRC (real)) != REG)
11056 abort ();
11057
11058 /* Transform:
11059 (set (mem (plus (reg x) (const y)))
11060 (reg z))
11061 into:
11062 (set (mem (plus (reg x) (const y+4)))
41f3a930 11063 (reg z+1200))
c19de7aa
AH
11064 */
11065
11066 real2 = copy_rtx (real);
11067 PUT_MODE (SET_DEST (real2), SImode);
11068 reg = SET_SRC (real2);
11069 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11070 synth = copy_rtx (real2);
11071
11072 if (BYTES_BIG_ENDIAN)
11073 {
11074 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11075 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11076 }
11077
11078 reg = SET_SRC (synth);
41f3a930 11079
c19de7aa 11080 synth = replace_rtx (synth, reg,
41f3a930 11081 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11082
11083 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11084 synth = replace_rtx (synth, offset,
11085 GEN_INT (INTVAL (offset)
11086 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11087
11088 RTX_FRAME_RELATED_P (synth) = 1;
11089 RTX_FRAME_RELATED_P (real2) = 1;
11090 if (BYTES_BIG_ENDIAN)
11091 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11092 else
11093 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11094
11095 return real;
11096}
11097
00b960c7
AH
11098/* Returns an insn that has a vrsave set operation with the
11099 appropriate CLOBBERs. */
11100
11101static rtx
9aa86737 11102generate_set_vrsave (reg, info, epiloguep)
00b960c7
AH
11103 rtx reg;
11104 rs6000_stack_t *info;
9aa86737 11105 int epiloguep;
00b960c7
AH
11106{
11107 int nclobs, i;
11108 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11109 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11110
a004eb82
AH
11111 clobs[0]
11112 = gen_rtx_SET (VOIDmode,
11113 vrsave,
11114 gen_rtx_UNSPEC_VOLATILE (SImode,
11115 gen_rtvec (2, reg, vrsave),
11116 30));
00b960c7
AH
11117
11118 nclobs = 1;
11119
9aa86737
AH
11120 /* We need to clobber the registers in the mask so the scheduler
11121 does not move sets to VRSAVE before sets of AltiVec registers.
11122
11123 However, if the function receives nonlocal gotos, reload will set
11124 all call saved registers live. We will end up with:
11125
11126 (set (reg 999) (mem))
11127 (parallel [ (set (reg vrsave) (unspec blah))
11128 (clobber (reg 999))])
11129
11130 The clobber will cause the store into reg 999 to be dead, and
11131 flow will attempt to delete an epilogue insn. In this case, we
11132 need an unspec use/set of the register. */
00b960c7
AH
11133
11134 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11135 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11136 {
11137 if (!epiloguep || call_used_regs [i])
11138 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11139 gen_rtx_REG (V4SImode, i));
11140 else
11141 {
11142 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11143
11144 clobs[nclobs++]
a004eb82
AH
11145 = gen_rtx_SET (VOIDmode,
11146 reg,
11147 gen_rtx_UNSPEC (V4SImode,
11148 gen_rtvec (1, reg), 27));
9aa86737
AH
11149 }
11150 }
00b960c7
AH
11151
11152 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11153
11154 for (i = 0; i < nclobs; ++i)
11155 XVECEXP (insn, 0, i) = clobs[i];
11156
11157 return insn;
11158}
11159
89e7058f
AH
11160/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11161 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11162
11163static void
11164emit_frame_save (frame_reg, frame_ptr, mode, regno, offset, total_size)
11165 rtx frame_reg;
11166 rtx frame_ptr;
11167 enum machine_mode mode;
11168 unsigned int regno;
11169 int offset;
11170 int total_size;
11171{
11172 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11173 rtx replacea, replaceb;
11174
11175 int_rtx = GEN_INT (offset);
11176
11177 /* Some cases that need register indexed addressing. */
11178 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11179 || (TARGET_SPE_ABI
11180 && SPE_VECTOR_MODE (mode)
11181 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11182 {
11183 /* Whomever calls us must make sure r11 is available in the
11184 flow path of instructions in the prologue. */
11185 offset_rtx = gen_rtx_REG (Pmode, 11);
11186 emit_move_insn (offset_rtx, int_rtx);
11187
11188 replacea = offset_rtx;
11189 replaceb = int_rtx;
11190 }
11191 else
11192 {
11193 offset_rtx = int_rtx;
11194 replacea = NULL_RTX;
11195 replaceb = NULL_RTX;
11196 }
11197
11198 reg = gen_rtx_REG (mode, regno);
11199 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11200 mem = gen_rtx_MEM (mode, addr);
11201 set_mem_alias_set (mem, rs6000_sr_alias_set);
11202
11203 insn = emit_move_insn (mem, reg);
11204
11205 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11206}
11207
a3170dc6
AH
11208/* Emit an offset memory reference suitable for a frame store, while
11209 converting to a valid addressing mode. */
11210
11211static rtx
11212gen_frame_mem_offset (mode, reg, offset)
11213 enum machine_mode mode;
11214 rtx reg;
11215 int offset;
11216{
11217 rtx int_rtx, offset_rtx;
11218
11219 int_rtx = GEN_INT (offset);
11220
11221 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11222 {
11223 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11224 emit_move_insn (offset_rtx, int_rtx);
11225 }
11226 else
11227 offset_rtx = int_rtx;
11228
11229 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11230}
11231
9ebbca7d
GK
11232/* Emit function prologue as insns. */
11233
9878760c 11234void
83720594 11235rs6000_emit_prologue ()
9878760c 11236{
4697a36c 11237 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
11238 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
11239 int reg_size = TARGET_POWERPC64 ? 8 : 4;
11240 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11241 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11242 rtx frame_reg_rtx = sp_reg_rtx;
11243 rtx cr_save_rtx = NULL;
11244 rtx insn;
11245 int saving_FPRs_inline;
11246 int using_store_multiple;
11247 HOST_WIDE_INT sp_offset = 0;
11248
c19de7aa 11249 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11250 {
11251 reg_mode = V2SImode;
11252 reg_size = 8;
11253 }
11254
9ebbca7d 11255 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11256 && (!TARGET_SPE_ABI
11257 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11258 && info->first_gp_reg_save < 31);
11259 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11260 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11261 || current_function_calls_eh_return
8c29550d 11262 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11263
11264 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11265 if (info->push_p
acd0b319
AM
11266 && (DEFAULT_ABI == ABI_V4
11267 || current_function_calls_eh_return))
9ebbca7d
GK
11268 {
11269 if (info->total_size < 32767)
11270 sp_offset = info->total_size;
11271 else
11272 frame_reg_rtx = frame_ptr_rtx;
11273 rs6000_emit_allocate_stack (info->total_size,
11274 (frame_reg_rtx != sp_reg_rtx
11275 && (info->cr_save_p
11276 || info->lr_save_p
11277 || info->first_fp_reg_save < 64
11278 || info->first_gp_reg_save < 32
11279 )));
11280 if (frame_reg_rtx != sp_reg_rtx)
11281 rs6000_emit_stack_tie ();
11282 }
11283
9aa86737
AH
11284 /* Save AltiVec registers if needed. */
11285 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11286 {
11287 int i;
11288
11289 /* There should be a non inline version of this, for when we
11290 are saving lots of vector registers. */
11291 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11292 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11293 {
11294 rtx areg, savereg, mem;
11295 int offset;
11296
11297 offset = info->altivec_save_offset + sp_offset
11298 + 16 * (i - info->first_altivec_reg_save);
11299
11300 savereg = gen_rtx_REG (V4SImode, i);
11301
11302 areg = gen_rtx_REG (Pmode, 0);
11303 emit_move_insn (areg, GEN_INT (offset));
11304
11305 /* AltiVec addressing mode is [reg+reg]. */
11306 mem = gen_rtx_MEM (V4SImode,
11307 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11308
11309 set_mem_alias_set (mem, rs6000_sr_alias_set);
11310
11311 insn = emit_move_insn (mem, savereg);
11312
5c242421
SB
11313 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11314 areg, GEN_INT (offset));
9aa86737
AH
11315 }
11316 }
11317
11318 /* VRSAVE is a bit vector representing which AltiVec registers
11319 are used. The OS uses this to determine which vector
11320 registers to save on a context switch. We need to save
11321 VRSAVE on the stack frame, add whatever AltiVec registers we
11322 used in this function, and do the corresponding magic in the
11323 epilogue. */
11324
11325 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
11326 {
a004eb82 11327 rtx reg, mem, vrsave;
9aa86737
AH
11328 int offset;
11329
11330 /* Get VRSAVE onto a GPR. */
11331 reg = gen_rtx_REG (SImode, 12);
a004eb82 11332 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11333 if (TARGET_MACHO)
11334 emit_insn (gen_get_vrsave_internal (reg));
11335 else
11336 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11337
11338 /* Save VRSAVE. */
11339 offset = info->vrsave_save_offset + sp_offset;
11340 mem
11341 = gen_rtx_MEM (SImode,
11342 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
11343 set_mem_alias_set (mem, rs6000_sr_alias_set);
11344 insn = emit_move_insn (mem, reg);
11345
11346 /* Include the registers in the mask. */
11347 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
11348
11349 insn = emit_insn (generate_set_vrsave (reg, info, 0));
11350 }
11351
9ebbca7d
GK
11352 /* If we use the link register, get it into r0. */
11353 if (info->lr_save_p)
71f123ca 11354 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
11355 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11356
11357 /* If we need to save CR, put it into r12. */
11358 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
11359 {
11360 cr_save_rtx = gen_rtx_REG (SImode, 12);
11361 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11362 }
11363
a4f6c312
SS
11364 /* Do any required saving of fpr's. If only one or two to save, do
11365 it ourselves. Otherwise, call function. */
9ebbca7d
GK
11366 if (saving_FPRs_inline)
11367 {
11368 int i;
11369 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11370 if ((regs_ever_live[info->first_fp_reg_save+i]
11371 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
11372 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
11373 info->first_fp_reg_save + i,
11374 info->fp_save_offset + sp_offset + 8 * i,
11375 info->total_size);
9ebbca7d
GK
11376 }
11377 else if (info->first_fp_reg_save != 64)
11378 {
11379 int i;
11380 char rname[30];
520a57c8 11381 const char *alloc_rname;
9ebbca7d
GK
11382 rtvec p;
11383 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
11384
11385 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
11386 gen_rtx_REG (Pmode,
11387 LINK_REGISTER_REGNUM));
11388 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
11389 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 11390 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11391 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
11392 gen_rtx_SYMBOL_REF (Pmode,
11393 alloc_rname));
11394 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11395 {
11396 rtx addr, reg, mem;
11397 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
11398 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11399 GEN_INT (info->fp_save_offset
11400 + sp_offset + 8*i));
11401 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11402 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11403
11404 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
11405 }
11406 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11407 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11408 NULL_RTX, NULL_RTX);
11409 }
b6c9286a 11410
9ebbca7d
GK
11411 /* Save GPRs. This is done as a PARALLEL if we are using
11412 the store-multiple instructions. */
11413 if (using_store_multiple)
b6c9286a 11414 {
308c142a 11415 rtvec p;
9ebbca7d
GK
11416 int i;
11417 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
11418 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11419 {
11420 rtx addr, reg, mem;
11421 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11422 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11423 GEN_INT (info->gp_save_offset
11424 + sp_offset
11425 + reg_size * i));
11426 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11427 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11428
11429 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
11430 }
11431 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11432 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11433 NULL_RTX, NULL_RTX);
b6c9286a
MM
11434 }
11435 else
11436 {
9ebbca7d
GK
11437 int i;
11438 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11439 if ((regs_ever_live[info->first_gp_reg_save+i]
11440 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11441 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11442 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11443 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
11444 {
11445 rtx addr, reg, mem;
11446 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11447
c19de7aa 11448 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11449 {
11450 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11451 rtx b;
11452
11453 if (!SPE_CONST_OFFSET_OK (offset))
11454 {
11455 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11456 emit_move_insn (b, GEN_INT (offset));
11457 }
11458 else
11459 b = GEN_INT (offset);
11460
11461 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11462 mem = gen_rtx_MEM (V2SImode, addr);
11463 set_mem_alias_set (mem, rs6000_sr_alias_set);
11464 insn = emit_move_insn (mem, reg);
11465
11466 if (GET_CODE (b) == CONST_INT)
11467 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11468 NULL_RTX, NULL_RTX);
11469 else
11470 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11471 b, GEN_INT (offset));
11472 }
11473 else
11474 {
11475 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11476 GEN_INT (info->gp_save_offset
11477 + sp_offset
11478 + reg_size * i));
11479 mem = gen_rtx_MEM (reg_mode, addr);
11480 set_mem_alias_set (mem, rs6000_sr_alias_set);
11481
11482 insn = emit_move_insn (mem, reg);
11483 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11484 NULL_RTX, NULL_RTX);
11485 }
11486 }
9ebbca7d
GK
11487 }
11488
83720594
RH
11489 /* ??? There's no need to emit actual instructions here, but it's the
11490 easiest way to get the frame unwind information emitted. */
11491 if (current_function_calls_eh_return)
11492 {
78e1b90d
DE
11493 unsigned int i, regno;
11494
fc4767bb
JJ
11495 /* In AIX ABI we need to pretend we save r2 here. */
11496 if (TARGET_AIX)
11497 {
11498 rtx addr, reg, mem;
11499
11500 reg = gen_rtx_REG (reg_mode, 2);
11501 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11502 GEN_INT (sp_offset + 5 * reg_size));
11503 mem = gen_rtx_MEM (reg_mode, addr);
11504 set_mem_alias_set (mem, rs6000_sr_alias_set);
11505
11506 insn = emit_move_insn (mem, reg);
11507 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11508 NULL_RTX, NULL_RTX);
11509 PATTERN (insn) = gen_blockage ();
11510 }
11511
83720594
RH
11512 for (i = 0; ; ++i)
11513 {
83720594
RH
11514 regno = EH_RETURN_DATA_REGNO (i);
11515 if (regno == INVALID_REGNUM)
11516 break;
11517
89e7058f
AH
11518 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
11519 info->ehrd_offset + sp_offset
11520 + reg_size * (int) i,
11521 info->total_size);
83720594
RH
11522 }
11523 }
11524
9ebbca7d
GK
11525 /* Save lr if we used it. */
11526 if (info->lr_save_p)
11527 {
11528 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11529 GEN_INT (info->lr_save_offset + sp_offset));
11530 rtx reg = gen_rtx_REG (Pmode, 0);
11531 rtx mem = gen_rtx_MEM (Pmode, addr);
11532 /* This should not be of rs6000_sr_alias_set, because of
11533 __builtin_return_address. */
11534
11535 insn = emit_move_insn (mem, reg);
11536 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11537 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11538 }
11539
11540 /* Save CR if we use any that must be preserved. */
11541 if (info->cr_save_p)
11542 {
11543 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11544 GEN_INT (info->cr_save_offset + sp_offset));
11545 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11546
11547 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11548
11549 /* If r12 was used to hold the original sp, copy cr into r0 now
11550 that it's free. */
11551 if (REGNO (frame_reg_rtx) == 12)
11552 {
11553 cr_save_rtx = gen_rtx_REG (SImode, 0);
11554 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11555 }
11556 insn = emit_move_insn (mem, cr_save_rtx);
11557
11558 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
11559 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
11560 But that's OK. All we have to do is specify that _one_ condition
11561 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
11562 will then restore all the call-saved registers.
11563 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 11564 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 11565 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
11566 }
11567
11568 /* Update stack and set back pointer unless this is V.4,
11569 for which it was done previously. */
fc4767bb
JJ
11570 if (info->push_p
11571 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
11572 rs6000_emit_allocate_stack (info->total_size, FALSE);
11573
11574 /* Set frame pointer, if needed. */
11575 if (frame_pointer_needed)
11576 {
a3170dc6 11577 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
11578 sp_reg_rtx);
11579 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 11580 }
9878760c 11581
1db02437 11582 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 11583 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 11584 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 11585 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
11586 {
11587 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 11588 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
11589 can use register 0. This allows us to use a plain 'blr' to return
11590 from the procedure more often. */
f1384257
AM
11591 int save_LR_around_toc_setup = (TARGET_ELF
11592 && DEFAULT_ABI != ABI_AIX
11593 && flag_pic
d5fa86ba
GK
11594 && ! info->lr_save_p
11595 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 11596 if (save_LR_around_toc_setup)
c4501e62
JJ
11597 {
11598 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11599 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
11600 rs6000_emit_load_toc_table (TRUE);
11601 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
11602 }
11603 else
11604 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 11605 }
ee890fe2 11606
fcce224d 11607#if TARGET_MACHO
ee890fe2
SS
11608 if (DEFAULT_ABI == ABI_DARWIN
11609 && flag_pic && current_function_uses_pic_offset_table)
11610 {
11611 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 11612 const char *picbase = machopic_function_base_name ();
6788f5ca 11613 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 11614
f51eee6a 11615 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
11616
11617 rs6000_maybe_dead (
1db02437 11618 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
11619 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
11620 }
fcce224d 11621#endif
9ebbca7d
GK
11622}
11623
9ebbca7d 11624/* Write function prologue. */
a4f6c312 11625
08c148a8
NB
11626static void
11627rs6000_output_function_prologue (file, size)
9ebbca7d 11628 FILE *file;
08c148a8 11629 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9ebbca7d
GK
11630{
11631 rs6000_stack_t *info = rs6000_stack_info ();
11632
4697a36c
MM
11633 if (TARGET_DEBUG_STACK)
11634 debug_stack_info (info);
9878760c 11635
a4f6c312
SS
11636 /* Write .extern for any function we will call to save and restore
11637 fp values. */
11638 if (info->first_fp_reg_save < 64
11639 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 11640 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 11641 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
11642 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
11643 RESTORE_FP_SUFFIX);
9878760c 11644
c764f757
RK
11645 /* Write .extern for AIX common mode routines, if needed. */
11646 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
11647 {
f6709c70
JW
11648 fputs ("\t.extern __mulh\n", file);
11649 fputs ("\t.extern __mull\n", file);
11650 fputs ("\t.extern __divss\n", file);
11651 fputs ("\t.extern __divus\n", file);
11652 fputs ("\t.extern __quoss\n", file);
11653 fputs ("\t.extern __quous\n", file);
c764f757
RK
11654 common_mode_defined = 1;
11655 }
9878760c 11656
9ebbca7d 11657 if (! HAVE_prologue)
979721f8 11658 {
9ebbca7d 11659 start_sequence ();
9dda4cc8 11660
a4f6c312
SS
11661 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
11662 the "toplevel" insn chain. */
2e040219 11663 emit_note (NOTE_INSN_DELETED);
9ebbca7d 11664 rs6000_emit_prologue ();
2e040219 11665 emit_note (NOTE_INSN_DELETED);
178c3eff
DJ
11666
11667 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11668 {
11669 rtx insn;
11670 unsigned addr = 0;
11671 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11672 {
11673 INSN_ADDRESSES_NEW (insn, addr);
11674 addr += 4;
11675 }
11676 }
9dda4cc8 11677
9ebbca7d 11678 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11679 debug_rtx_list (get_insns (), 100);
11680 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11681 end_sequence ();
979721f8
MM
11682 }
11683
9ebbca7d
GK
11684 rs6000_pic_labelno++;
11685}
11686
11687/* Emit function epilogue as insns.
9878760c 11688
9ebbca7d
GK
11689 At present, dwarf2out_frame_debug_expr doesn't understand
11690 register restores, so we don't bother setting RTX_FRAME_RELATED_P
11691 anywhere in the epilogue. Most of the insns below would in any case
11692 need special notes to explain where r11 is in relation to the stack. */
9878760c 11693
9ebbca7d 11694void
83720594 11695rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
11696 int sibcall;
11697{
11698 rs6000_stack_t *info;
11699 int restoring_FPRs_inline;
11700 int using_load_multiple;
11701 int using_mfcr_multiple;
11702 int use_backchain_to_restore_sp;
11703 int sp_offset = 0;
11704 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
11705 rtx frame_reg_rtx = sp_reg_rtx;
11706 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
11707 int reg_size = TARGET_POWERPC64 ? 8 : 4;
11708 int i;
11709
c19de7aa
AH
11710 info = rs6000_stack_info ();
11711
11712 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11713 {
11714 reg_mode = V2SImode;
11715 reg_size = 8;
11716 }
11717
9ebbca7d 11718 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11719 && (!TARGET_SPE_ABI
11720 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11721 && info->first_gp_reg_save < 31);
11722 restoring_FPRs_inline = (sibcall
83720594 11723 || current_function_calls_eh_return
9ebbca7d
GK
11724 || info->first_fp_reg_save == 64
11725 || FP_SAVE_INLINE (info->first_fp_reg_save));
11726 use_backchain_to_restore_sp = (frame_pointer_needed
11727 || current_function_calls_alloca
11728 || info->total_size > 32767);
11729 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
11730 || rs6000_cpu == PROCESSOR_PPC603
11731 || rs6000_cpu == PROCESSOR_PPC750
11732 || optimize_size);
11733
11734 /* If we have a frame pointer, a call to alloca, or a large stack
11735 frame, restore the old stack pointer using the backchain. Otherwise,
11736 we know what size to update it with. */
11737 if (use_backchain_to_restore_sp)
bacbde18 11738 {
9ebbca7d
GK
11739 /* Under V.4, don't reset the stack pointer until after we're done
11740 loading the saved registers. */
f607bc57 11741 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 11742 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 11743
9ebbca7d
GK
11744 emit_move_insn (frame_reg_rtx,
11745 gen_rtx_MEM (Pmode, sp_reg_rtx));
11746
bacbde18 11747 }
9ebbca7d 11748 else if (info->push_p)
85638c0d 11749 {
fc4767bb
JJ
11750 if (DEFAULT_ABI == ABI_V4
11751 || current_function_calls_eh_return)
9ebbca7d
GK
11752 sp_offset = info->total_size;
11753 else
11754 {
11755 emit_insn (TARGET_32BIT
11756 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11757 GEN_INT (info->total_size))
11758 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11759 GEN_INT (info->total_size)));
11760 }
85638c0d 11761 }
9ebbca7d 11762
9aa86737
AH
11763 /* Restore AltiVec registers if needed. */
11764 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11765 {
11766 int i;
11767
11768 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11769 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11770 {
11771 rtx addr, areg, mem;
11772
11773 areg = gen_rtx_REG (Pmode, 0);
11774 emit_move_insn
11775 (areg, GEN_INT (info->altivec_save_offset
11776 + sp_offset
11777 + 16 * (i - info->first_altivec_reg_save)));
11778
11779 /* AltiVec addressing mode is [reg+reg]. */
11780 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
11781 mem = gen_rtx_MEM (V4SImode, addr);
11782 set_mem_alias_set (mem, rs6000_sr_alias_set);
11783
11784 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
11785 }
11786 }
11787
11788 /* Restore VRSAVE if needed. */
11789 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
11790 {
11791 rtx addr, mem, reg;
11792
11793 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11794 GEN_INT (info->vrsave_save_offset + sp_offset));
11795 mem = gen_rtx_MEM (SImode, addr);
11796 set_mem_alias_set (mem, rs6000_sr_alias_set);
11797 reg = gen_rtx_REG (SImode, 12);
11798 emit_move_insn (reg, mem);
11799
11800 emit_insn (generate_set_vrsave (reg, info, 1));
11801 }
11802
9ebbca7d
GK
11803 /* Get the old lr if we saved it. */
11804 if (info->lr_save_p)
b6c9286a 11805 {
a3170dc6
AH
11806 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
11807 info->lr_save_offset + sp_offset);
ba4828e0
RK
11808
11809 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 11810
9ebbca7d 11811 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 11812 }
9ebbca7d
GK
11813
11814 /* Get the old cr if we saved it. */
11815 if (info->cr_save_p)
11816 {
11817 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11818 GEN_INT (info->cr_save_offset + sp_offset));
11819 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11820
11821 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 11822
9ebbca7d
GK
11823 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
11824 }
11825
11826 /* Set LR here to try to overlap restores below. */
4697a36c 11827 if (info->lr_save_p)
9ebbca7d
GK
11828 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
11829 gen_rtx_REG (Pmode, 0));
11830
83720594
RH
11831 /* Load exception handler data registers, if needed. */
11832 if (current_function_calls_eh_return)
11833 {
78e1b90d
DE
11834 unsigned int i, regno;
11835
fc4767bb
JJ
11836 if (TARGET_AIX)
11837 {
11838 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11839 GEN_INT (sp_offset + 5 * reg_size));
11840 rtx mem = gen_rtx_MEM (reg_mode, addr);
11841
11842 set_mem_alias_set (mem, rs6000_sr_alias_set);
11843
11844 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
11845 }
11846
83720594
RH
11847 for (i = 0; ; ++i)
11848 {
a3170dc6 11849 rtx mem;
83720594
RH
11850
11851 regno = EH_RETURN_DATA_REGNO (i);
11852 if (regno == INVALID_REGNUM)
11853 break;
11854
a3170dc6
AH
11855 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
11856 info->ehrd_offset + sp_offset
11857 + reg_size * (int) i);
ba4828e0 11858 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
11859
11860 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
11861 }
11862 }
9ebbca7d
GK
11863
11864 /* Restore GPRs. This is done as a PARALLEL if we are using
11865 the load-multiple instructions. */
11866 if (using_load_multiple)
979721f8 11867 {
9ebbca7d
GK
11868 rtvec p;
11869 p = rtvec_alloc (32 - info->first_gp_reg_save);
11870 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 11871 {
9ebbca7d
GK
11872 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11873 GEN_INT (info->gp_save_offset
11874 + sp_offset
11875 + reg_size * i));
11876 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
11877
11878 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11879
11880 RTVEC_ELT (p, i) =
11881 gen_rtx_SET (VOIDmode,
11882 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
11883 mem);
979721f8 11884 }
9ebbca7d 11885 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 11886 }
9ebbca7d
GK
11887 else
11888 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11889 if ((regs_ever_live[info->first_gp_reg_save+i]
11890 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11891 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11892 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11893 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
11894 {
11895 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11896 GEN_INT (info->gp_save_offset
11897 + sp_offset
11898 + reg_size * i));
11899 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11900
a3170dc6 11901 /* Restore 64-bit quantities for SPE. */
c19de7aa 11902 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11903 {
11904 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11905 rtx b;
11906
11907 if (!SPE_CONST_OFFSET_OK (offset))
11908 {
11909 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11910 emit_move_insn (b, GEN_INT (offset));
11911 }
11912 else
11913 b = GEN_INT (offset);
11914
11915 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11916 mem = gen_rtx_MEM (V2SImode, addr);
11917 }
11918
ba4828e0 11919 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11920
11921 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 11922 info->first_gp_reg_save + i), mem);
9ebbca7d 11923 }
9878760c 11924
9ebbca7d
GK
11925 /* Restore fpr's if we need to do it without calling a function. */
11926 if (restoring_FPRs_inline)
11927 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11928 if ((regs_ever_live[info->first_fp_reg_save+i]
11929 && ! call_used_regs[info->first_fp_reg_save+i]))
11930 {
11931 rtx addr, mem;
11932 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11933 GEN_INT (info->fp_save_offset
11934 + sp_offset
a4f6c312 11935 + 8 * i));
9ebbca7d 11936 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11937 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11938
11939 emit_move_insn (gen_rtx_REG (DFmode,
11940 info->first_fp_reg_save + i),
11941 mem);
11942 }
8d30c4ee 11943
9ebbca7d
GK
11944 /* If we saved cr, restore it here. Just those that were used. */
11945 if (info->cr_save_p)
979721f8 11946 {
9ebbca7d 11947 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 11948 int count = 0;
9ebbca7d
GK
11949
11950 if (using_mfcr_multiple)
979721f8 11951 {
9ebbca7d
GK
11952 for (i = 0; i < 8; i++)
11953 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 11954 count++;
9ebbca7d 11955 if (count == 0)
e35b9579
GK
11956 abort ();
11957 }
11958
11959 if (using_mfcr_multiple && count > 1)
11960 {
11961 rtvec p;
11962 int ndx;
9ebbca7d 11963
e35b9579 11964 p = rtvec_alloc (count);
9ebbca7d 11965
e35b9579 11966 ndx = 0;
9ebbca7d
GK
11967 for (i = 0; i < 8; i++)
11968 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
11969 {
11970 rtvec r = rtvec_alloc (2);
11971 RTVEC_ELT (r, 0) = r12_rtx;
11972 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 11973 RTVEC_ELT (p, ndx) =
9ebbca7d 11974 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 11975 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 11976 ndx++;
9ebbca7d
GK
11977 }
11978 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
11979 if (ndx != count)
11980 abort ();
979721f8
MM
11981 }
11982 else
9ebbca7d
GK
11983 for (i = 0; i < 8; i++)
11984 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 11985 {
9ebbca7d
GK
11986 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
11987 CR0_REGNO+i),
11988 r12_rtx));
979721f8 11989 }
979721f8
MM
11990 }
11991
9ebbca7d
GK
11992 /* If this is V.4, unwind the stack pointer after all of the loads
11993 have been done. We need to emit a block here so that sched
11994 doesn't decide to move the sp change before the register restores
11995 (which may not have any obvious dependency on the stack). This
11996 doesn't hurt performance, because there is no scheduling that can
11997 be done after this point. */
fc4767bb
JJ
11998 if (DEFAULT_ABI == ABI_V4
11999 || current_function_calls_eh_return)
b6c9286a 12000 {
9ebbca7d
GK
12001 if (frame_reg_rtx != sp_reg_rtx)
12002 rs6000_emit_stack_tie ();
b6c9286a 12003
9ebbca7d 12004 if (use_backchain_to_restore_sp)
b6c9286a 12005 {
9ebbca7d 12006 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12007 }
9ebbca7d 12008 else if (sp_offset != 0)
13f1623b 12009 {
5b71a4e7 12010 emit_insn (TARGET_32BIT
9ebbca7d
GK
12011 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12012 GEN_INT (sp_offset))
12013 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12014 GEN_INT (sp_offset)));
13f1623b 12015 }
9ebbca7d 12016 }
b6c9286a 12017
83720594
RH
12018 if (current_function_calls_eh_return)
12019 {
12020 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12021 emit_insn (TARGET_32BIT
83720594
RH
12022 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12023 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12024 }
12025
9ebbca7d
GK
12026 if (!sibcall)
12027 {
12028 rtvec p;
12029 if (! restoring_FPRs_inline)
12030 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12031 else
12032 p = rtvec_alloc (2);
b6c9286a 12033
e35b9579
GK
12034 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12035 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12036 gen_rtx_REG (Pmode,
12037 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12038
12039 /* If we have to restore more than two FP registers, branch to the
12040 restore function. It will return to our caller. */
12041 if (! restoring_FPRs_inline)
12042 {
12043 int i;
12044 char rname[30];
520a57c8 12045 const char *alloc_rname;
979721f8 12046
9ebbca7d
GK
12047 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12048 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12049 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12050 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12051 gen_rtx_SYMBOL_REF (Pmode,
12052 alloc_rname));
b6c9286a 12053
9ebbca7d
GK
12054 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12055 {
12056 rtx addr, mem;
12057 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12058 GEN_INT (info->fp_save_offset + 8*i));
12059 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12060 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12061
12062 RTVEC_ELT (p, i+3) =
12063 gen_rtx_SET (VOIDmode,
12064 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12065 mem);
b6c9286a
MM
12066 }
12067 }
9ebbca7d
GK
12068
12069 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12070 }
9878760c
RK
12071}
12072
12073/* Write function epilogue. */
12074
08c148a8
NB
12075static void
12076rs6000_output_function_epilogue (file, size)
9878760c 12077 FILE *file;
08c148a8 12078 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9878760c 12079{
4697a36c 12080 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12081
9ebbca7d 12082 if (! HAVE_epilogue)
9878760c 12083 {
9ebbca7d
GK
12084 rtx insn = get_last_insn ();
12085 /* If the last insn was a BARRIER, we don't have to write anything except
12086 the trace table. */
12087 if (GET_CODE (insn) == NOTE)
12088 insn = prev_nonnote_insn (insn);
12089 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12090 {
9ebbca7d
GK
12091 /* This is slightly ugly, but at least we don't have two
12092 copies of the epilogue-emitting code. */
12093 start_sequence ();
12094
12095 /* A NOTE_INSN_DELETED is supposed to be at the start
12096 and end of the "toplevel" insn chain. */
2e040219 12097 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12098 rs6000_emit_epilogue (FALSE);
2e040219 12099 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12100
178c3eff
DJ
12101 /* Expand INSN_ADDRESSES so final() doesn't crash. */
12102 {
12103 rtx insn;
12104 unsigned addr = 0;
12105 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12106 {
12107 INSN_ADDRESSES_NEW (insn, addr);
12108 addr += 4;
12109 }
12110 }
12111
9ebbca7d 12112 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12113 debug_rtx_list (get_insns (), 100);
12114 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12115 end_sequence ();
4697a36c 12116 }
9878760c 12117 }
b4ac57ab 12118
9b30bae2 12119 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12120 on its format.
12121
12122 We don't output a traceback table if -finhibit-size-directive was
12123 used. The documentation for -finhibit-size-directive reads
12124 ``don't output a @code{.size} assembler directive, or anything
12125 else that would cause trouble if the function is split in the
12126 middle, and the two halves are placed at locations far apart in
12127 memory.'' The traceback table has this property, since it
12128 includes the offset from the start of the function to the
4d30c363
MM
12129 traceback table itself.
12130
12131 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12132 different traceback table. */
57ac7be9
AM
12133 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12134 && rs6000_traceback != traceback_none)
9b30bae2 12135 {
69c75916 12136 const char *fname = NULL;
3ac88239 12137 const char *language_string = lang_hooks.name;
6041bf2f 12138 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12139 int i;
57ac7be9
AM
12140 int optional_tbtab;
12141
12142 if (rs6000_traceback == traceback_full)
12143 optional_tbtab = 1;
12144 else if (rs6000_traceback == traceback_part)
12145 optional_tbtab = 0;
12146 else
12147 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12148
69c75916
AM
12149 if (optional_tbtab)
12150 {
12151 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12152 while (*fname == '.') /* V.4 encodes . in the name */
12153 fname++;
12154
12155 /* Need label immediately before tbtab, so we can compute
12156 its offset from the function start. */
12157 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12158 ASM_OUTPUT_LABEL (file, fname);
12159 }
314fc5a9
ILT
12160
12161 /* The .tbtab pseudo-op can only be used for the first eight
12162 expressions, since it can't handle the possibly variable
12163 length fields that follow. However, if you omit the optional
12164 fields, the assembler outputs zeros for all optional fields
12165 anyways, giving each variable length field is minimum length
12166 (as defined in sys/debug.h). Thus we can not use the .tbtab
12167 pseudo-op at all. */
12168
12169 /* An all-zero word flags the start of the tbtab, for debuggers
12170 that have to find it by searching forward from the entry
12171 point or from the current pc. */
19d2d16f 12172 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12173
12174 /* Tbtab format type. Use format type 0. */
19d2d16f 12175 fputs ("\t.byte 0,", file);
314fc5a9
ILT
12176
12177 /* Language type. Unfortunately, there doesn't seem to be any
12178 official way to get this info, so we use language_string. C
12179 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 12180 value for C for now. There is no official value for Java,
6f573ff9 12181 although IBM appears to be using 13. There is no official value
f710504c 12182 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 12183 if (! strcmp (language_string, "GNU C")
e2c953b6 12184 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
12185 i = 0;
12186 else if (! strcmp (language_string, "GNU F77"))
12187 i = 1;
12188 else if (! strcmp (language_string, "GNU Ada"))
12189 i = 3;
8b83775b 12190 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
12191 i = 2;
12192 else if (! strcmp (language_string, "GNU C++"))
12193 i = 9;
9517ead8
AG
12194 else if (! strcmp (language_string, "GNU Java"))
12195 i = 13;
6f573ff9
JL
12196 else if (! strcmp (language_string, "GNU CHILL"))
12197 i = 44;
314fc5a9
ILT
12198 else
12199 abort ();
12200 fprintf (file, "%d,", i);
12201
12202 /* 8 single bit fields: global linkage (not set for C extern linkage,
12203 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12204 from start of procedure stored in tbtab, internal function, function
12205 has controlled storage, function has no toc, function uses fp,
12206 function logs/aborts fp operations. */
12207 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12208 fprintf (file, "%d,",
12209 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12210
12211 /* 6 bitfields: function is interrupt handler, name present in
12212 proc table, function calls alloca, on condition directives
12213 (controls stack walks, 3 bits), saves condition reg, saves
12214 link reg. */
12215 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12216 set up as a frame pointer, even when there is no alloca call. */
12217 fprintf (file, "%d,",
6041bf2f
DE
12218 ((optional_tbtab << 6)
12219 | ((optional_tbtab & frame_pointer_needed) << 5)
12220 | (info->cr_save_p << 1)
12221 | (info->lr_save_p)));
314fc5a9 12222
6041bf2f 12223 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12224 (6 bits). */
12225 fprintf (file, "%d,",
4697a36c 12226 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12227
12228 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12229 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12230
6041bf2f
DE
12231 if (optional_tbtab)
12232 {
12233 /* Compute the parameter info from the function decl argument
12234 list. */
12235 tree decl;
12236 int next_parm_info_bit = 31;
314fc5a9 12237
6041bf2f
DE
12238 for (decl = DECL_ARGUMENTS (current_function_decl);
12239 decl; decl = TREE_CHAIN (decl))
12240 {
12241 rtx parameter = DECL_INCOMING_RTL (decl);
12242 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12243
6041bf2f
DE
12244 if (GET_CODE (parameter) == REG)
12245 {
12246 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12247 {
12248 int bits;
12249
12250 float_parms++;
12251
12252 if (mode == SFmode)
12253 bits = 0x2;
fcce224d 12254 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12255 bits = 0x3;
12256 else
12257 abort ();
12258
12259 /* If only one bit will fit, don't or in this entry. */
12260 if (next_parm_info_bit > 0)
12261 parm_info |= (bits << (next_parm_info_bit - 1));
12262 next_parm_info_bit -= 2;
12263 }
12264 else
12265 {
12266 fixed_parms += ((GET_MODE_SIZE (mode)
12267 + (UNITS_PER_WORD - 1))
12268 / UNITS_PER_WORD);
12269 next_parm_info_bit -= 1;
12270 }
12271 }
12272 }
12273 }
314fc5a9
ILT
12274
12275 /* Number of fixed point parameters. */
12276 /* This is actually the number of words of fixed point parameters; thus
12277 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12278 fprintf (file, "%d,", fixed_parms);
12279
12280 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12281 all on stack. */
12282 /* This is actually the number of fp registers that hold parameters;
12283 and thus the maximum value is 13. */
12284 /* Set parameters on stack bit if parameters are not in their original
12285 registers, regardless of whether they are on the stack? Xlc
12286 seems to set the bit when not optimizing. */
12287 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12288
6041bf2f
DE
12289 if (! optional_tbtab)
12290 return;
12291
314fc5a9
ILT
12292 /* Optional fields follow. Some are variable length. */
12293
12294 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12295 11 double float. */
12296 /* There is an entry for each parameter in a register, in the order that
12297 they occur in the parameter list. Any intervening arguments on the
12298 stack are ignored. If the list overflows a long (max possible length
12299 34 bits) then completely leave off all elements that don't fit. */
12300 /* Only emit this long if there was at least one parameter. */
12301 if (fixed_parms || float_parms)
12302 fprintf (file, "\t.long %d\n", parm_info);
12303
12304 /* Offset from start of code to tb table. */
19d2d16f 12305 fputs ("\t.long ", file);
314fc5a9 12306 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12307#if TARGET_AIX
12308 RS6000_OUTPUT_BASENAME (file, fname);
12309#else
9ebbca7d 12310 assemble_name (file, fname);
54ee9799 12311#endif
19d2d16f 12312 fputs ("-.", file);
54ee9799
DE
12313#if TARGET_AIX
12314 RS6000_OUTPUT_BASENAME (file, fname);
12315#else
9ebbca7d 12316 assemble_name (file, fname);
54ee9799 12317#endif
19d2d16f 12318 putc ('\n', file);
314fc5a9
ILT
12319
12320 /* Interrupt handler mask. */
12321 /* Omit this long, since we never set the interrupt handler bit
12322 above. */
12323
12324 /* Number of CTL (controlled storage) anchors. */
12325 /* Omit this long, since the has_ctl bit is never set above. */
12326
12327 /* Displacement into stack of each CTL anchor. */
12328 /* Omit this list of longs, because there are no CTL anchors. */
12329
12330 /* Length of function name. */
69c75916
AM
12331 if (*fname == '*')
12332 ++fname;
296b8152 12333 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
12334
12335 /* Function name. */
12336 assemble_string (fname, strlen (fname));
12337
12338 /* Register for alloca automatic storage; this is always reg 31.
12339 Only emit this if the alloca bit was set above. */
12340 if (frame_pointer_needed)
19d2d16f 12341 fputs ("\t.byte 31\n", file);
b1765bde
DE
12342
12343 fputs ("\t.align 2\n", file);
9b30bae2 12344 }
9878760c 12345}
17167fd8 12346\f
a4f6c312
SS
12347/* A C compound statement that outputs the assembler code for a thunk
12348 function, used to implement C++ virtual function calls with
12349 multiple inheritance. The thunk acts as a wrapper around a virtual
12350 function, adjusting the implicit object parameter before handing
12351 control off to the real function.
12352
12353 First, emit code to add the integer DELTA to the location that
12354 contains the incoming first argument. Assume that this argument
12355 contains a pointer, and is the one used to pass the `this' pointer
12356 in C++. This is the incoming argument *before* the function
12357 prologue, e.g. `%o0' on a sparc. The addition must preserve the
12358 values of all other incoming arguments.
17167fd8
MM
12359
12360 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
12361 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
12362 not touch the return address. Hence returning from FUNCTION will
12363 return to whoever called the current `thunk'.
17167fd8 12364
a4f6c312
SS
12365 The effect must be as if FUNCTION had been called directly with the
12366 adjusted first argument. This macro is responsible for emitting
12367 all of the code for a thunk function; output_function_prologue()
12368 and output_function_epilogue() are not invoked.
17167fd8 12369
a4f6c312
SS
12370 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
12371 been extracted from it.) It might possibly be useful on some
12372 targets, but probably not.
17167fd8 12373
a4f6c312
SS
12374 If you do not define this macro, the target-independent code in the
12375 C++ frontend will generate a less efficient heavyweight thunk that
12376 calls FUNCTION instead of jumping to it. The generic approach does
12377 not support varargs. */
17167fd8 12378
3961e8fe
RH
12379static void
12380rs6000_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
17167fd8 12381 FILE *file;
d330fd93 12382 tree thunk_fndecl ATTRIBUTE_UNUSED;
eb0424da 12383 HOST_WIDE_INT delta;
5b71a4e7 12384 HOST_WIDE_INT vcall_offset;
17167fd8
MM
12385 tree function;
12386{
5b71a4e7 12387 rtx this, insn, funexp;
17167fd8 12388
5b71a4e7 12389 reload_completed = 1;
fe3ad572 12390 epilogue_completed = 1;
5b71a4e7 12391 no_new_pseudos = 1;
56a7189a 12392
5b71a4e7 12393 /* Mark the end of the (empty) prologue. */
2e040219 12394 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 12395
5b71a4e7
DE
12396 /* Find the "this" pointer. If the function returns a structure,
12397 the structure return pointer is in r3. */
12398 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
12399 this = gen_rtx_REG (Pmode, 4);
56a7189a 12400 else
5b71a4e7 12401 this = gen_rtx_REG (Pmode, 3);
17167fd8 12402
5b71a4e7
DE
12403 /* Apply the constant offset, if required. */
12404 if (delta)
12405 {
12406 rtx delta_rtx = GEN_INT (delta);
12407 emit_insn (TARGET_32BIT
12408 ? gen_addsi3 (this, this, delta_rtx)
12409 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
12410 }
12411
5b71a4e7
DE
12412 /* Apply the offset from the vtable, if required. */
12413 if (vcall_offset)
17167fd8 12414 {
5b71a4e7
DE
12415 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
12416 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 12417
5b71a4e7 12418 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
12419 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
12420 {
12421 emit_insn (TARGET_32BIT
12422 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
12423 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
12424 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
12425 }
12426 else
12427 {
12428 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
12429
12430 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
12431 }
5b71a4e7
DE
12432 emit_insn (TARGET_32BIT
12433 ? gen_addsi3 (this, this, tmp)
12434 : gen_adddi3 (this, this, tmp));
17167fd8
MM
12435 }
12436
5b71a4e7
DE
12437 /* Generate a tail call to the target function. */
12438 if (!TREE_USED (function))
12439 {
12440 assemble_external (function);
12441 TREE_USED (function) = 1;
12442 }
12443 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 12444 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
12445
12446#if TARGET_MACHO
ab82a49f 12447 if (MACHOPIC_INDIRECT)
5b71a4e7 12448 funexp = machopic_indirect_call_target (funexp);
ee890fe2 12449#endif
5b71a4e7
DE
12450
12451 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
12452 generate sibcall RTL explicitly to avoid constraint abort. */
12453 insn = emit_call_insn (
12454 gen_rtx_PARALLEL (VOIDmode,
12455 gen_rtvec (4,
12456 gen_rtx_CALL (VOIDmode,
12457 funexp, const0_rtx),
12458 gen_rtx_USE (VOIDmode, const0_rtx),
12459 gen_rtx_USE (VOIDmode,
12460 gen_rtx_REG (SImode,
12461 LINK_REGISTER_REGNUM)),
12462 gen_rtx_RETURN (VOIDmode))));
12463 SIBLING_CALL_P (insn) = 1;
12464 emit_barrier ();
12465
12466 /* Run just enough of rest_of_compilation to get the insns emitted.
12467 There's not really enough bulk here to make other passes such as
12468 instruction scheduling worth while. Note that use_thunk calls
12469 assemble_start_function and assemble_end_function. */
12470 insn = get_insns ();
a2855205 12471 insn_locators_initialize ();
5b71a4e7
DE
12472 shorten_branches (insn);
12473 final_start_function (insn, file, 1);
12474 final (insn, file, 1, 0);
12475 final_end_function ();
12476
12477 reload_completed = 0;
fe3ad572 12478 epilogue_completed = 0;
5b71a4e7 12479 no_new_pseudos = 0;
9ebbca7d 12480}
9ebbca7d
GK
12481\f
12482/* A quick summary of the various types of 'constant-pool tables'
12483 under PowerPC:
12484
12485 Target Flags Name One table per
12486 AIX (none) AIX TOC object file
12487 AIX -mfull-toc AIX TOC object file
12488 AIX -mminimal-toc AIX minimal TOC translation unit
12489 SVR4/EABI (none) SVR4 SDATA object file
12490 SVR4/EABI -fpic SVR4 pic object file
12491 SVR4/EABI -fPIC SVR4 PIC translation unit
12492 SVR4/EABI -mrelocatable EABI TOC function
12493 SVR4/EABI -maix AIX TOC object file
12494 SVR4/EABI -maix -mminimal-toc
12495 AIX minimal TOC translation unit
12496
12497 Name Reg. Set by entries contains:
12498 made by addrs? fp? sum?
12499
12500 AIX TOC 2 crt0 as Y option option
12501 AIX minimal TOC 30 prolog gcc Y Y option
12502 SVR4 SDATA 13 crt0 gcc N Y N
12503 SVR4 pic 30 prolog ld Y not yet N
12504 SVR4 PIC 30 prolog gcc Y option option
12505 EABI TOC 30 prolog gcc Y option option
12506
12507*/
12508
9ebbca7d
GK
12509/* Hash functions for the hash table. */
12510
12511static unsigned
12512rs6000_hash_constant (k)
12513 rtx k;
12514{
46b33600
RH
12515 enum rtx_code code = GET_CODE (k);
12516 enum machine_mode mode = GET_MODE (k);
12517 unsigned result = (code << 3) ^ mode;
12518 const char *format;
12519 int flen, fidx;
9ebbca7d 12520
46b33600
RH
12521 format = GET_RTX_FORMAT (code);
12522 flen = strlen (format);
12523 fidx = 0;
9ebbca7d 12524
46b33600
RH
12525 switch (code)
12526 {
12527 case LABEL_REF:
12528 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
12529
12530 case CONST_DOUBLE:
12531 if (mode != VOIDmode)
12532 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
12533 flen = 2;
12534 break;
12535
12536 case CODE_LABEL:
12537 fidx = 3;
12538 break;
12539
12540 default:
12541 break;
12542 }
9ebbca7d
GK
12543
12544 for (; fidx < flen; fidx++)
12545 switch (format[fidx])
12546 {
12547 case 's':
12548 {
12549 unsigned i, len;
12550 const char *str = XSTR (k, fidx);
12551 len = strlen (str);
12552 result = result * 613 + len;
12553 for (i = 0; i < len; i++)
12554 result = result * 613 + (unsigned) str[i];
17167fd8
MM
12555 break;
12556 }
9ebbca7d
GK
12557 case 'u':
12558 case 'e':
12559 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
12560 break;
12561 case 'i':
12562 case 'n':
12563 result = result * 613 + (unsigned) XINT (k, fidx);
12564 break;
12565 case 'w':
12566 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
12567 result = result * 613 + (unsigned) XWINT (k, fidx);
12568 else
12569 {
12570 size_t i;
12571 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
12572 result = result * 613 + (unsigned) (XWINT (k, fidx)
12573 >> CHAR_BIT * i);
12574 }
12575 break;
09501938
DE
12576 case '0':
12577 break;
9ebbca7d 12578 default:
a4f6c312 12579 abort ();
9ebbca7d 12580 }
46b33600 12581
9ebbca7d
GK
12582 return result;
12583}
12584
12585static unsigned
12586toc_hash_function (hash_entry)
12587 const void * hash_entry;
12588{
a9098fd0
GK
12589 const struct toc_hash_struct *thc =
12590 (const struct toc_hash_struct *) hash_entry;
12591 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
12592}
12593
12594/* Compare H1 and H2 for equivalence. */
12595
12596static int
12597toc_hash_eq (h1, h2)
12598 const void * h1;
12599 const void * h2;
12600{
12601 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
12602 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
12603
a9098fd0
GK
12604 if (((const struct toc_hash_struct *) h1)->key_mode
12605 != ((const struct toc_hash_struct *) h2)->key_mode)
12606 return 0;
12607
5692c7bc 12608 return rtx_equal_p (r1, r2);
9ebbca7d
GK
12609}
12610
28e510bd
MM
12611/* These are the names given by the C++ front-end to vtables, and
12612 vtable-like objects. Ideally, this logic should not be here;
12613 instead, there should be some programmatic way of inquiring as
12614 to whether or not an object is a vtable. */
12615
12616#define VTABLE_NAME_P(NAME) \
12617 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
12618 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
12619 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
12620 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
12621
12622void
12623rs6000_output_symbol_ref (file, x)
12624 FILE *file;
12625 rtx x;
12626{
12627 /* Currently C++ toc references to vtables can be emitted before it
12628 is decided whether the vtable is public or private. If this is
12629 the case, then the linker will eventually complain that there is
12630 a reference to an unknown section. Thus, for vtables only,
12631 we emit the TOC reference to reference the symbol and not the
12632 section. */
12633 const char *name = XSTR (x, 0);
54ee9799
DE
12634
12635 if (VTABLE_NAME_P (name))
12636 {
12637 RS6000_OUTPUT_BASENAME (file, name);
12638 }
12639 else
12640 assemble_name (file, name);
28e510bd
MM
12641}
12642
a4f6c312
SS
12643/* Output a TOC entry. We derive the entry name from what is being
12644 written. */
9878760c
RK
12645
12646void
a9098fd0 12647output_toc (file, x, labelno, mode)
9878760c
RK
12648 FILE *file;
12649 rtx x;
12650 int labelno;
a9098fd0 12651 enum machine_mode mode;
9878760c
RK
12652{
12653 char buf[256];
3cce094d 12654 const char *name = buf;
ec940faa 12655 const char *real_name;
9878760c
RK
12656 rtx base = x;
12657 int offset = 0;
12658
4697a36c
MM
12659 if (TARGET_NO_TOC)
12660 abort ();
12661
9ebbca7d
GK
12662 /* When the linker won't eliminate them, don't output duplicate
12663 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
12664 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
12665 CODE_LABELs. */
12666 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
12667 {
12668 struct toc_hash_struct *h;
12669 void * * found;
12670
17211ab5 12671 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 12672 time because GGC is not initialized at that point. */
17211ab5
GK
12673 if (toc_hash_table == NULL)
12674 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
12675 toc_hash_eq, NULL);
12676
9ebbca7d
GK
12677 h = ggc_alloc (sizeof (*h));
12678 h->key = x;
a9098fd0 12679 h->key_mode = mode;
9ebbca7d
GK
12680 h->labelno = labelno;
12681
12682 found = htab_find_slot (toc_hash_table, h, 1);
12683 if (*found == NULL)
12684 *found = h;
12685 else /* This is indeed a duplicate.
12686 Set this label equal to that label. */
12687 {
12688 fputs ("\t.set ", file);
12689 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
12690 fprintf (file, "%d,", labelno);
12691 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
12692 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
12693 found)->labelno));
12694 return;
12695 }
12696 }
12697
12698 /* If we're going to put a double constant in the TOC, make sure it's
12699 aligned properly when strict alignment is on. */
ff1720ed
RK
12700 if (GET_CODE (x) == CONST_DOUBLE
12701 && STRICT_ALIGNMENT
a9098fd0 12702 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
12703 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
12704 ASM_OUTPUT_ALIGN (file, 3);
12705 }
12706
4977bab6 12707 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 12708
37c37a57
RK
12709 /* Handle FP constants specially. Note that if we have a minimal
12710 TOC, things we put here aren't actually in the TOC, so we can allow
12711 FP constants. */
fcce224d
DE
12712 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
12713 {
12714 REAL_VALUE_TYPE rv;
12715 long k[4];
12716
12717 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12718 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
12719
12720 if (TARGET_64BIT)
12721 {
12722 if (TARGET_MINIMAL_TOC)
12723 fputs (DOUBLE_INT_ASM_OP, file);
12724 else
12725 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
12726 k[0] & 0xffffffff, k[1] & 0xffffffff,
12727 k[2] & 0xffffffff, k[3] & 0xffffffff);
12728 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
12729 k[0] & 0xffffffff, k[1] & 0xffffffff,
12730 k[2] & 0xffffffff, k[3] & 0xffffffff);
12731 return;
12732 }
12733 else
12734 {
12735 if (TARGET_MINIMAL_TOC)
12736 fputs ("\t.long ", file);
12737 else
12738 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
12739 k[0] & 0xffffffff, k[1] & 0xffffffff,
12740 k[2] & 0xffffffff, k[3] & 0xffffffff);
12741 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
12742 k[0] & 0xffffffff, k[1] & 0xffffffff,
12743 k[2] & 0xffffffff, k[3] & 0xffffffff);
12744 return;
12745 }
12746 }
12747 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 12748 {
042259f2
DE
12749 REAL_VALUE_TYPE rv;
12750 long k[2];
0adc764e 12751
042259f2
DE
12752 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12753 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 12754
13ded975
DE
12755 if (TARGET_64BIT)
12756 {
12757 if (TARGET_MINIMAL_TOC)
2bfcf297 12758 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12759 else
2f0552b6
AM
12760 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
12761 k[0] & 0xffffffff, k[1] & 0xffffffff);
12762 fprintf (file, "0x%lx%08lx\n",
12763 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
12764 return;
12765 }
1875cc88 12766 else
13ded975
DE
12767 {
12768 if (TARGET_MINIMAL_TOC)
2bfcf297 12769 fputs ("\t.long ", file);
13ded975 12770 else
2f0552b6
AM
12771 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
12772 k[0] & 0xffffffff, k[1] & 0xffffffff);
12773 fprintf (file, "0x%lx,0x%lx\n",
12774 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
12775 return;
12776 }
9878760c 12777 }
a9098fd0 12778 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 12779 {
042259f2
DE
12780 REAL_VALUE_TYPE rv;
12781 long l;
9878760c 12782
042259f2
DE
12783 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12784 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
12785
31bfaa0b
DE
12786 if (TARGET_64BIT)
12787 {
12788 if (TARGET_MINIMAL_TOC)
2bfcf297 12789 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 12790 else
2f0552b6
AM
12791 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
12792 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
12793 return;
12794 }
042259f2 12795 else
31bfaa0b
DE
12796 {
12797 if (TARGET_MINIMAL_TOC)
2bfcf297 12798 fputs ("\t.long ", file);
31bfaa0b 12799 else
2f0552b6
AM
12800 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
12801 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
12802 return;
12803 }
042259f2 12804 }
f176e826 12805 else if (GET_MODE (x) == VOIDmode
a9098fd0 12806 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 12807 {
e2c953b6 12808 unsigned HOST_WIDE_INT low;
042259f2
DE
12809 HOST_WIDE_INT high;
12810
12811 if (GET_CODE (x) == CONST_DOUBLE)
12812 {
12813 low = CONST_DOUBLE_LOW (x);
12814 high = CONST_DOUBLE_HIGH (x);
12815 }
12816 else
12817#if HOST_BITS_PER_WIDE_INT == 32
12818 {
12819 low = INTVAL (x);
0858c623 12820 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
12821 }
12822#else
12823 {
0858c623 12824 low = INTVAL (x) & 0xffffffff;
042259f2
DE
12825 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
12826 }
12827#endif
9878760c 12828
a9098fd0
GK
12829 /* TOC entries are always Pmode-sized, but since this
12830 is a bigendian machine then if we're putting smaller
12831 integer constants in the TOC we have to pad them.
12832 (This is still a win over putting the constants in
12833 a separate constant pool, because then we'd have
02a4ec28
FS
12834 to have both a TOC entry _and_ the actual constant.)
12835
12836 For a 32-bit target, CONST_INT values are loaded and shifted
12837 entirely within `low' and can be stored in one TOC entry. */
12838
12839 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 12840 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
12841
12842 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
12843 {
12844#if HOST_BITS_PER_WIDE_INT == 32
12845 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
12846 POINTER_SIZE, &low, &high, 0);
12847#else
12848 low |= high << 32;
12849 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
12850 high = (HOST_WIDE_INT) low >> 32;
12851 low &= 0xffffffff;
12852#endif
12853 }
a9098fd0 12854
13ded975
DE
12855 if (TARGET_64BIT)
12856 {
12857 if (TARGET_MINIMAL_TOC)
2bfcf297 12858 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12859 else
2f0552b6
AM
12860 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
12861 (long) high & 0xffffffff, (long) low & 0xffffffff);
12862 fprintf (file, "0x%lx%08lx\n",
12863 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
12864 return;
12865 }
1875cc88 12866 else
13ded975 12867 {
02a4ec28
FS
12868 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
12869 {
12870 if (TARGET_MINIMAL_TOC)
2bfcf297 12871 fputs ("\t.long ", file);
02a4ec28 12872 else
2bfcf297 12873 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
12874 (long) high & 0xffffffff, (long) low & 0xffffffff);
12875 fprintf (file, "0x%lx,0x%lx\n",
12876 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 12877 }
13ded975 12878 else
02a4ec28
FS
12879 {
12880 if (TARGET_MINIMAL_TOC)
2bfcf297 12881 fputs ("\t.long ", file);
02a4ec28 12882 else
2f0552b6
AM
12883 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
12884 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 12885 }
13ded975
DE
12886 return;
12887 }
9878760c
RK
12888 }
12889
12890 if (GET_CODE (x) == CONST)
12891 {
2bfcf297
DB
12892 if (GET_CODE (XEXP (x, 0)) != PLUS)
12893 abort ();
12894
9878760c
RK
12895 base = XEXP (XEXP (x, 0), 0);
12896 offset = INTVAL (XEXP (XEXP (x, 0), 1));
12897 }
12898
12899 if (GET_CODE (base) == SYMBOL_REF)
12900 name = XSTR (base, 0);
12901 else if (GET_CODE (base) == LABEL_REF)
12902 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
12903 else if (GET_CODE (base) == CODE_LABEL)
12904 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
12905 else
12906 abort ();
12907
772c5265 12908 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 12909 if (TARGET_MINIMAL_TOC)
2bfcf297 12910 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
12911 else
12912 {
b6c9286a 12913 fprintf (file, "\t.tc %s", real_name);
9878760c 12914
1875cc88
JW
12915 if (offset < 0)
12916 fprintf (file, ".N%d", - offset);
12917 else if (offset)
12918 fprintf (file, ".P%d", offset);
9878760c 12919
19d2d16f 12920 fputs ("[TC],", file);
1875cc88 12921 }
581bc4de
MM
12922
12923 /* Currently C++ toc references to vtables can be emitted before it
12924 is decided whether the vtable is public or private. If this is
12925 the case, then the linker will eventually complain that there is
12926 a TOC reference to an unknown section. Thus, for vtables only,
12927 we emit the TOC reference to reference the symbol and not the
12928 section. */
28e510bd 12929 if (VTABLE_NAME_P (name))
581bc4de 12930 {
54ee9799 12931 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
12932 if (offset < 0)
12933 fprintf (file, "%d", offset);
12934 else if (offset > 0)
12935 fprintf (file, "+%d", offset);
12936 }
12937 else
12938 output_addr_const (file, x);
19d2d16f 12939 putc ('\n', file);
9878760c
RK
12940}
12941\f
12942/* Output an assembler pseudo-op to write an ASCII string of N characters
12943 starting at P to FILE.
12944
12945 On the RS/6000, we have to do this using the .byte operation and
12946 write out special characters outside the quoted string.
12947 Also, the assembler is broken; very long strings are truncated,
a4f6c312 12948 so we must artificially break them up early. */
9878760c
RK
12949
12950void
12951output_ascii (file, p, n)
12952 FILE *file;
d330fd93 12953 const char *p;
9878760c
RK
12954 int n;
12955{
12956 char c;
12957 int i, count_string;
d330fd93
KG
12958 const char *for_string = "\t.byte \"";
12959 const char *for_decimal = "\t.byte ";
12960 const char *to_close = NULL;
9878760c
RK
12961
12962 count_string = 0;
12963 for (i = 0; i < n; i++)
12964 {
12965 c = *p++;
12966 if (c >= ' ' && c < 0177)
12967 {
12968 if (for_string)
12969 fputs (for_string, file);
12970 putc (c, file);
12971
12972 /* Write two quotes to get one. */
12973 if (c == '"')
12974 {
12975 putc (c, file);
12976 ++count_string;
12977 }
12978
12979 for_string = NULL;
12980 for_decimal = "\"\n\t.byte ";
12981 to_close = "\"\n";
12982 ++count_string;
12983
12984 if (count_string >= 512)
12985 {
12986 fputs (to_close, file);
12987
12988 for_string = "\t.byte \"";
12989 for_decimal = "\t.byte ";
12990 to_close = NULL;
12991 count_string = 0;
12992 }
12993 }
12994 else
12995 {
12996 if (for_decimal)
12997 fputs (for_decimal, file);
12998 fprintf (file, "%d", c);
12999
13000 for_string = "\n\t.byte \"";
13001 for_decimal = ", ";
13002 to_close = "\n";
13003 count_string = 0;
13004 }
13005 }
13006
13007 /* Now close the string if we have written one. Then end the line. */
13008 if (to_close)
9ebbca7d 13009 fputs (to_close, file);
9878760c
RK
13010}
13011\f
13012/* Generate a unique section name for FILENAME for a section type
13013 represented by SECTION_DESC. Output goes into BUF.
13014
13015 SECTION_DESC can be any string, as long as it is different for each
13016 possible section type.
13017
13018 We name the section in the same manner as xlc. The name begins with an
13019 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13020 names) with the last period replaced by the string SECTION_DESC. If
13021 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13022 the name. */
9878760c
RK
13023
13024void
13025rs6000_gen_section_name (buf, filename, section_desc)
13026 char **buf;
9ebbca7d
GK
13027 const char *filename;
13028 const char *section_desc;
9878760c 13029{
9ebbca7d 13030 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13031 char *p;
13032 int len;
9878760c
RK
13033
13034 after_last_slash = filename;
13035 for (q = filename; *q; q++)
11e5fe42
RK
13036 {
13037 if (*q == '/')
13038 after_last_slash = q + 1;
13039 else if (*q == '.')
13040 last_period = q;
13041 }
9878760c 13042
11e5fe42 13043 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13044 *buf = (char *) xmalloc (len);
9878760c
RK
13045
13046 p = *buf;
13047 *p++ = '_';
13048
13049 for (q = after_last_slash; *q; q++)
13050 {
11e5fe42 13051 if (q == last_period)
9878760c
RK
13052 {
13053 strcpy (p, section_desc);
13054 p += strlen (section_desc);
e3981aab 13055 break;
9878760c
RK
13056 }
13057
e9a780ec 13058 else if (ISALNUM (*q))
9878760c
RK
13059 *p++ = *q;
13060 }
13061
11e5fe42 13062 if (last_period == 0)
9878760c
RK
13063 strcpy (p, section_desc);
13064 else
13065 *p = '\0';
13066}
e165f3f0 13067\f
a4f6c312 13068/* Emit profile function. */
411707f4 13069
411707f4
CC
13070void
13071output_profile_hook (labelno)
57ac7be9 13072 int labelno ATTRIBUTE_UNUSED;
411707f4 13073{
ffcfcb5f
AM
13074 if (TARGET_PROFILE_KERNEL)
13075 return;
13076
8480e480
CC
13077 if (DEFAULT_ABI == ABI_AIX)
13078 {
9739c90c
JJ
13079#ifndef NO_PROFILE_COUNTERS
13080# define NO_PROFILE_COUNTERS 0
13081#endif
13082 if (NO_PROFILE_COUNTERS)
13083 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13084 else
13085 {
13086 char buf[30];
13087 const char *label_name;
13088 rtx fun;
411707f4 13089
9739c90c
JJ
13090 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13091 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13092 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13093
9739c90c
JJ
13094 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13095 fun, Pmode);
13096 }
8480e480 13097 }
ee890fe2
SS
13098 else if (DEFAULT_ABI == ABI_DARWIN)
13099 {
d5fa86ba 13100 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13101 int caller_addr_regno = LINK_REGISTER_REGNUM;
13102
13103 /* Be conservative and always set this, at least for now. */
13104 current_function_uses_pic_offset_table = 1;
13105
13106#if TARGET_MACHO
13107 /* For PIC code, set up a stub and collect the caller's address
13108 from r0, which is where the prologue puts it. */
ab82a49f 13109 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13110 {
13111 mcount_name = machopic_stub_name (mcount_name);
13112 if (current_function_uses_pic_offset_table)
13113 caller_addr_regno = 0;
13114 }
13115#endif
13116 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13117 0, VOIDmode, 1,
13118 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13119 }
411707f4
CC
13120}
13121
a4f6c312 13122/* Write function profiler code. */
e165f3f0
RK
13123
13124void
13125output_function_profiler (file, labelno)
13126 FILE *file;
13127 int labelno;
13128{
3daf36a4 13129 char buf[100];
09eeeacb 13130 int save_lr = 8;
e165f3f0 13131
38c1f2d7 13132 switch (DEFAULT_ABI)
3daf36a4 13133 {
38c1f2d7
MM
13134 default:
13135 abort ();
13136
13137 case ABI_V4:
09eeeacb 13138 save_lr = 4;
09eeeacb
AM
13139 if (!TARGET_32BIT)
13140 {
13141 warning ("no profiling of 64-bit code for this ABI");
13142 return;
13143 }
ffcfcb5f 13144 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13145 fprintf (file, "\tmflr %s\n", reg_names[0]);
13146 if (flag_pic == 1)
13147 {
dfdfa60f 13148 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13149 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13150 reg_names[0], save_lr, reg_names[1]);
17167fd8 13151 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13152 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13153 assemble_name (file, buf);
17167fd8 13154 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13155 }
9ebbca7d 13156 else if (flag_pic > 1)
38c1f2d7 13157 {
09eeeacb
AM
13158 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13159 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13160 /* Now, we need to get the address of the label. */
13161 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13162 assemble_name (file, buf);
9ebbca7d
GK
13163 fputs ("-.\n1:", file);
13164 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13165 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13166 reg_names[0], reg_names[11]);
13167 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13168 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13169 }
38c1f2d7
MM
13170 else
13171 {
17167fd8 13172 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13173 assemble_name (file, buf);
dfdfa60f 13174 fputs ("@ha\n", file);
09eeeacb
AM
13175 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13176 reg_names[0], save_lr, reg_names[1]);
a260abc9 13177 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13178 assemble_name (file, buf);
17167fd8 13179 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13180 }
13181
50d440bc
NC
13182 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
13183 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
13184 break;
13185
13186 case ABI_AIX:
ee890fe2 13187 case ABI_DARWIN:
ffcfcb5f
AM
13188 if (!TARGET_PROFILE_KERNEL)
13189 {
13190 /* Don't do anything, done in output_profile_hook (). */
13191 }
13192 else
13193 {
13194 if (TARGET_32BIT)
13195 abort ();
13196
13197 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13198 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13199
13200 if (current_function_needs_context)
13201 {
13202 asm_fprintf (file, "\tstd %s,24(%s)\n",
13203 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13204 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13205 asm_fprintf (file, "\tld %s,24(%s)\n",
13206 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13207 }
13208 else
13209 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13210 }
38c1f2d7
MM
13211 break;
13212 }
e165f3f0 13213}
a251ffd0 13214
b54cf83a
DE
13215\f
13216static int
13217rs6000_use_dfa_pipeline_interface ()
13218{
13219 return 1;
13220}
13221
b54cf83a
DE
13222/* Power4 load update and store update instructions are cracked into a
13223 load or store and an integer insn which are executed in the same cycle.
13224 Branches have their own dispatch slot which does not count against the
13225 GCC issue rate, but it changes the program flow so there are no other
13226 instructions to issue in this cycle. */
13227
13228static int
13229rs6000_variable_issue (stream, verbose, insn, more)
13230 FILE *stream ATTRIBUTE_UNUSED;
13231 int verbose ATTRIBUTE_UNUSED;
13232 rtx insn;
13233 int more;
13234{
13235 if (GET_CODE (PATTERN (insn)) == USE
13236 || GET_CODE (PATTERN (insn)) == CLOBBER)
13237 return more;
13238
13239 if (rs6000_cpu == PROCESSOR_POWER4)
13240 {
13241 enum attr_type type = get_attr_type (insn);
13242 if (type == TYPE_LOAD_EXT_U || type == TYPE_LOAD_EXT_UX
2c4a9cff
DE
13243 || type == TYPE_LOAD_UX || type == TYPE_STORE_UX
13244 || type == TYPE_MFCR)
b54cf83a
DE
13245 return 0;
13246 else if (type == TYPE_LOAD_U || type == TYPE_STORE_U
13247 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
9259f3b0
DE
13248 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
13249 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
13250 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
13251 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
8e8238f1
DE
13252 || type == TYPE_IDIV || type == TYPE_LDIV
13253 || type == TYPE_INSERT_WORD)
3317bab1 13254 return more > 2 ? more - 2 : 0;
b54cf83a 13255 }
165b263e
DE
13256
13257 return more - 1;
b54cf83a
DE
13258}
13259
a251ffd0
TG
13260/* Adjust the cost of a scheduling dependency. Return the new cost of
13261 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13262
c237e94a 13263static int
a06faf84 13264rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
13265 rtx insn;
13266 rtx link;
296b8152 13267 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
13268 int cost;
13269{
13270 if (! recog_memoized (insn))
13271 return 0;
13272
13273 if (REG_NOTE_KIND (link) != 0)
13274 return 0;
13275
13276 if (REG_NOTE_KIND (link) == 0)
13277 {
ed947a96
DJ
13278 /* Data dependency; DEP_INSN writes a register that INSN reads
13279 some cycles later. */
13280 switch (get_attr_type (insn))
13281 {
13282 case TYPE_JMPREG:
309323c2 13283 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13284 a mtctr and bctr (and mtlr and br/blr). The first
13285 scheduling pass will not know about this latency since
13286 the mtctr instruction, which has the latency associated
13287 to it, will be generated by reload. */
309323c2 13288 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13289 case TYPE_BRANCH:
13290 /* Leave some extra cycles between a compare and its
13291 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13292 if ((rs6000_cpu_attr == CPU_PPC603
13293 || rs6000_cpu_attr == CPU_PPC604
13294 || rs6000_cpu_attr == CPU_PPC604E
13295 || rs6000_cpu_attr == CPU_PPC620
13296 || rs6000_cpu_attr == CPU_PPC630
13297 || rs6000_cpu_attr == CPU_PPC750
13298 || rs6000_cpu_attr == CPU_PPC7400
13299 || rs6000_cpu_attr == CPU_PPC7450
13300 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13301 && recog_memoized (dep_insn)
13302 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13303 && (get_attr_type (dep_insn) == TYPE_CMP
13304 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13305 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13306 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13307 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13308 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13309 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13310 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13311 return cost + 2;
13312 default:
13313 break;
13314 }
a251ffd0
TG
13315 /* Fall out to return default cost. */
13316 }
13317
13318 return cost;
13319}
b6c9286a 13320
a4f6c312
SS
13321/* A C statement (sans semicolon) to update the integer scheduling
13322 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
13323 INSN earlier, increase the priority to execute INSN later. Do not
13324 define this macro if you do not need to adjust the scheduling
13325 priorities of insns. */
bef84347 13326
c237e94a 13327static int
bef84347 13328rs6000_adjust_priority (insn, priority)
d330fd93 13329 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
13330 int priority;
13331{
a4f6c312
SS
13332 /* On machines (like the 750) which have asymmetric integer units,
13333 where one integer unit can do multiply and divides and the other
13334 can't, reduce the priority of multiply/divide so it is scheduled
13335 before other integer operations. */
bef84347
VM
13336
13337#if 0
2c3c49de 13338 if (! INSN_P (insn))
bef84347
VM
13339 return priority;
13340
13341 if (GET_CODE (PATTERN (insn)) == USE)
13342 return priority;
13343
13344 switch (rs6000_cpu_attr) {
13345 case CPU_PPC750:
13346 switch (get_attr_type (insn))
13347 {
13348 default:
13349 break;
13350
13351 case TYPE_IMUL:
13352 case TYPE_IDIV:
3cb999d8
DE
13353 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
13354 priority, priority);
bef84347
VM
13355 if (priority >= 0 && priority < 0x01000000)
13356 priority >>= 3;
13357 break;
13358 }
13359 }
13360#endif
13361
13362 return priority;
13363}
13364
a4f6c312
SS
13365/* Return how many instructions the machine can issue per cycle. */
13366
c237e94a
ZW
13367static int
13368rs6000_issue_rate ()
b6c9286a 13369{
3317bab1
DE
13370 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
13371 if (!reload_completed)
13372 return 1;
13373
b6c9286a 13374 switch (rs6000_cpu_attr) {
3cb999d8
DE
13375 case CPU_RIOS1: /* ? */
13376 case CPU_RS64A:
13377 case CPU_PPC601: /* ? */
ed947a96 13378 case CPU_PPC7450:
3cb999d8 13379 return 3;
b54cf83a 13380 case CPU_PPC440:
b6c9286a 13381 case CPU_PPC603:
bef84347 13382 case CPU_PPC750:
ed947a96 13383 case CPU_PPC7400:
be12c2b0 13384 case CPU_PPC8540:
bef84347 13385 return 2;
3cb999d8 13386 case CPU_RIOS2:
b6c9286a 13387 case CPU_PPC604:
19684119 13388 case CPU_PPC604E:
b6c9286a 13389 case CPU_PPC620:
3cb999d8 13390 case CPU_PPC630:
309323c2 13391 case CPU_POWER4:
b6c9286a
MM
13392 return 4;
13393 default:
13394 return 1;
13395 }
13396}
13397
be12c2b0
VM
13398/* Return how many instructions to look ahead for better insn
13399 scheduling. */
13400
13401static int
13402rs6000_use_sched_lookahead ()
13403{
13404 if (rs6000_cpu_attr == CPU_PPC8540)
13405 return 4;
13406 return 0;
13407}
13408
b6c9286a 13409\f
b6c9286a
MM
13410/* Length in units of the trampoline for entering a nested function. */
13411
13412int
13413rs6000_trampoline_size ()
13414{
13415 int ret = 0;
13416
13417 switch (DEFAULT_ABI)
13418 {
13419 default:
13420 abort ();
13421
13422 case ABI_AIX:
8f802bfb 13423 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
13424 break;
13425
4dabc42d 13426 case ABI_DARWIN:
b6c9286a 13427 case ABI_V4:
03a7e1a5 13428 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 13429 break;
b6c9286a
MM
13430 }
13431
13432 return ret;
13433}
13434
13435/* Emit RTL insns to initialize the variable parts of a trampoline.
13436 FNADDR is an RTX for the address of the function's pure code.
13437 CXT is an RTX for the static chain value for the function. */
13438
13439void
13440rs6000_initialize_trampoline (addr, fnaddr, cxt)
13441 rtx addr;
13442 rtx fnaddr;
13443 rtx cxt;
13444{
ac2a93a1 13445 enum machine_mode pmode = Pmode;
8bd04c56
MM
13446 int regsize = (TARGET_32BIT) ? 4 : 8;
13447 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
13448
13449 switch (DEFAULT_ABI)
13450 {
13451 default:
13452 abort ();
13453
8bd04c56 13454/* Macros to shorten the code expansions below. */
39403d82 13455#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
13456#define MEM_PLUS(addr,offset) \
13457 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 13458
b6c9286a
MM
13459 /* Under AIX, just build the 3 word function descriptor */
13460 case ABI_AIX:
8bd04c56
MM
13461 {
13462 rtx fn_reg = gen_reg_rtx (pmode);
13463 rtx toc_reg = gen_reg_rtx (pmode);
13464 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 13465 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
13466 emit_move_insn (MEM_DEREF (addr), fn_reg);
13467 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
13468 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
13469 }
b6c9286a
MM
13470 break;
13471
4dabc42d
TC
13472 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
13473 case ABI_DARWIN:
b6c9286a 13474 case ABI_V4:
39403d82 13475 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
13476 FALSE, VOIDmode, 4,
13477 addr, pmode,
13478 GEN_INT (rs6000_trampoline_size ()), SImode,
13479 fnaddr, pmode,
13480 ctx_reg, pmode);
b6c9286a 13481 break;
b6c9286a
MM
13482 }
13483
13484 return;
13485}
7509c759
MM
13486
13487\f
91d231cb 13488/* Table of valid machine attributes. */
a4f6c312 13489
91d231cb 13490const struct attribute_spec rs6000_attribute_table[] =
7509c759 13491{
91d231cb 13492 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
13493 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
13494 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
13495 { NULL, 0, 0, false, false, false, NULL }
91d231cb 13496};
7509c759 13497
a5c76ee6
ZW
13498/* Handle a "longcall" or "shortcall" attribute; arguments as in
13499 struct attribute_spec.handler. */
a4f6c312 13500
91d231cb
JM
13501static tree
13502rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs)
13503 tree *node;
13504 tree name;
13505 tree args ATTRIBUTE_UNUSED;
13506 int flags ATTRIBUTE_UNUSED;
13507 bool *no_add_attrs;
13508{
13509 if (TREE_CODE (*node) != FUNCTION_TYPE
13510 && TREE_CODE (*node) != FIELD_DECL
13511 && TREE_CODE (*node) != TYPE_DECL)
13512 {
13513 warning ("`%s' attribute only applies to functions",
13514 IDENTIFIER_POINTER (name));
13515 *no_add_attrs = true;
13516 }
6a4cee5f 13517
91d231cb 13518 return NULL_TREE;
7509c759
MM
13519}
13520
a5c76ee6
ZW
13521/* Set longcall attributes on all functions declared when
13522 rs6000_default_long_calls is true. */
13523static void
13524rs6000_set_default_type_attributes (type)
13525 tree type;
13526{
13527 if (rs6000_default_long_calls
13528 && (TREE_CODE (type) == FUNCTION_TYPE
13529 || TREE_CODE (type) == METHOD_TYPE))
13530 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
13531 NULL_TREE,
13532 TYPE_ATTRIBUTES (type));
13533}
13534
3cb999d8
DE
13535/* Return a reference suitable for calling a function with the
13536 longcall attribute. */
a4f6c312 13537
6a4cee5f
MM
13538struct rtx_def *
13539rs6000_longcall_ref (call_ref)
13540 rtx call_ref;
13541{
d330fd93 13542 const char *call_name;
6a4cee5f
MM
13543 tree node;
13544
13545 if (GET_CODE (call_ref) != SYMBOL_REF)
13546 return call_ref;
13547
13548 /* System V adds '.' to the internal name, so skip them. */
13549 call_name = XSTR (call_ref, 0);
13550 if (*call_name == '.')
13551 {
13552 while (*call_name == '.')
13553 call_name++;
13554
13555 node = get_identifier (call_name);
39403d82 13556 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
13557 }
13558
13559 return force_reg (Pmode, call_ref);
13560}
7509c759 13561\f
b64a1b53
RH
13562#ifdef USING_ELFOS_H
13563
7509c759
MM
13564/* A C statement or statements to switch to the appropriate section
13565 for output of RTX in mode MODE. You can assume that RTX is some
13566 kind of constant in RTL. The argument MODE is redundant except in
13567 the case of a `const_int' rtx. Select the section by calling
13568 `text_section' or one of the alternatives for other sections.
13569
13570 Do not define this macro if you put all constants in the read-only
13571 data section. */
13572
b64a1b53
RH
13573static void
13574rs6000_elf_select_rtx_section (mode, x, align)
a9098fd0 13575 enum machine_mode mode;
7509c759 13576 rtx x;
b64a1b53 13577 unsigned HOST_WIDE_INT align;
7509c759 13578{
a9098fd0 13579 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 13580 toc_section ();
7509c759 13581 else
b64a1b53 13582 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
13583}
13584
13585/* A C statement or statements to switch to the appropriate
13586 section for output of DECL. DECL is either a `VAR_DECL' node
13587 or a constant of some sort. RELOC indicates whether forming
13588 the initial value of DECL requires link-time relocations. */
13589
ae46c4e0
RH
13590static void
13591rs6000_elf_select_section (decl, reloc, align)
7509c759
MM
13592 tree decl;
13593 int reloc;
0e5dbd9b 13594 unsigned HOST_WIDE_INT align;
7509c759 13595{
f1384257
AM
13596 /* Pretend that we're always building for a shared library when
13597 ABI_AIX, because otherwise we end up with dynamic relocations
13598 in read-only sections. This happens for function pointers,
13599 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
13600 default_elf_select_section_1 (decl, reloc, align,
13601 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
13602}
13603
13604/* A C statement to build up a unique section name, expressed as a
13605 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
13606 RELOC indicates whether the initial value of EXP requires
13607 link-time relocations. If you do not define this macro, GCC will use
13608 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 13609 macro can now be called for uninitialized data items as well as
4912a07c 13610 initialized data and functions. */
63019373 13611
ae46c4e0
RH
13612static void
13613rs6000_elf_unique_section (decl, reloc)
63019373
GK
13614 tree decl;
13615 int reloc;
13616{
f1384257
AM
13617 /* As above, pretend that we're always building for a shared library
13618 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
13619 default_unique_section_1 (decl, reloc,
13620 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 13621}
d9407988 13622\f
d1908feb
JJ
13623/* For a SYMBOL_REF, set generic flags and then perform some
13624 target-specific processing.
13625
d1908feb
JJ
13626 When the AIX ABI is requested on a non-AIX system, replace the
13627 function name with the real name (with a leading .) rather than the
13628 function descriptor name. This saves a lot of overriding code to
13629 read the prefixes. */
d9407988 13630
fb49053f 13631static void
c6a2438a 13632rs6000_elf_encode_section_info (decl, rtl, first)
d9407988 13633 tree decl;
c6a2438a 13634 rtx rtl;
b2003250 13635 int first;
d9407988 13636{
d1908feb 13637 default_encode_section_info (decl, rtl, first);
b2003250 13638
d1908feb
JJ
13639 if (first
13640 && TREE_CODE (decl) == FUNCTION_DECL
13641 && !TARGET_AIX
13642 && DEFAULT_ABI == ABI_AIX)
d9407988 13643 {
c6a2438a 13644 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
13645 size_t len = strlen (XSTR (sym_ref, 0));
13646 char *str = alloca (len + 2);
13647 str[0] = '.';
13648 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
13649 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 13650 }
d9407988
MM
13651}
13652
0e5dbd9b
DE
13653static bool
13654rs6000_elf_in_small_data_p (decl)
13655 tree decl;
13656{
13657 if (rs6000_sdata == SDATA_NONE)
13658 return false;
13659
13660 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
13661 {
13662 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
13663 if (strcmp (section, ".sdata") == 0
13664 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
13665 || strcmp (section, ".sbss") == 0
13666 || strcmp (section, ".sbss2") == 0
13667 || strcmp (section, ".PPC.EMB.sdata0") == 0
13668 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
13669 return true;
13670 }
13671 else
13672 {
13673 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
13674
13675 if (size > 0
307b599c 13676 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
13677 /* If it's not public, and we're not going to reference it there,
13678 there's no need to put it in the small data section. */
0e5dbd9b
DE
13679 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
13680 return true;
13681 }
13682
13683 return false;
13684}
13685
b91da81f 13686#endif /* USING_ELFOS_H */
000034eb 13687
a6c2a102 13688\f
000034eb 13689/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
13690 ADDR can be effectively incremented by incrementing REG.
13691
13692 r0 is special and we must not select it as an address
13693 register by this routine since our caller will try to
13694 increment the returned register via an "la" instruction. */
000034eb
DE
13695
13696struct rtx_def *
13697find_addr_reg (addr)
13698 rtx addr;
13699{
13700 while (GET_CODE (addr) == PLUS)
13701 {
02441cd6
JL
13702 if (GET_CODE (XEXP (addr, 0)) == REG
13703 && REGNO (XEXP (addr, 0)) != 0)
000034eb 13704 addr = XEXP (addr, 0);
02441cd6
JL
13705 else if (GET_CODE (XEXP (addr, 1)) == REG
13706 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
13707 addr = XEXP (addr, 1);
13708 else if (CONSTANT_P (XEXP (addr, 0)))
13709 addr = XEXP (addr, 1);
13710 else if (CONSTANT_P (XEXP (addr, 1)))
13711 addr = XEXP (addr, 0);
13712 else
13713 abort ();
13714 }
02441cd6 13715 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
13716 return addr;
13717 abort ();
13718}
13719
a6c2a102
DE
13720void
13721rs6000_fatal_bad_address (op)
13722 rtx op;
13723{
13724 fatal_insn ("bad address", op);
13725}
c8023011 13726
ee890fe2
SS
13727#if TARGET_MACHO
13728
13729#if 0
13730/* Returns 1 if OP is either a symbol reference or a sum of a symbol
13731 reference and a constant. */
13732
13733int
13734symbolic_operand (op)
592696dd 13735 rtx op;
ee890fe2
SS
13736{
13737 switch (GET_CODE (op))
13738 {
13739 case SYMBOL_REF:
13740 case LABEL_REF:
13741 return 1;
13742 case CONST:
13743 op = XEXP (op, 0);
13744 return (GET_CODE (op) == SYMBOL_REF ||
13745 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
13746 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
13747 && GET_CODE (XEXP (op, 1)) == CONST_INT);
13748 default:
13749 return 0;
13750 }
c8023011 13751}
ee890fe2
SS
13752#endif
13753
13754#ifdef RS6000_LONG_BRANCH
13755
13756static tree stub_list = 0;
13757
13758/* ADD_COMPILER_STUB adds the compiler generated stub for handling
13759 procedure calls to the linked list. */
13760
13761void
13762add_compiler_stub (label_name, function_name, line_number)
13763 tree label_name;
13764 tree function_name;
13765 int line_number;
13766{
13767 tree stub = build_tree_list (function_name, label_name);
13768 TREE_TYPE (stub) = build_int_2 (line_number, 0);
13769 TREE_CHAIN (stub) = stub_list;
13770 stub_list = stub;
13771}
13772
13773#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
13774#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
13775#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
13776
a4f6c312
SS
13777/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
13778 handling procedure calls from the linked list and initializes the
13779 linked list. */
ee890fe2 13780
a4f6c312
SS
13781void
13782output_compiler_stub ()
ee890fe2
SS
13783{
13784 char tmp_buf[256];
13785 char label_buf[256];
308c142a 13786 tree stub;
ee890fe2
SS
13787
13788 if (!flag_pic)
13789 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13790 {
13791 fprintf (asm_out_file,
13792 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
13793
13794#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
13795 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
13796 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
13797#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
13798
13799 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
13800 strcpy (label_buf,
13801 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
13802 else
13803 {
13804 label_buf[0] = '_';
13805 strcpy (label_buf+1,
13806 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
13807 }
13808
13809 strcpy (tmp_buf, "lis r12,hi16(");
13810 strcat (tmp_buf, label_buf);
13811 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
13812 strcat (tmp_buf, label_buf);
13813 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
13814 output_asm_insn (tmp_buf, 0);
13815
13816#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
13817 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
13818 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
13819#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
13820 }
13821
13822 stub_list = 0;
13823}
13824
13825/* NO_PREVIOUS_DEF checks in the link list whether the function name is
13826 already there or not. */
13827
a4f6c312
SS
13828int
13829no_previous_def (function_name)
ee890fe2
SS
13830 tree function_name;
13831{
13832 tree stub;
13833 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13834 if (function_name == STUB_FUNCTION_NAME (stub))
13835 return 0;
13836 return 1;
13837}
13838
13839/* GET_PREV_LABEL gets the label name from the previous definition of
13840 the function. */
13841
a4f6c312
SS
13842tree
13843get_prev_label (function_name)
ee890fe2
SS
13844 tree function_name;
13845{
13846 tree stub;
13847 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13848 if (function_name == STUB_FUNCTION_NAME (stub))
13849 return STUB_LABEL_NAME (stub);
13850 return 0;
13851}
13852
13853/* INSN is either a function call or a millicode call. It may have an
13854 unconditional jump in its delay slot.
13855
13856 CALL_DEST is the routine we are calling. */
13857
13858char *
13859output_call (insn, call_dest, operand_number)
13860 rtx insn;
13861 rtx call_dest;
13862 int operand_number;
13863{
13864 static char buf[256];
13865 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
13866 {
13867 tree labelname;
13868 tree funname = get_identifier (XSTR (call_dest, 0));
13869
13870 if (no_previous_def (funname))
13871 {
308c142a 13872 int line_number = 0;
ee890fe2
SS
13873 rtx label_rtx = gen_label_rtx ();
13874 char *label_buf, temp_buf[256];
13875 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
13876 CODE_LABEL_NUMBER (label_rtx));
13877 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
13878 labelname = get_identifier (label_buf);
13879 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
13880 if (insn)
13881 line_number = NOTE_LINE_NUMBER (insn);
13882 add_compiler_stub (labelname, funname, line_number);
13883 }
13884 else
13885 labelname = get_prev_label (funname);
13886
13887 sprintf (buf, "jbsr %%z%d,%.246s",
13888 operand_number, IDENTIFIER_POINTER (labelname));
13889 return buf;
13890 }
13891 else
13892 {
13893 sprintf (buf, "bl %%z%d", operand_number);
13894 return buf;
13895 }
13896}
13897
13898#endif /* RS6000_LONG_BRANCH */
13899
13900#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
13901 do { \
83182544 13902 const char *const symbol_ = (SYMBOL); \
ee890fe2
SS
13903 char *buffer_ = (BUF); \
13904 if (symbol_[0] == '"') \
13905 { \
13906 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
13907 } \
13908 else if (name_needs_quotes(symbol_)) \
13909 { \
13910 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
13911 } \
13912 else \
13913 { \
13914 sprintf(buffer_, "L%d$%s", (N), symbol_); \
13915 } \
13916 } while (0)
13917
13918
13919/* Generate PIC and indirect symbol stubs. */
13920
13921void
13922machopic_output_stub (file, symb, stub)
13923 FILE *file;
13924 const char *symb, *stub;
13925{
13926 unsigned int length;
a4f6c312
SS
13927 char *symbol_name, *lazy_ptr_name;
13928 char *local_label_0;
ee890fe2
SS
13929 static int label = 0;
13930
df56a27f 13931 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 13932 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 13933
ee890fe2
SS
13934 label += 1;
13935
ee890fe2
SS
13936 length = strlen (symb);
13937 symbol_name = alloca (length + 32);
13938 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
13939
13940 lazy_ptr_name = alloca (length + 32);
13941 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
13942
13943 local_label_0 = alloca (length + 32);
13944 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
13945
ee890fe2 13946 if (flag_pic == 2)
d3c300d2 13947 machopic_picsymbol_stub1_section ();
ee890fe2 13948 else
d3c300d2
DJ
13949 machopic_symbol_stub1_section ();
13950 fprintf (file, "\t.align 2\n");
ee890fe2
SS
13951
13952 fprintf (file, "%s:\n", stub);
13953 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13954
13955 if (flag_pic == 2)
13956 {
13957 fprintf (file, "\tmflr r0\n");
13958 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
13959 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
13960 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
13961 lazy_ptr_name, local_label_0);
13962 fprintf (file, "\tmtlr r0\n");
d3c300d2 13963 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
13964 lazy_ptr_name, local_label_0);
13965 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
13966 fprintf (file, "\tbctr\n");
13967 }
13968 else
ab82a49f
AP
13969 {
13970 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
13971 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
13972 fprintf (file, "\tmtctr r12\n");
13973 fprintf (file, "\tbctr\n");
13974 }
ee890fe2
SS
13975
13976 machopic_lazy_symbol_ptr_section ();
13977 fprintf (file, "%s:\n", lazy_ptr_name);
13978 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13979 fprintf (file, "\t.long dyld_stub_binding_helper\n");
13980}
13981
13982/* Legitimize PIC addresses. If the address is already
13983 position-independent, we return ORIG. Newly generated
13984 position-independent addresses go into a reg. This is REG if non
13985 zero, otherwise we allocate register(s) as necessary. */
13986
c859cda6 13987#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
13988
13989rtx
13990rs6000_machopic_legitimize_pic_address (orig, mode, reg)
13991 rtx orig;
13992 enum machine_mode mode;
13993 rtx reg;
13994{
13995 rtx base, offset;
13996
13997 if (reg == NULL && ! reload_in_progress && ! reload_completed)
13998 reg = gen_reg_rtx (Pmode);
13999
14000 if (GET_CODE (orig) == CONST)
14001 {
14002 if (GET_CODE (XEXP (orig, 0)) == PLUS
14003 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
14004 return orig;
14005
14006 if (GET_CODE (XEXP (orig, 0)) == PLUS)
14007 {
a4f6c312
SS
14008 base =
14009 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
14010 Pmode, reg);
14011 offset =
14012 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
14013 Pmode, reg);
ee890fe2
SS
14014 }
14015 else
14016 abort ();
14017
14018 if (GET_CODE (offset) == CONST_INT)
14019 {
14020 if (SMALL_INT (offset))
ed8908e7 14021 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
14022 else if (! reload_in_progress && ! reload_completed)
14023 offset = force_reg (Pmode, offset);
14024 else
c859cda6
DJ
14025 {
14026 rtx mem = force_const_mem (Pmode, orig);
14027 return machopic_legitimize_pic_address (mem, Pmode, reg);
14028 }
ee890fe2
SS
14029 }
14030 return gen_rtx (PLUS, Pmode, base, offset);
14031 }
14032
14033 /* Fall back on generic machopic code. */
14034 return machopic_legitimize_pic_address (orig, mode, reg);
14035}
14036
14037/* This is just a placeholder to make linking work without having to
14038 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
14039 ever needed for Darwin (not too likely!) this would have to get a
14040 real definition. */
14041
14042void
14043toc_section ()
14044{
14045}
14046
14047#endif /* TARGET_MACHO */
7c262518
RH
14048
14049#if TARGET_ELF
14050static unsigned int
14051rs6000_elf_section_type_flags (decl, name, reloc)
14052 tree decl;
14053 const char *name;
14054 int reloc;
14055{
5add3202
DE
14056 unsigned int flags
14057 = default_section_type_flags_1 (decl, name, reloc,
14058 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 14059
270fc29b
RH
14060 if (TARGET_RELOCATABLE)
14061 flags |= SECTION_WRITE;
7c262518 14062
d0101753 14063 return flags;
7c262518 14064}
d9f6800d
RH
14065
14066/* Record an element in the table of global constructors. SYMBOL is
14067 a SYMBOL_REF of the function to be called; PRIORITY is a number
14068 between 0 and MAX_INIT_PRIORITY.
14069
14070 This differs from default_named_section_asm_out_constructor in
14071 that we have special handling for -mrelocatable. */
14072
14073static void
14074rs6000_elf_asm_out_constructor (symbol, priority)
14075 rtx symbol;
14076 int priority;
14077{
14078 const char *section = ".ctors";
14079 char buf[16];
14080
14081 if (priority != DEFAULT_INIT_PRIORITY)
14082 {
14083 sprintf (buf, ".ctors.%.5u",
14084 /* Invert the numbering so the linker puts us in the proper
14085 order; constructors are run from right to left, and the
14086 linker sorts in increasing order. */
14087 MAX_INIT_PRIORITY - priority);
14088 section = buf;
14089 }
14090
715bdd29
RH
14091 named_section_flags (section, SECTION_WRITE);
14092 assemble_align (POINTER_SIZE);
d9f6800d
RH
14093
14094 if (TARGET_RELOCATABLE)
14095 {
14096 fputs ("\t.long (", asm_out_file);
14097 output_addr_const (asm_out_file, symbol);
14098 fputs (")@fixup\n", asm_out_file);
14099 }
14100 else
c8af3574 14101 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
14102}
14103
14104static void
14105rs6000_elf_asm_out_destructor (symbol, priority)
14106 rtx symbol;
14107 int priority;
14108{
14109 const char *section = ".dtors";
14110 char buf[16];
14111
14112 if (priority != DEFAULT_INIT_PRIORITY)
14113 {
14114 sprintf (buf, ".dtors.%.5u",
14115 /* Invert the numbering so the linker puts us in the proper
14116 order; constructors are run from right to left, and the
14117 linker sorts in increasing order. */
14118 MAX_INIT_PRIORITY - priority);
14119 section = buf;
14120 }
14121
715bdd29
RH
14122 named_section_flags (section, SECTION_WRITE);
14123 assemble_align (POINTER_SIZE);
d9f6800d
RH
14124
14125 if (TARGET_RELOCATABLE)
14126 {
14127 fputs ("\t.long (", asm_out_file);
14128 output_addr_const (asm_out_file, symbol);
14129 fputs (")@fixup\n", asm_out_file);
14130 }
14131 else
c8af3574 14132 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 14133}
9739c90c
JJ
14134
14135void
14136rs6000_elf_declare_function_name (file, name, decl)
14137 FILE *file;
14138 const char *name;
14139 tree decl;
14140{
14141 if (TARGET_64BIT)
14142 {
14143 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
14144 ASM_OUTPUT_LABEL (file, name);
14145 fputs (DOUBLE_INT_ASM_OP, file);
14146 putc ('.', file);
14147 assemble_name (file, name);
14148 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
14149 assemble_name (file, name);
14150 fputs (",24\n\t.type\t.", file);
14151 assemble_name (file, name);
14152 fputs (",@function\n", file);
14153 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
14154 {
14155 fputs ("\t.globl\t.", file);
14156 assemble_name (file, name);
14157 putc ('\n', file);
14158 }
14159 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
14160 putc ('.', file);
14161 ASM_OUTPUT_LABEL (file, name);
14162 return;
14163 }
14164
14165 if (TARGET_RELOCATABLE
14166 && (get_pool_size () != 0 || current_function_profile)
14167 && uses_TOC())
14168 {
14169 char buf[256];
14170
14171 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
14172
14173 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
14174 fprintf (file, "\t.long ");
14175 assemble_name (file, buf);
14176 putc ('-', file);
14177 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
14178 assemble_name (file, buf);
14179 putc ('\n', file);
14180 }
14181
14182 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
14183 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
14184
14185 if (DEFAULT_ABI == ABI_AIX)
14186 {
14187 const char *desc_name, *orig_name;
14188
14189 orig_name = (*targetm.strip_name_encoding) (name);
14190 desc_name = orig_name;
14191 while (*desc_name == '.')
14192 desc_name++;
14193
14194 if (TREE_PUBLIC (decl))
14195 fprintf (file, "\t.globl %s\n", desc_name);
14196
14197 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
14198 fprintf (file, "%s:\n", desc_name);
14199 fprintf (file, "\t.long %s\n", orig_name);
14200 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
14201 if (DEFAULT_ABI == ABI_AIX)
14202 fputs ("\t.long 0\n", file);
14203 fprintf (file, "\t.previous\n");
14204 }
14205 ASM_OUTPUT_LABEL (file, name);
14206}
7c262518
RH
14207#endif
14208
cbaaba19 14209#if TARGET_XCOFF
7c262518 14210static void
b275d088
DE
14211rs6000_xcoff_asm_globalize_label (stream, name)
14212 FILE *stream;
14213 const char *name;
14214{
14215 fputs (GLOBAL_ASM_OP, stream);
14216 RS6000_OUTPUT_BASENAME (stream, name);
14217 putc ('\n', stream);
14218}
14219
14220static void
14221rs6000_xcoff_asm_named_section (name, flags)
7c262518 14222 const char *name;
0e5dbd9b 14223 unsigned int flags;
7c262518 14224{
0e5dbd9b
DE
14225 int smclass;
14226 static const char * const suffix[3] = { "PR", "RO", "RW" };
14227
14228 if (flags & SECTION_CODE)
14229 smclass = 0;
14230 else if (flags & SECTION_WRITE)
14231 smclass = 2;
14232 else
14233 smclass = 1;
14234
5b5198f7 14235 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 14236 (flags & SECTION_CODE) ? "." : "",
5b5198f7 14237 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 14238}
ae46c4e0
RH
14239
14240static void
0e5dbd9b
DE
14241rs6000_xcoff_select_section (decl, reloc, align)
14242 tree decl;
ae46c4e0
RH
14243 int reloc;
14244 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
14245{
5add3202 14246 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 14247 {
0e5dbd9b 14248 if (TREE_PUBLIC (decl))
ae46c4e0
RH
14249 read_only_data_section ();
14250 else
14251 read_only_private_data_section ();
14252 }
14253 else
14254 {
0e5dbd9b 14255 if (TREE_PUBLIC (decl))
ae46c4e0
RH
14256 data_section ();
14257 else
14258 private_data_section ();
14259 }
14260}
14261
14262static void
14263rs6000_xcoff_unique_section (decl, reloc)
14264 tree decl;
772c5265 14265 int reloc ATTRIBUTE_UNUSED;
ae46c4e0
RH
14266{
14267 const char *name;
ae46c4e0 14268
5b5198f7
DE
14269 /* Use select_section for private and uninitialized data. */
14270 if (!TREE_PUBLIC (decl)
14271 || DECL_COMMON (decl)
0e5dbd9b
DE
14272 || DECL_INITIAL (decl) == NULL_TREE
14273 || DECL_INITIAL (decl) == error_mark_node
14274 || (flag_zero_initialized_in_bss
14275 && initializer_zerop (DECL_INITIAL (decl))))
14276 return;
14277
14278 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
14279 name = (*targetm.strip_name_encoding) (name);
14280 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 14281}
b64a1b53 14282
fb49053f
RH
14283/* Select section for constant in constant pool.
14284
14285 On RS/6000, all constants are in the private read-only data area.
14286 However, if this is being placed in the TOC it must be output as a
14287 toc entry. */
14288
b64a1b53
RH
14289static void
14290rs6000_xcoff_select_rtx_section (mode, x, align)
14291 enum machine_mode mode;
14292 rtx x;
14293 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
14294{
14295 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
14296 toc_section ();
14297 else
14298 read_only_private_data_section ();
14299}
772c5265
RH
14300
14301/* Remove any trailing [DS] or the like from the symbol name. */
14302
14303static const char *
14304rs6000_xcoff_strip_name_encoding (name)
14305 const char *name;
14306{
14307 size_t len;
14308 if (*name == '*')
14309 name++;
14310 len = strlen (name);
14311 if (name[len - 1] == ']')
14312 return ggc_alloc_string (name, len - 4);
14313 else
14314 return name;
14315}
14316
5add3202
DE
14317/* Section attributes. AIX is always PIC. */
14318
14319static unsigned int
14320rs6000_xcoff_section_type_flags (decl, name, reloc)
14321 tree decl;
14322 const char *name;
14323 int reloc;
14324{
5b5198f7
DE
14325 unsigned int align;
14326 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
14327
14328 /* Align to at least UNIT size. */
14329 if (flags & SECTION_CODE)
14330 align = MIN_UNITS_PER_WORD;
14331 else
14332 /* Increase alignment of large objects if not already stricter. */
14333 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
14334 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
14335 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
14336
14337 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 14338}
a5fe455b 14339
1bc7c5b6
ZW
14340/* Output at beginning of assembler file.
14341
14342 Initialize the section names for the RS/6000 at this point.
14343
14344 Specify filename, including full path, to assembler.
14345
14346 We want to go into the TOC section so at least one .toc will be emitted.
14347 Also, in order to output proper .bs/.es pairs, we need at least one static
14348 [RW] section emitted.
14349
14350 Finally, declare mcount when profiling to make the assembler happy. */
14351
14352static void
14353rs6000_xcoff_file_start ()
14354{
14355 rs6000_gen_section_name (&xcoff_bss_section_name,
14356 main_input_filename, ".bss_");
14357 rs6000_gen_section_name (&xcoff_private_data_section_name,
14358 main_input_filename, ".rw_");
14359 rs6000_gen_section_name (&xcoff_read_only_section_name,
14360 main_input_filename, ".ro_");
14361
14362 fputs ("\t.file\t", asm_out_file);
14363 output_quoted_string (asm_out_file, main_input_filename);
14364 fputc ('\n', asm_out_file);
14365 toc_section ();
14366 if (write_symbols != NO_DEBUG)
14367 private_data_section ();
14368 text_section ();
14369 if (profile_flag)
14370 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
14371 rs6000_file_start ();
14372}
14373
a5fe455b
ZW
14374/* Output at end of assembler file.
14375 On the RS/6000, referencing data should automatically pull in text. */
14376
14377static void
14378rs6000_xcoff_file_end ()
14379{
14380 text_section ();
14381 fputs ("_section_.text:\n", asm_out_file);
14382 data_section ();
14383 fputs (TARGET_32BIT
14384 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
14385 asm_out_file);
14386}
f1384257 14387#endif /* TARGET_XCOFF */
0e5dbd9b 14388
f1384257
AM
14389#if TARGET_MACHO
14390/* Cross-module name binding. Darwin does not support overriding
7f3d8013 14391 functions at dynamic-link time. */
0e5dbd9b 14392
2bcc50d0 14393static bool
0e5dbd9b
DE
14394rs6000_binds_local_p (decl)
14395 tree decl;
14396{
f1384257 14397 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 14398}
f1384257 14399#endif
34bb030a 14400
3c50106f
RH
14401/* Compute a (partial) cost for rtx X. Return true if the complete
14402 cost has been computed, and false if subexpressions should be
14403 scanned. In either case, *TOTAL contains the cost result. */
14404
14405static bool
14406rs6000_rtx_costs (x, code, outer_code, total)
14407 rtx x;
14408 int code, outer_code ATTRIBUTE_UNUSED;
14409 int *total;
14410{
14411 switch (code)
14412 {
14413 /* On the RS/6000, if it is valid in the insn, it is free.
14414 So this always returns 0. */
14415 case CONST_INT:
14416 case CONST:
14417 case LABEL_REF:
14418 case SYMBOL_REF:
14419 case CONST_DOUBLE:
14420 case HIGH:
14421 *total = 0;
14422 return true;
14423
14424 case PLUS:
14425 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
14426 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
14427 + 0x8000) >= 0x10000)
14428 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
14429 ? COSTS_N_INSNS (2)
14430 : COSTS_N_INSNS (1));
14431 return true;
14432
14433 case AND:
14434 case IOR:
14435 case XOR:
14436 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
14437 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
14438 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
14439 ? COSTS_N_INSNS (2)
14440 : COSTS_N_INSNS (1));
14441 return true;
14442
14443 case MULT:
14444 if (optimize_size)
14445 {
14446 *total = COSTS_N_INSNS (2);
14447 return true;
14448 }
14449 switch (rs6000_cpu)
14450 {
14451 case PROCESSOR_RIOS1:
14452 case PROCESSOR_PPC405:
14453 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14454 ? COSTS_N_INSNS (5)
14455 : (INTVAL (XEXP (x, 1)) >= -256
14456 && INTVAL (XEXP (x, 1)) <= 255)
14457 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
14458 return true;
14459
02ca7595
DE
14460 case PROCESSOR_PPC440:
14461 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14462 ? COSTS_N_INSNS (3)
14463 : COSTS_N_INSNS (2));
14464 return true;
14465
3c50106f
RH
14466 case PROCESSOR_RS64A:
14467 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14468 ? GET_MODE (XEXP (x, 1)) != DImode
14469 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
14470 : (INTVAL (XEXP (x, 1)) >= -256
14471 && INTVAL (XEXP (x, 1)) <= 255)
14472 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
14473 return true;
14474
14475 case PROCESSOR_RIOS2:
14476 case PROCESSOR_MPCCORE:
14477 case PROCESSOR_PPC604e:
14478 *total = COSTS_N_INSNS (2);
14479 return true;
14480
14481 case PROCESSOR_PPC601:
14482 *total = COSTS_N_INSNS (5);
14483 return true;
14484
14485 case PROCESSOR_PPC603:
14486 case PROCESSOR_PPC7400:
14487 case PROCESSOR_PPC750:
14488 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14489 ? COSTS_N_INSNS (5)
14490 : (INTVAL (XEXP (x, 1)) >= -256
14491 && INTVAL (XEXP (x, 1)) <= 255)
14492 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
14493 return true;
14494
14495 case PROCESSOR_PPC7450:
14496 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14497 ? COSTS_N_INSNS (4)
14498 : COSTS_N_INSNS (3));
14499 return true;
14500
14501 case PROCESSOR_PPC403:
14502 case PROCESSOR_PPC604:
14503 case PROCESSOR_PPC8540:
14504 *total = COSTS_N_INSNS (4);
14505 return true;
14506
14507 case PROCESSOR_PPC620:
14508 case PROCESSOR_PPC630:
3c50106f
RH
14509 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14510 ? GET_MODE (XEXP (x, 1)) != DImode
14511 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
14512 : (INTVAL (XEXP (x, 1)) >= -256
14513 && INTVAL (XEXP (x, 1)) <= 255)
14514 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
14515 return true;
14516
9259f3b0
DE
14517 case PROCESSOR_POWER4:
14518 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14519 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
14520 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
14521 : COSTS_N_INSNS (2));
9259f3b0
DE
14522 return true;
14523
3c50106f
RH
14524 default:
14525 abort ();
14526 }
14527
14528 case DIV:
14529 case MOD:
14530 if (GET_CODE (XEXP (x, 1)) == CONST_INT
14531 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
14532 {
14533 *total = COSTS_N_INSNS (2);
14534 return true;
14535 }
14536 /* FALLTHRU */
14537
14538 case UDIV:
14539 case UMOD:
14540 switch (rs6000_cpu)
14541 {
14542 case PROCESSOR_RIOS1:
14543 *total = COSTS_N_INSNS (19);
14544 return true;
14545
14546 case PROCESSOR_RIOS2:
14547 *total = COSTS_N_INSNS (13);
14548 return true;
14549
14550 case PROCESSOR_RS64A:
14551 *total = (GET_MODE (XEXP (x, 1)) != DImode
14552 ? COSTS_N_INSNS (65)
14553 : COSTS_N_INSNS (67));
14554 return true;
14555
14556 case PROCESSOR_MPCCORE:
14557 *total = COSTS_N_INSNS (6);
14558 return true;
14559
14560 case PROCESSOR_PPC403:
14561 *total = COSTS_N_INSNS (33);
14562 return true;
14563
14564 case PROCESSOR_PPC405:
14565 *total = COSTS_N_INSNS (35);
14566 return true;
14567
02ca7595
DE
14568 case PROCESSOR_PPC440:
14569 *total = COSTS_N_INSNS (34);
14570 return true;
14571
3c50106f
RH
14572 case PROCESSOR_PPC601:
14573 *total = COSTS_N_INSNS (36);
14574 return true;
14575
14576 case PROCESSOR_PPC603:
14577 *total = COSTS_N_INSNS (37);
14578 return true;
14579
14580 case PROCESSOR_PPC604:
14581 case PROCESSOR_PPC604e:
14582 *total = COSTS_N_INSNS (20);
14583 return true;
14584
14585 case PROCESSOR_PPC620:
14586 case PROCESSOR_PPC630:
3c50106f
RH
14587 *total = (GET_MODE (XEXP (x, 1)) != DImode
14588 ? COSTS_N_INSNS (21)
14589 : COSTS_N_INSNS (37));
14590 return true;
14591
14592 case PROCESSOR_PPC750:
14593 case PROCESSOR_PPC8540:
14594 case PROCESSOR_PPC7400:
14595 *total = COSTS_N_INSNS (19);
14596 return true;
14597
14598 case PROCESSOR_PPC7450:
14599 *total = COSTS_N_INSNS (23);
14600 return true;
984e25ac
DE
14601
14602 case PROCESSOR_POWER4:
14603 *total = (GET_MODE (XEXP (x, 1)) != DImode
14604 ? COSTS_N_INSNS (18)
14605 : COSTS_N_INSNS (34));
14606 return true;
3c50106f
RH
14607
14608 default:
14609 abort ();
14610 }
14611
14612 case FFS:
14613 *total = COSTS_N_INSNS (4);
14614 return true;
14615
14616 case MEM:
14617 /* MEM should be slightly more expensive than (plus (reg) (const)) */
14618 *total = 5;
14619 return true;
14620
14621 default:
14622 return false;
14623 }
14624}
14625
34bb030a
DE
14626/* A C expression returning the cost of moving data from a register of class
14627 CLASS1 to one of CLASS2. */
14628
14629int
14630rs6000_register_move_cost (mode, from, to)
14631 enum machine_mode mode;
14632 enum reg_class from, to;
14633{
14634 /* Moves from/to GENERAL_REGS. */
14635 if (reg_classes_intersect_p (to, GENERAL_REGS)
14636 || reg_classes_intersect_p (from, GENERAL_REGS))
14637 {
14638 if (! reg_classes_intersect_p (to, GENERAL_REGS))
14639 from = to;
14640
14641 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
14642 return (rs6000_memory_move_cost (mode, from, 0)
14643 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
14644
14645/* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/
14646 else if (from == CR_REGS)
14647 return 4;
14648
14649 else
14650/* A move will cost one instruction per GPR moved. */
14651 return 2 * HARD_REGNO_NREGS (0, mode);
14652 }
14653
14654/* Moving between two similar registers is just one instruction. */
14655 else if (reg_classes_intersect_p (to, from))
14656 return mode == TFmode ? 4 : 2;
14657
14658/* Everything else has to go through GENERAL_REGS. */
14659 else
14660 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
14661 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
14662}
14663
14664/* A C expressions returning the cost of moving data of MODE from a register to
14665 or from memory. */
14666
14667int
14668rs6000_memory_move_cost (mode, class, in)
14669 enum machine_mode mode;
14670 enum reg_class class;
14671 int in ATTRIBUTE_UNUSED;
14672{
14673 if (reg_classes_intersect_p (class, GENERAL_REGS))
14674 return 4 * HARD_REGNO_NREGS (0, mode);
14675 else if (reg_classes_intersect_p (class, FLOAT_REGS))
14676 return 4 * HARD_REGNO_NREGS (32, mode);
14677 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
14678 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
14679 else
14680 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
14681}
14682
ded9bf77
AH
14683/* Return an RTX representing where to find the function value of a
14684 function returning MODE. */
14685static rtx
14686rs6000_complex_function_value (enum machine_mode mode)
14687{
14688 unsigned int regno;
14689 rtx r1, r2;
14690 enum machine_mode inner = GET_MODE_INNER (mode);
14691
14692 if (FLOAT_MODE_P (mode))
14693 regno = FP_ARG_RETURN;
14694 else
14695 {
14696 regno = GP_ARG_RETURN;
14697
14698 /* 32-bit is OK since it'll go in r3/r4. */
165848da
AH
14699 if (TARGET_32BIT
14700 && GET_MODE_BITSIZE (inner) >= 32)
ded9bf77
AH
14701 return gen_rtx_REG (mode, regno);
14702 }
14703
14704 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
14705 const0_rtx);
14706 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
14707 GEN_INT (GET_MODE_UNIT_SIZE (inner)));
14708 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
14709}
14710
a6ebc39a
AH
14711/* Define how to find the value returned by a function.
14712 VALTYPE is the data type of the value (as a tree).
14713 If the precise function being called is known, FUNC is its FUNCTION_DECL;
14714 otherwise, FUNC is 0.
14715
14716 On the SPE, both FPs and vectors are returned in r3.
14717
14718 On RS/6000 an integer value is in r3 and a floating-point value is in
14719 fp1, unless -msoft-float. */
14720
14721rtx
14722rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
14723{
14724 enum machine_mode mode;
2a8fa26c 14725 unsigned int regno;
a6ebc39a
AH
14726
14727 if ((INTEGRAL_TYPE_P (valtype)
14728 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
14729 || POINTER_TYPE_P (valtype))
14730 mode = word_mode;
14731 else
14732 mode = TYPE_MODE (valtype);
14733
2a8fa26c
DE
14734 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
14735 regno = FP_ARG_RETURN;
ded9bf77
AH
14736 else if (TREE_CODE (valtype) == COMPLEX_TYPE
14737 && TARGET_HARD_FLOAT
14738 && SPLIT_COMPLEX_ARGS)
14739 return rs6000_complex_function_value (mode);
2a8fa26c 14740 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
14741 regno = ALTIVEC_ARG_RETURN;
14742 else
14743 regno = GP_ARG_RETURN;
14744
14745 return gen_rtx_REG (mode, regno);
14746}
14747
ded9bf77
AH
14748/* Define how to find the value returned by a library function
14749 assuming the value has mode MODE. */
14750rtx
14751rs6000_libcall_value (enum machine_mode mode)
14752{
14753 unsigned int regno;
14754
14755 if (GET_MODE_CLASS (mode) == MODE_FLOAT
14756 && TARGET_HARD_FLOAT && TARGET_FPRS)
14757 regno = FP_ARG_RETURN;
14758 else if (ALTIVEC_VECTOR_MODE (mode))
14759 regno = ALTIVEC_ARG_RETURN;
14760 else if (COMPLEX_MODE_P (mode) && SPLIT_COMPLEX_ARGS)
14761 return rs6000_complex_function_value (mode);
14762 else
14763 regno = GP_ARG_RETURN;
14764
14765 return gen_rtx_REG (mode, regno);
14766}
14767
62e1dfcf
NC
14768/* Return true if TYPE is of type __ev64_opaque__. */
14769
c8e4f0e9 14770static bool
62e1dfcf
NC
14771is_ev64_opaque_type (type)
14772 tree type;
14773{
c8e4f0e9 14774 return (TARGET_SPE
2abe3e28
AH
14775 && (type == opaque_V2SI_type_node
14776 || type == opaque_V2SF_type_node
36252949 14777 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
14778}
14779
96714395
AH
14780static rtx
14781rs6000_dwarf_register_span (reg)
14782 rtx reg;
14783{
14784 unsigned regno;
14785
14786 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
14787 return NULL_RTX;
14788
14789 regno = REGNO (reg);
14790
14791 /* The duality of the SPE register size wreaks all kinds of havoc.
14792 This is a way of distinguishing r0 in 32-bits from r0 in
14793 64-bits. */
14794 return
14795 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
14796 BYTES_BIG_ENDIAN
14797 ? gen_rtvec (2,
14798 gen_rtx_REG (SImode, regno + 1200),
14799 gen_rtx_REG (SImode, regno))
14800 : gen_rtvec (2,
14801 gen_rtx_REG (SImode, regno),
14802 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
14803}
14804
17211ab5 14805#include "gt-rs6000.h"