]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
re PR libstdc++/11740 (ctype<wchar_t>::do_is(mask, wchar_t) doesn't handle multiple...
[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"
c15c90bb 40#include "libfuncs.h"
2a430ec1 41#include "except.h"
a7df97e6 42#include "function.h"
296b8152 43#include "output.h"
d5fa86ba 44#include "basic-block.h"
d0101753 45#include "integrate.h"
296b8152 46#include "toplev.h"
c8023011 47#include "ggc.h"
9ebbca7d
GK
48#include "hashtab.h"
49#include "tm_p.h"
672a6f42
NB
50#include "target.h"
51#include "target-def.h"
3ac88239 52#include "langhooks.h"
24ea750e 53#include "reload.h"
117dca74 54#include "cfglayout.h"
1bc7c5b6
ZW
55#if TARGET_XCOFF
56#include "xcoffout.h" /* get declarations of xcoff_*_section_name */
57#endif
9b30bae2 58
7509c759
MM
59#ifndef TARGET_NO_PROTOTYPE
60#define TARGET_NO_PROTOTYPE 0
61#endif
62
d744e06e
AH
63#define EASY_VECTOR_15(n, x, y) ((n) >= -16 && (n) <= 15 \
64 && easy_vector_same (x, y))
65
66#define EASY_VECTOR_15_ADD_SELF(n, x, y) ((n) >= 0x10 && (n) <= 0x1e \
67 && !((n) & 1) \
68 && easy_vector_same (x, y))
69
9878760c
RK
70#define min(A,B) ((A) < (B) ? (A) : (B))
71#define max(A,B) ((A) > (B) ? (A) : (B))
72
5248c961
RK
73/* Target cpu type */
74
75enum processor_type rs6000_cpu;
8e3f41e7
MM
76struct rs6000_cpu_select rs6000_select[3] =
77{
815cdc52
MM
78 /* switch name, tune arch */
79 { (const char *)0, "--with-cpu=", 1, 1 },
80 { (const char *)0, "-mcpu=", 1, 1 },
81 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 82};
5248c961 83
6fa3f289
ZW
84/* Size of long double */
85const char *rs6000_long_double_size_string;
86int rs6000_long_double_type_size;
87
88/* Whether -mabi=altivec has appeared */
89int rs6000_altivec_abi;
90
08b57fb3
AH
91/* Whether VRSAVE instructions should be generated. */
92int rs6000_altivec_vrsave;
93
94/* String from -mvrsave= option. */
95const char *rs6000_altivec_vrsave_string;
96
a3170dc6
AH
97/* Nonzero if we want SPE ABI extensions. */
98int rs6000_spe_abi;
99
100/* Whether isel instructions should be generated. */
101int rs6000_isel;
102
993f19a8
AH
103/* Whether SPE simd instructions should be generated. */
104int rs6000_spe;
105
5da702b1
AH
106/* Nonzero if floating point operations are done in the GPRs. */
107int rs6000_float_gprs = 0;
108
109/* String from -mfloat-gprs=. */
110const char *rs6000_float_gprs_string;
a3170dc6
AH
111
112/* String from -misel=. */
113const char *rs6000_isel_string;
114
993f19a8
AH
115/* String from -mspe=. */
116const char *rs6000_spe_string;
117
a0ab749a 118/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 119static GTY(()) int common_mode_defined;
c81bebd7 120
9878760c
RK
121/* Save information from a "cmpxx" operation until the branch or scc is
122 emitted. */
9878760c
RK
123rtx rs6000_compare_op0, rs6000_compare_op1;
124int rs6000_compare_fp_p;
874a0744 125
874a0744
MM
126/* Label number of label created for -mrelocatable, to call to so we can
127 get the address of the GOT section */
128int rs6000_pic_labelno;
c81bebd7 129
b91da81f 130#ifdef USING_ELFOS_H
c81bebd7 131/* Which abi to adhere to */
9739c90c 132const char *rs6000_abi_name;
d9407988
MM
133
134/* Semantics of the small data area */
135enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
136
137/* Which small data model to use */
815cdc52 138const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
139
140/* Counter for labels which are to be placed in .fixup. */
141int fixuplabelno = 0;
874a0744 142#endif
4697a36c 143
c4501e62
JJ
144/* Bit size of immediate TLS offsets and string from which it is decoded. */
145int rs6000_tls_size = 32;
146const char *rs6000_tls_size_string;
147
b6c9286a
MM
148/* ABI enumeration available for subtarget to use. */
149enum rs6000_abi rs6000_current_abi;
150
0ac081f6
AH
151/* ABI string from -mabi= option. */
152const char *rs6000_abi_string;
153
38c1f2d7 154/* Debug flags */
815cdc52 155const char *rs6000_debug_name;
38c1f2d7
MM
156int rs6000_debug_stack; /* debug stack applications */
157int rs6000_debug_arg; /* debug argument handling */
158
6035d635 159/* Opaque types. */
2abe3e28 160static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 161static GTY(()) tree opaque_V2SF_type_node;
6035d635 162static GTY(()) tree opaque_p_V2SI_type_node;
2abe3e28 163
57ac7be9
AM
164const char *rs6000_traceback_name;
165static enum {
166 traceback_default = 0,
167 traceback_none,
168 traceback_part,
169 traceback_full
170} rs6000_traceback;
171
38c1f2d7
MM
172/* Flag to say the TOC is initialized */
173int toc_initialized;
9ebbca7d 174char toc_label_name[10];
38c1f2d7 175
9ebbca7d
GK
176/* Alias set for saves and restores from the rs6000 stack. */
177static int rs6000_sr_alias_set;
c8023011 178
a5c76ee6
ZW
179/* Call distance, overridden by -mlongcall and #pragma longcall(1).
180 The only place that looks at this is rs6000_set_default_type_attributes;
181 everywhere else should rely on the presence or absence of a longcall
182 attribute on the function declaration. */
183int rs6000_default_long_calls;
184const char *rs6000_longcall_switch;
185
025d9908
KH
186/* Control alignment for fields within structures. */
187/* String from -malign-XXXXX. */
188const char *rs6000_alignment_string;
189int rs6000_alignment_flags;
190
a3170dc6
AH
191struct builtin_description
192{
193 /* mask is not const because we're going to alter it below. This
194 nonsense will go away when we rewrite the -march infrastructure
195 to give us more target flag bits. */
196 unsigned int mask;
197 const enum insn_code icode;
198 const char *const name;
199 const enum rs6000_builtins code;
200};
201
a2369ed3
DJ
202static bool rs6000_function_ok_for_sibcall (tree, tree);
203static int num_insns_constant_wide (HOST_WIDE_INT);
204static void validate_condition_mode (enum rtx_code, enum machine_mode);
205static rtx rs6000_generate_compare (enum rtx_code);
206static void rs6000_maybe_dead (rtx);
207static void rs6000_emit_stack_tie (void);
208static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
209static rtx spe_synthesize_frame_save (rtx);
210static bool spe_func_has_64bit_regs_p (void);
211static void emit_frame_save (rtx, rtx, enum machine_mode,
212 unsigned int, int, int);
213static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
214static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
215static unsigned rs6000_hash_constant (rtx);
216static unsigned toc_hash_function (const void *);
217static int toc_hash_eq (const void *, const void *);
218static int constant_pool_expr_1 (rtx, int *, int *);
219static bool constant_pool_expr_p (rtx);
220static bool toc_relative_expr_p (rtx);
221static bool legitimate_small_data_p (enum machine_mode, rtx);
222static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
223static bool legitimate_indexed_address_p (rtx, int);
224static bool legitimate_indirect_address_p (rtx, int);
225static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
226static struct machine_function * rs6000_init_machine_status (void);
227static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 228#ifdef HAVE_GAS_HIDDEN
a2369ed3 229static void rs6000_assemble_visibility (tree, int);
5add3202 230#endif
a2369ed3
DJ
231static int rs6000_ra_ever_killed (void);
232static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
b86fe7b4 233extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
234static void rs6000_set_default_type_attributes (tree);
235static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
236static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
237static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
238 HOST_WIDE_INT, tree);
239static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
240static void rs6000_file_start (void);
7c262518 241#if TARGET_ELF
a2369ed3
DJ
242static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
243static void rs6000_elf_asm_out_constructor (rtx, int);
244static void rs6000_elf_asm_out_destructor (rtx, int);
245static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
246static void rs6000_elf_unique_section (tree, int);
247static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
248 unsigned HOST_WIDE_INT);
a56d7372 249static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 250 ATTRIBUTE_UNUSED;
a2369ed3 251static bool rs6000_elf_in_small_data_p (tree);
7c262518 252#endif
cbaaba19 253#if TARGET_XCOFF
a2369ed3
DJ
254static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
255static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
256static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
257static void rs6000_xcoff_unique_section (tree, int);
258static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
259 unsigned HOST_WIDE_INT);
260static const char * rs6000_xcoff_strip_name_encoding (const char *);
261static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
262static void rs6000_xcoff_file_start (void);
263static void rs6000_xcoff_file_end (void);
f1384257
AM
264#endif
265#if TARGET_MACHO
a2369ed3 266static bool rs6000_binds_local_p (tree);
f1384257 267#endif
a2369ed3
DJ
268static int rs6000_use_dfa_pipeline_interface (void);
269static int rs6000_variable_issue (FILE *, int, rtx, int);
270static bool rs6000_rtx_costs (rtx, int, int, int *);
271static int rs6000_adjust_cost (rtx, rtx, rtx, int);
272static int rs6000_adjust_priority (rtx, int);
273static int rs6000_issue_rate (void);
274static int rs6000_use_sched_lookahead (void);
275
276static void rs6000_init_builtins (void);
277static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
278static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
279static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
280static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
281static void altivec_init_builtins (void);
282static void rs6000_common_init_builtins (void);
c15c90bb 283static void rs6000_init_libfuncs (void);
a2369ed3
DJ
284
285static void enable_mask_for_builtins (struct builtin_description *,
a3170dc6 286 int, enum rs6000_builtins,
a2369ed3
DJ
287 enum rs6000_builtins);
288static void spe_init_builtins (void);
289static rtx spe_expand_builtin (tree, rtx, bool *);
290static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
291static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
292static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
293
294static rtx altivec_expand_builtin (tree, rtx, bool *);
295static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
296static rtx altivec_expand_st_builtin (tree, rtx, bool *);
297static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
298static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
299static rtx altivec_expand_predicate_builtin (enum insn_code,
300 const char *, tree, rtx);
301static rtx altivec_expand_stv_builtin (enum insn_code, tree);
302static void rs6000_parse_abi_options (void);
303static void rs6000_parse_alignment_option (void);
304static void rs6000_parse_tls_size_option (void);
5da702b1 305static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
306static int first_altivec_reg_to_save (void);
307static unsigned int compute_vrsave_mask (void);
308static void is_altivec_return_reg (rtx, void *);
309static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
310int easy_vector_constant (rtx, enum machine_mode);
311static int easy_vector_same (rtx, enum machine_mode);
312static bool is_ev64_opaque_type (tree);
313static rtx rs6000_dwarf_register_span (rtx);
314static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
315static rtx rs6000_tls_get_addr (void);
316static rtx rs6000_got_sym (void);
317static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
318static const char *rs6000_get_some_local_dynamic_name (void);
319static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 320static rtx rs6000_complex_function_value (enum machine_mode);
a2369ed3
DJ
321static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
322 enum machine_mode, tree);
17211ab5
GK
323
324/* Hash table stuff for keeping track of TOC entries. */
325
326struct toc_hash_struct GTY(())
327{
328 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
329 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
330 rtx key;
331 enum machine_mode key_mode;
332 int labelno;
333};
334
335static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
336\f
337/* Default register names. */
338char rs6000_reg_names[][8] =
339{
802a0058
MM
340 "0", "1", "2", "3", "4", "5", "6", "7",
341 "8", "9", "10", "11", "12", "13", "14", "15",
342 "16", "17", "18", "19", "20", "21", "22", "23",
343 "24", "25", "26", "27", "28", "29", "30", "31",
344 "0", "1", "2", "3", "4", "5", "6", "7",
345 "8", "9", "10", "11", "12", "13", "14", "15",
346 "16", "17", "18", "19", "20", "21", "22", "23",
347 "24", "25", "26", "27", "28", "29", "30", "31",
348 "mq", "lr", "ctr","ap",
349 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
350 "xer",
351 /* AltiVec registers. */
0cd5e3a1
AH
352 "0", "1", "2", "3", "4", "5", "6", "7",
353 "8", "9", "10", "11", "12", "13", "14", "15",
354 "16", "17", "18", "19", "20", "21", "22", "23",
355 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
356 "vrsave", "vscr",
357 /* SPE registers. */
358 "spe_acc", "spefscr"
c81bebd7
MM
359};
360
361#ifdef TARGET_REGNAMES
8b60264b 362static const char alt_reg_names[][8] =
c81bebd7 363{
802a0058
MM
364 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
365 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
366 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
367 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
368 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
369 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
370 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
371 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
372 "mq", "lr", "ctr", "ap",
373 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 374 "xer",
59a4c851 375 /* AltiVec registers. */
0ac081f6 376 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
377 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
378 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
379 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
380 "vrsave", "vscr",
381 /* SPE registers. */
382 "spe_acc", "spefscr"
c81bebd7
MM
383};
384#endif
9878760c 385\f
daf11973
MM
386#ifndef MASK_STRICT_ALIGN
387#define MASK_STRICT_ALIGN 0
388#endif
ffcfcb5f
AM
389#ifndef TARGET_PROFILE_KERNEL
390#define TARGET_PROFILE_KERNEL 0
391#endif
3961e8fe
RH
392
393/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
394#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
395
396/* Return 1 for a symbol ref for a thread-local storage symbol. */
397#define RS6000_SYMBOL_REF_TLS_P(RTX) \
398 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
399\f
400/* Initialize the GCC target structure. */
91d231cb
JM
401#undef TARGET_ATTRIBUTE_TABLE
402#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
403#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
404#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 405
301d03af
RS
406#undef TARGET_ASM_ALIGNED_DI_OP
407#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
408
409/* Default unaligned ops are only provided for ELF. Find the ops needed
410 for non-ELF systems. */
411#ifndef OBJECT_FORMAT_ELF
cbaaba19 412#if TARGET_XCOFF
ae6c1efd 413/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
414 64-bit targets. */
415#undef TARGET_ASM_UNALIGNED_HI_OP
416#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
417#undef TARGET_ASM_UNALIGNED_SI_OP
418#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
419#undef TARGET_ASM_UNALIGNED_DI_OP
420#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
421#else
422/* For Darwin. */
423#undef TARGET_ASM_UNALIGNED_HI_OP
424#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
425#undef TARGET_ASM_UNALIGNED_SI_OP
426#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
427#endif
428#endif
429
430/* This hook deals with fixups for relocatable code and DI-mode objects
431 in 64-bit code. */
432#undef TARGET_ASM_INTEGER
433#define TARGET_ASM_INTEGER rs6000_assemble_integer
434
93638d7a
AM
435#ifdef HAVE_GAS_HIDDEN
436#undef TARGET_ASM_ASSEMBLE_VISIBILITY
437#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
438#endif
439
c4501e62
JJ
440#undef TARGET_HAVE_TLS
441#define TARGET_HAVE_TLS HAVE_AS_TLS
442
443#undef TARGET_CANNOT_FORCE_CONST_MEM
444#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
445
08c148a8
NB
446#undef TARGET_ASM_FUNCTION_PROLOGUE
447#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
448#undef TARGET_ASM_FUNCTION_EPILOGUE
449#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
450
b54cf83a
DE
451#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
452#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
453#undef TARGET_SCHED_VARIABLE_ISSUE
454#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
455
c237e94a
ZW
456#undef TARGET_SCHED_ISSUE_RATE
457#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
458#undef TARGET_SCHED_ADJUST_COST
459#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
460#undef TARGET_SCHED_ADJUST_PRIORITY
461#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
462
be12c2b0
VM
463#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
464#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
465
0ac081f6
AH
466#undef TARGET_INIT_BUILTINS
467#define TARGET_INIT_BUILTINS rs6000_init_builtins
468
469#undef TARGET_EXPAND_BUILTIN
470#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
471
c15c90bb
ZW
472#undef TARGET_INIT_LIBFUNCS
473#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
474
f1384257 475#if TARGET_MACHO
0e5dbd9b
DE
476#undef TARGET_BINDS_LOCAL_P
477#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 478#endif
0e5dbd9b 479
3961e8fe
RH
480#undef TARGET_ASM_OUTPUT_MI_THUNK
481#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
482
3961e8fe 483#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 484#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 485
4977bab6
ZW
486#undef TARGET_FUNCTION_OK_FOR_SIBCALL
487#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
488
3c50106f
RH
489#undef TARGET_RTX_COSTS
490#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
491#undef TARGET_ADDRESS_COST
492#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 493
c8e4f0e9
AH
494#undef TARGET_VECTOR_OPAQUE_P
495#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 496
96714395
AH
497#undef TARGET_DWARF_REGISTER_SPAN
498#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
499
f6897b10 500struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 501\f
5248c961
RK
502/* Override command line options. Mostly we process the processor
503 type and sometimes adjust other TARGET_ options. */
504
505void
d779d0dc 506rs6000_override_options (const char *default_cpu)
5248c961 507{
c4d38ccb 508 size_t i, j;
8e3f41e7 509 struct rs6000_cpu_select *ptr;
5248c961 510
85638c0d
RK
511 /* Simplify the entries below by making a mask for any POWER
512 variant and any PowerPC variant. */
513
938937d8 514#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
515#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
516 | MASK_PPC_GFXOPT | MASK_POWERPC64)
517#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 518
5248c961
RK
519 static struct ptt
520 {
8b60264b
KG
521 const char *const name; /* Canonical processor name. */
522 const enum processor_type processor; /* Processor type enum value. */
523 const int target_enable; /* Target flags to enable. */
524 const int target_disable; /* Target flags to disable. */
525 } const processor_target_table[]
cf27b467
MM
526 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
527 POWER_MASKS | POWERPC_MASKS},
db7f1e43 528 {"power", PROCESSOR_POWER,
938937d8 529 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 530 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
531 {"power2", PROCESSOR_POWER,
532 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
533 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
534 {"power3", PROCESSOR_PPC630,
535 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 536 POWER_MASKS},
309323c2 537 {"power4", PROCESSOR_POWER4,
7f3d8013 538 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a12f8290 539 POWER_MASKS},
db7f1e43
RK
540 {"powerpc", PROCESSOR_POWERPC,
541 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 542 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
543 {"powerpc64", PROCESSOR_POWERPC64,
544 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
545 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 546 {"rios", PROCESSOR_RIOS1,
938937d8 547 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
548 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
549 {"rios1", PROCESSOR_RIOS1,
938937d8 550 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
551 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
552 {"rsc", PROCESSOR_PPC601,
938937d8 553 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
554 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
555 {"rsc1", PROCESSOR_PPC601,
938937d8 556 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
557 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
558 {"rios2", PROCESSOR_RIOS2,
938937d8 559 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 560 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
561 {"rs64a", PROCESSOR_RS64A,
562 MASK_POWERPC | MASK_NEW_MNEMONICS,
563 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
564 {"401", PROCESSOR_PPC403,
565 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
566 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 567 {"403", PROCESSOR_PPC403,
daf11973 568 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 569 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
570 {"405", PROCESSOR_PPC405,
571 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
572 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
02ca7595
DE
573 {"405fp", PROCESSOR_PPC405,
574 MASK_POWERPC | MASK_NEW_MNEMONICS,
575 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
576 {"440", PROCESSOR_PPC440,
577 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
578 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
579 {"440fp", PROCESSOR_PPC440,
4977bab6
ZW
580 MASK_POWERPC | MASK_NEW_MNEMONICS,
581 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
582 {"505", PROCESSOR_MPCCORE,
583 MASK_POWERPC | MASK_NEW_MNEMONICS,
584 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 585 {"601", PROCESSOR_PPC601,
938937d8 586 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 587 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 588 {"602", PROCESSOR_PPC603,
cf27b467
MM
589 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
590 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 591 {"603", PROCESSOR_PPC603,
68c49ffa
RK
592 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
593 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
594 {"603e", PROCESSOR_PPC603,
595 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
596 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 597 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
598 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
599 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 600 {"604", PROCESSOR_PPC604,
b6c9286a
MM
601 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
602 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 603 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
604 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
605 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 606 {"620", PROCESSOR_PPC620,
68c49ffa 607 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 608 POWER_MASKS},
3cb999d8
DE
609 {"630", PROCESSOR_PPC630,
610 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 611 POWER_MASKS},
bef84347
VM
612 {"740", PROCESSOR_PPC750,
613 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
614 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
615 {"750", PROCESSOR_PPC750,
616 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
617 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
618 {"7400", PROCESSOR_PPC7400,
619 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
620 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
621 {"7450", PROCESSOR_PPC7450,
622 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
623 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a3170dc6
AH
624 {"8540", PROCESSOR_PPC8540,
625 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
626 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
627 {"801", PROCESSOR_MPCCORE,
628 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
629 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
630 {"821", PROCESSOR_MPCCORE,
631 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
632 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
633 {"823", PROCESSOR_MPCCORE,
634 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
635 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
636 {"860", PROCESSOR_MPCCORE,
637 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
7177e720
DE
638 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
639 {"970", PROCESSOR_POWER4,
640 MASK_POWERPC | POWERPC_OPT_MASKS | MASK_NEW_MNEMONICS,
641 POWER_MASKS}};
5248c961 642
ca7558fc 643 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 644
a4f6c312
SS
645 /* Save current -mmultiple/-mno-multiple status. */
646 int multiple = TARGET_MULTIPLE;
647 /* Save current -mstring/-mno-string status. */
648 int string = TARGET_STRING;
8a61d227 649
a4f6c312 650 /* Identify the processor type. */
8e3f41e7 651 rs6000_select[0].string = default_cpu;
3cb999d8 652 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 653
b6a1cbae 654 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 655 {
8e3f41e7
MM
656 ptr = &rs6000_select[i];
657 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 658 {
8e3f41e7
MM
659 for (j = 0; j < ptt_size; j++)
660 if (! strcmp (ptr->string, processor_target_table[j].name))
661 {
662 if (ptr->set_tune_p)
663 rs6000_cpu = processor_target_table[j].processor;
664
665 if (ptr->set_arch_p)
666 {
667 target_flags |= processor_target_table[j].target_enable;
668 target_flags &= ~processor_target_table[j].target_disable;
669 }
670 break;
671 }
672
4406229e 673 if (j == ptt_size)
8e3f41e7 674 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
675 }
676 }
8a61d227 677
993f19a8 678 if (TARGET_E500)
a3170dc6
AH
679 rs6000_isel = 1;
680
dff9f1b6
DE
681 /* If we are optimizing big endian systems for space, use the load/store
682 multiple and string instructions. */
ef792183 683 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 684 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 685
8a61d227
MM
686 /* If -mmultiple or -mno-multiple was explicitly used, don't
687 override with the processor default */
b21fb038 688 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 689 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 690
a4f6c312
SS
691 /* If -mstring or -mno-string was explicitly used, don't override
692 with the processor default. */
b21fb038 693 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 694 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 695
a4f6c312
SS
696 /* Don't allow -mmultiple or -mstring on little endian systems
697 unless the cpu is a 750, because the hardware doesn't support the
698 instructions used in little endian mode, and causes an alignment
699 trap. The 750 does not cause an alignment trap (except when the
700 target is unaligned). */
bef84347 701
b21fb038 702 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
703 {
704 if (TARGET_MULTIPLE)
705 {
706 target_flags &= ~MASK_MULTIPLE;
b21fb038 707 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
708 warning ("-mmultiple is not supported on little endian systems");
709 }
710
711 if (TARGET_STRING)
712 {
713 target_flags &= ~MASK_STRING;
b21fb038 714 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 715 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
716 }
717 }
3933e0e1 718
38c1f2d7
MM
719 /* Set debug flags */
720 if (rs6000_debug_name)
721 {
bfc79d3b 722 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 723 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 724 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 725 rs6000_debug_stack = 1;
bfc79d3b 726 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
727 rs6000_debug_arg = 1;
728 else
c725bd79 729 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
730 }
731
57ac7be9
AM
732 if (rs6000_traceback_name)
733 {
734 if (! strncmp (rs6000_traceback_name, "full", 4))
735 rs6000_traceback = traceback_full;
736 else if (! strncmp (rs6000_traceback_name, "part", 4))
737 rs6000_traceback = traceback_part;
738 else if (! strncmp (rs6000_traceback_name, "no", 2))
739 rs6000_traceback = traceback_none;
740 else
741 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
742 rs6000_traceback_name);
743 }
744
6fa3f289
ZW
745 /* Set size of long double */
746 rs6000_long_double_type_size = 64;
747 if (rs6000_long_double_size_string)
748 {
749 char *tail;
750 int size = strtol (rs6000_long_double_size_string, &tail, 10);
751 if (*tail != '\0' || (size != 64 && size != 128))
752 error ("Unknown switch -mlong-double-%s",
753 rs6000_long_double_size_string);
754 else
755 rs6000_long_double_type_size = size;
756 }
757
0ac081f6
AH
758 /* Handle -mabi= options. */
759 rs6000_parse_abi_options ();
760
025d9908
KH
761 /* Handle -malign-XXXXX option. */
762 rs6000_parse_alignment_option ();
763
5da702b1
AH
764 /* Handle generic -mFOO=YES/NO options. */
765 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
766 &rs6000_altivec_vrsave);
767 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
768 &rs6000_isel);
769 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
770 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
771 &rs6000_float_gprs);
993f19a8 772
c4501e62
JJ
773 /* Handle -mtls-size option. */
774 rs6000_parse_tls_size_option ();
775
a7ae18e2
AH
776#ifdef SUBTARGET_OVERRIDE_OPTIONS
777 SUBTARGET_OVERRIDE_OPTIONS;
778#endif
779#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
780 SUBSUBTARGET_OVERRIDE_OPTIONS;
781#endif
782
5da702b1
AH
783 if (TARGET_E500)
784 {
785 /* The e500 does not have string instructions, and we set
786 MASK_STRING above when optimizing for size. */
787 if ((target_flags & MASK_STRING) != 0)
788 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
789
790 /* No SPE means 64-bit long doubles, even if an E500. */
791 if (rs6000_spe_string != 0
792 && !strcmp (rs6000_spe_string, "no"))
793 rs6000_long_double_type_size = 64;
5da702b1
AH
794 }
795 else if (rs6000_select[1].string != NULL)
796 {
797 /* For the powerpc-eabispe configuration, we set all these by
798 default, so let's unset them if we manually set another
799 CPU that is not the E500. */
800 if (rs6000_abi_string == 0)
801 rs6000_spe_abi = 0;
802 if (rs6000_spe_string == 0)
803 rs6000_spe = 0;
804 if (rs6000_float_gprs_string == 0)
805 rs6000_float_gprs = 0;
806 if (rs6000_isel_string == 0)
807 rs6000_isel = 0;
b6e59a3a
AH
808 if (rs6000_long_double_size_string == 0)
809 rs6000_long_double_type_size = 64;
5da702b1 810 }
b5044283 811
a5c76ee6
ZW
812 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
813 using TARGET_OPTIONS to handle a toggle switch, but we're out of
814 bits in target_flags so TARGET_SWITCHES cannot be used.
815 Assumption here is that rs6000_longcall_switch points into the
816 text of the complete option, rather than being a copy, so we can
817 scan back for the presence or absence of the no- modifier. */
818 if (rs6000_longcall_switch)
819 {
820 const char *base = rs6000_longcall_switch;
821 while (base[-1] != 'm') base--;
822
823 if (*rs6000_longcall_switch != '\0')
824 error ("invalid option `%s'", base);
825 rs6000_default_long_calls = (base[0] != 'n');
826 }
827
c81bebd7 828#ifdef TARGET_REGNAMES
a4f6c312
SS
829 /* If the user desires alternate register names, copy in the
830 alternate names now. */
c81bebd7 831 if (TARGET_REGNAMES)
4e135bdd 832 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
833#endif
834
6fa3f289
ZW
835 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
836 If -maix-struct-return or -msvr4-struct-return was explicitly
837 used, don't override with the ABI default. */
b21fb038 838 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
839 {
840 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
841 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
842 else
843 target_flags |= MASK_AIX_STRUCT_RET;
844 }
845
fcce224d
DE
846 if (TARGET_LONG_DOUBLE_128
847 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
848 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
849
9ebbca7d
GK
850 /* Allocate an alias set for register saves & restores from stack. */
851 rs6000_sr_alias_set = new_alias_set ();
852
853 if (TARGET_TOC)
854 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 855
301d03af
RS
856 /* We can only guarantee the availability of DI pseudo-ops when
857 assembling for 64-bit targets. */
ae6c1efd 858 if (!TARGET_64BIT)
301d03af
RS
859 {
860 targetm.asm_out.aligned_op.di = NULL;
861 targetm.asm_out.unaligned_op.di = NULL;
862 }
863
2792d578
DE
864 /* Set maximum branch target alignment at two instructions, eight bytes. */
865 align_jumps_max_skip = 8;
866 align_loops_max_skip = 8;
867
71f123ca
FS
868 /* Arrange to save and restore machine status around nested functions. */
869 init_machine_status = rs6000_init_machine_status;
5248c961 870}
5accd822 871
5da702b1
AH
872/* Handle generic options of the form -mfoo=yes/no.
873 NAME is the option name.
874 VALUE is the option value.
875 FLAG is the pointer to the flag where to store a 1 or 0, depending on
876 whether the option value is 'yes' or 'no' respectively. */
993f19a8 877static void
5da702b1 878rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 879{
5da702b1 880 if (value == 0)
993f19a8 881 return;
5da702b1
AH
882 else if (!strcmp (value, "yes"))
883 *flag = 1;
884 else if (!strcmp (value, "no"))
885 *flag = 0;
08b57fb3 886 else
5da702b1 887 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
888}
889
0ac081f6 890/* Handle -mabi= options. */
00b960c7 891static void
863d938c 892rs6000_parse_abi_options (void)
0ac081f6
AH
893{
894 if (rs6000_abi_string == 0)
895 return;
896 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 897 rs6000_altivec_abi = 1;
76a773f3
AH
898 else if (! strcmp (rs6000_abi_string, "no-altivec"))
899 rs6000_altivec_abi = 0;
a3170dc6 900 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
901 {
902 rs6000_spe_abi = 1;
903 if (!TARGET_SPE_ABI)
904 error ("not configured for ABI: '%s'", rs6000_abi_string);
905 }
906
a3170dc6
AH
907 else if (! strcmp (rs6000_abi_string, "no-spe"))
908 rs6000_spe_abi = 0;
0ac081f6 909 else
c725bd79 910 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
911}
912
025d9908
KH
913/* Handle -malign-XXXXXX options. */
914static void
863d938c 915rs6000_parse_alignment_option (void)
025d9908
KH
916{
917 if (rs6000_alignment_string == 0
918 || ! strcmp (rs6000_alignment_string, "power"))
919 rs6000_alignment_flags = MASK_ALIGN_POWER;
920 else if (! strcmp (rs6000_alignment_string, "natural"))
921 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
922 else
923 error ("unknown -malign-XXXXX option specified: '%s'",
924 rs6000_alignment_string);
925}
926
c4501e62
JJ
927/* Validate and record the size specified with the -mtls-size option. */
928
929static void
863d938c 930rs6000_parse_tls_size_option (void)
c4501e62
JJ
931{
932 if (rs6000_tls_size_string == 0)
933 return;
934 else if (strcmp (rs6000_tls_size_string, "16") == 0)
935 rs6000_tls_size = 16;
936 else if (strcmp (rs6000_tls_size_string, "32") == 0)
937 rs6000_tls_size = 32;
938 else if (strcmp (rs6000_tls_size_string, "64") == 0)
939 rs6000_tls_size = 64;
940 else
941 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
942}
943
5accd822 944void
a2369ed3 945optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 946{
5accd822 947}
3cfa4909
MM
948\f
949/* Do anything needed at the start of the asm file. */
950
1bc7c5b6 951static void
863d938c 952rs6000_file_start (void)
3cfa4909 953{
c4d38ccb 954 size_t i;
3cfa4909 955 char buffer[80];
d330fd93 956 const char *start = buffer;
3cfa4909 957 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
958 const char *default_cpu = TARGET_CPU_DEFAULT;
959 FILE *file = asm_out_file;
960
961 default_file_start ();
962
963#ifdef TARGET_BI_ARCH
964 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
965 default_cpu = 0;
966#endif
3cfa4909
MM
967
968 if (flag_verbose_asm)
969 {
970 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
971 rs6000_select[0].string = default_cpu;
972
b6a1cbae 973 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
974 {
975 ptr = &rs6000_select[i];
976 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
977 {
978 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
979 start = "";
980 }
981 }
982
b91da81f 983#ifdef USING_ELFOS_H
3cfa4909
MM
984 switch (rs6000_sdata)
985 {
986 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
987 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
988 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
989 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
990 }
991
992 if (rs6000_sdata && g_switch_value)
993 {
307b599c
MK
994 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
995 g_switch_value);
3cfa4909
MM
996 start = "";
997 }
998#endif
999
1000 if (*start == '\0')
949ea356 1001 putc ('\n', file);
3cfa4909
MM
1002 }
1003}
5248c961 1004\f
a0ab749a 1005/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1006
1007int
863d938c 1008direct_return (void)
9878760c 1009{
4697a36c
MM
1010 if (reload_completed)
1011 {
1012 rs6000_stack_t *info = rs6000_stack_info ();
1013
1014 if (info->first_gp_reg_save == 32
1015 && info->first_fp_reg_save == 64
00b960c7 1016 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1017 && ! info->lr_save_p
1018 && ! info->cr_save_p
00b960c7 1019 && info->vrsave_mask == 0
c81fc13e 1020 && ! info->push_p)
4697a36c
MM
1021 return 1;
1022 }
1023
1024 return 0;
9878760c
RK
1025}
1026
1027/* Returns 1 always. */
1028
1029int
a2369ed3
DJ
1030any_operand (rtx op ATTRIBUTE_UNUSED,
1031 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1032{
1033 return 1;
1034}
1035
a4f6c312 1036/* Returns 1 if op is the count register. */
38c1f2d7 1037int
a2369ed3 1038count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1039{
1040 if (GET_CODE (op) != REG)
1041 return 0;
1042
1043 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1044 return 1;
1045
1046 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1047 return 1;
1048
1049 return 0;
1050}
1051
0ec4e2a8
AH
1052/* Returns 1 if op is an altivec register. */
1053int
a2369ed3 1054altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1055{
1056
1057 return (register_operand (op, mode)
1058 && (GET_CODE (op) != REG
1059 || REGNO (op) > FIRST_PSEUDO_REGISTER
1060 || ALTIVEC_REGNO_P (REGNO (op))));
1061}
1062
38c1f2d7 1063int
a2369ed3 1064xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1065{
1066 if (GET_CODE (op) != REG)
1067 return 0;
1068
9ebbca7d 1069 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1070 return 1;
1071
802a0058
MM
1072 return 0;
1073}
1074
c859cda6 1075/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1076 by such constants completes more quickly. */
c859cda6
DJ
1077
1078int
a2369ed3 1079s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1080{
1081 return ( GET_CODE (op) == CONST_INT
1082 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1083}
1084
9878760c
RK
1085/* Return 1 if OP is a constant that can fit in a D field. */
1086
1087int
a2369ed3 1088short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1089{
5f59ecb7
DE
1090 return (GET_CODE (op) == CONST_INT
1091 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1092}
1093
5519a4f9 1094/* Similar for an unsigned D field. */
9878760c
RK
1095
1096int
a2369ed3 1097u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1098{
19684119 1099 return (GET_CODE (op) == CONST_INT
c1f11548 1100 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1101}
1102
dcfedcd0
RK
1103/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1104
1105int
a2369ed3 1106non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1107{
1108 return (GET_CODE (op) == CONST_INT
a7653a2c 1109 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1110}
1111
2bfcf297
DB
1112/* Returns 1 if OP is a CONST_INT that is a positive value
1113 and an exact power of 2. */
1114
1115int
a2369ed3 1116exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1117{
1118 return (GET_CODE (op) == CONST_INT
1119 && INTVAL (op) > 0
1120 && exact_log2 (INTVAL (op)) >= 0);
1121}
1122
9878760c
RK
1123/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1124 ctr, or lr). */
1125
1126int
a2369ed3 1127gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1128{
1129 return (register_operand (op, mode)
802a0058 1130 && (GET_CODE (op) != REG
9ebbca7d
GK
1131 || (REGNO (op) >= ARG_POINTER_REGNUM
1132 && !XER_REGNO_P (REGNO (op)))
1133 || REGNO (op) < MQ_REGNO));
9878760c
RK
1134}
1135
1136/* Returns 1 if OP is either a pseudo-register or a register denoting a
1137 CR field. */
1138
1139int
a2369ed3 1140cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1141{
1142 return (register_operand (op, mode)
1143 && (GET_CODE (op) != REG
1144 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1145 || CR_REGNO_P (REGNO (op))));
1146}
1147
815cdc52
MM
1148/* Returns 1 if OP is either a pseudo-register or a register denoting a
1149 CR field that isn't CR0. */
1150
1151int
a2369ed3 1152cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1153{
1154 return (register_operand (op, mode)
1155 && (GET_CODE (op) != REG
1156 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1157 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1158}
1159
a4f6c312
SS
1160/* Returns 1 if OP is either a constant integer valid for a D-field or
1161 a non-special register. If a register, it must be in the proper
1162 mode unless MODE is VOIDmode. */
9878760c
RK
1163
1164int
a2369ed3 1165reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1166{
f5a28898 1167 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1168}
1169
a4f6c312
SS
1170/* Similar, except check if the negation of the constant would be
1171 valid for a D-field. */
9878760c
RK
1172
1173int
a2369ed3 1174reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1175{
1176 if (GET_CODE (op) == CONST_INT)
1177 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1178
cd2b37d9 1179 return gpc_reg_operand (op, mode);
9878760c
RK
1180}
1181
768070a0
TR
1182/* Returns 1 if OP is either a constant integer valid for a DS-field or
1183 a non-special register. If a register, it must be in the proper
1184 mode unless MODE is VOIDmode. */
1185
1186int
a2369ed3 1187reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1188{
1189 if (gpc_reg_operand (op, mode))
1190 return 1;
1191 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1192 return 1;
1193
1194 return 0;
1195}
1196
1197
a4f6c312
SS
1198/* Return 1 if the operand is either a register or an integer whose
1199 high-order 16 bits are zero. */
9878760c
RK
1200
1201int
a2369ed3 1202reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1203{
e675f625 1204 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1205}
1206
1207/* Return 1 is the operand is either a non-special register or ANY
1208 constant integer. */
1209
1210int
a2369ed3 1211reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1212{
a4f6c312 1213 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1214}
1215
1216/* Return 1 is the operand is either a non-special register or ANY
1217 32-bit signed constant integer. */
1218
1219int
a2369ed3 1220reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1221{
a4f6c312
SS
1222 return (gpc_reg_operand (op, mode)
1223 || (GET_CODE (op) == CONST_INT
f6bf7de2 1224#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1225 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1226 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1227#endif
a4f6c312 1228 ));
9878760c
RK
1229}
1230
2bfcf297
DB
1231/* Return 1 is the operand is either a non-special register or a 32-bit
1232 signed constant integer valid for 64-bit addition. */
1233
1234int
a2369ed3 1235reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1236{
a4f6c312
SS
1237 return (gpc_reg_operand (op, mode)
1238 || (GET_CODE (op) == CONST_INT
a65c591c 1239#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1240 && INTVAL (op) < 0x7fff8000
a65c591c 1241#else
a4f6c312
SS
1242 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1243 < 0x100000000ll)
2bfcf297 1244#endif
a4f6c312 1245 ));
2bfcf297
DB
1246}
1247
1248/* Return 1 is the operand is either a non-special register or a 32-bit
1249 signed constant integer valid for 64-bit subtraction. */
1250
1251int
a2369ed3 1252reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1253{
a4f6c312
SS
1254 return (gpc_reg_operand (op, mode)
1255 || (GET_CODE (op) == CONST_INT
a65c591c 1256#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1257 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1258#else
a4f6c312
SS
1259 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1260 < 0x100000000ll)
2bfcf297 1261#endif
a4f6c312 1262 ));
2bfcf297
DB
1263}
1264
9ebbca7d
GK
1265/* Return 1 is the operand is either a non-special register or ANY
1266 32-bit unsigned constant integer. */
1267
1268int
a2369ed3 1269reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1270{
1d328b19
GK
1271 if (GET_CODE (op) == CONST_INT)
1272 {
1273 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1274 {
1275 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1276 abort ();
1d328b19
GK
1277
1278 if (INTVAL (op) < 0)
1279 return 0;
1280 }
1281
1282 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1283 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1284 }
1285 else if (GET_CODE (op) == CONST_DOUBLE)
1286 {
1287 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1288 || mode != DImode)
a4f6c312 1289 abort ();
1d328b19
GK
1290
1291 return CONST_DOUBLE_HIGH (op) == 0;
1292 }
1293 else
1294 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1295}
1296
51d3e7d6 1297/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1298
1299int
a2369ed3 1300got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1301{
1302 return (GET_CODE (op) == SYMBOL_REF
1303 || GET_CODE (op) == CONST
1304 || GET_CODE (op) == LABEL_REF);
1305}
1306
38c1f2d7
MM
1307/* Return 1 if the operand is a simple references that can be loaded via
1308 the GOT (labels involving addition aren't allowed). */
1309
1310int
a2369ed3 1311got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1312{
1313 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1314}
1315
4e74d8ec
MM
1316/* Return the number of instructions it takes to form a constant in an
1317 integer register. */
1318
1319static int
a2369ed3 1320num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1321{
1322 /* signed constant loadable with {cal|addi} */
5f59ecb7 1323 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1324 return 1;
1325
4e74d8ec 1326 /* constant loadable with {cau|addis} */
5f59ecb7 1327 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1328 return 1;
1329
5f59ecb7 1330#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1331 else if (TARGET_POWERPC64)
4e74d8ec 1332 {
a65c591c
DE
1333 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1334 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1335
a65c591c 1336 if (high == 0 || high == -1)
4e74d8ec
MM
1337 return 2;
1338
a65c591c 1339 high >>= 1;
4e74d8ec 1340
a65c591c 1341 if (low == 0)
4e74d8ec 1342 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1343 else
1344 return (num_insns_constant_wide (high)
e396202a 1345 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1346 }
1347#endif
1348
1349 else
1350 return 2;
1351}
1352
1353int
a2369ed3 1354num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1355{
4e74d8ec 1356 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1357 {
1358#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1359 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1360 && mask64_operand (op, mode))
0d30d435
DE
1361 return 2;
1362 else
1363#endif
1364 return num_insns_constant_wide (INTVAL (op));
1365 }
4e74d8ec 1366
6fc48950
MM
1367 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1368 {
1369 long l;
1370 REAL_VALUE_TYPE rv;
1371
1372 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1373 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1374 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1375 }
1376
47ad8c61 1377 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1378 {
47ad8c61
MM
1379 HOST_WIDE_INT low;
1380 HOST_WIDE_INT high;
1381 long l[2];
1382 REAL_VALUE_TYPE rv;
1383 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1384
47ad8c61
MM
1385 if (mode == VOIDmode || mode == DImode)
1386 {
1387 high = CONST_DOUBLE_HIGH (op);
1388 low = CONST_DOUBLE_LOW (op);
1389 }
1390 else
1391 {
1392 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1393 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1394 high = l[endian];
1395 low = l[1 - endian];
1396 }
4e74d8ec 1397
47ad8c61
MM
1398 if (TARGET_32BIT)
1399 return (num_insns_constant_wide (low)
1400 + num_insns_constant_wide (high));
4e74d8ec
MM
1401
1402 else
47ad8c61 1403 {
e72247f4 1404 if (high == 0 && low >= 0)
47ad8c61
MM
1405 return num_insns_constant_wide (low);
1406
e72247f4 1407 else if (high == -1 && low < 0)
47ad8c61
MM
1408 return num_insns_constant_wide (low);
1409
a260abc9
DE
1410 else if (mask64_operand (op, mode))
1411 return 2;
1412
47ad8c61
MM
1413 else if (low == 0)
1414 return num_insns_constant_wide (high) + 1;
1415
1416 else
1417 return (num_insns_constant_wide (high)
1418 + num_insns_constant_wide (low) + 1);
1419 }
4e74d8ec
MM
1420 }
1421
1422 else
1423 abort ();
1424}
1425
a4f6c312
SS
1426/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1427 register with one instruction per word. We only do this if we can
1428 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1429
1430int
a2369ed3 1431easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1432{
9878760c
RK
1433 if (GET_CODE (op) != CONST_DOUBLE
1434 || GET_MODE (op) != mode
4e74d8ec 1435 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1436 return 0;
1437
a4f6c312 1438 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1439 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1440 && mode != DImode)
b6c9286a
MM
1441 return 1;
1442
a4f6c312 1443 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1444 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1445 return 0;
1446
5ae4759c 1447#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1448 /* Similarly if we are using -mrelocatable, consider all constants
1449 to be hard. */
5ae4759c
MM
1450 if (TARGET_RELOCATABLE)
1451 return 0;
1452#endif
1453
fcce224d
DE
1454 if (mode == TFmode)
1455 {
1456 long k[4];
1457 REAL_VALUE_TYPE rv;
1458
1459 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1460 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1461
1462 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1463 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1464 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1465 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1466 }
1467
1468 else if (mode == DFmode)
042259f2
DE
1469 {
1470 long k[2];
1471 REAL_VALUE_TYPE rv;
1472
1473 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1474 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1475
a65c591c
DE
1476 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1477 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1478 }
4e74d8ec
MM
1479
1480 else if (mode == SFmode)
042259f2
DE
1481 {
1482 long l;
1483 REAL_VALUE_TYPE rv;
1484
1485 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1486 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1487
4e74d8ec 1488 return num_insns_constant_wide (l) == 1;
042259f2 1489 }
4e74d8ec 1490
a260abc9 1491 else if (mode == DImode)
c81fc13e 1492 return ((TARGET_POWERPC64
a260abc9
DE
1493 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1494 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1495
a9098fd0
GK
1496 else if (mode == SImode)
1497 return 1;
4e74d8ec
MM
1498 else
1499 abort ();
9878760c 1500}
8f75773e 1501
72ac76be 1502/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1503
1504static int
a2369ed3 1505easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1506{
1507 int units, i, cst;
1508
1509 units = CONST_VECTOR_NUNITS (op);
1510
1511 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1512 for (i = 1; i < units; ++i)
1513 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1514 break;
1515 if (i == units)
1516 return 1;
1517 return 0;
1518}
1519
1520/* Return 1 if the operand is a CONST_INT and can be put into a
1521 register without using memory. */
1522
1523int
a2369ed3 1524easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1525{
d744e06e 1526 int cst, cst2;
69ef87e2 1527
d744e06e
AH
1528 if (GET_CODE (op) != CONST_VECTOR
1529 || (!TARGET_ALTIVEC
1530 && !TARGET_SPE))
69ef87e2
AH
1531 return 0;
1532
d744e06e
AH
1533 if (zero_constant (op, mode)
1534 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1535 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1536 return 1;
69ef87e2 1537
d744e06e
AH
1538 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1539 return 0;
1540
f5119d10
AH
1541 if (TARGET_SPE && mode == V1DImode)
1542 return 0;
1543
d744e06e
AH
1544 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1545 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1546
1547 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1548 li r0, CONSTANT1
1549 evmergelo r0, r0, r0
1550 li r0, CONSTANT2
1551
1552 I don't know how efficient it would be to allow bigger constants,
1553 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1554 instructions is better than a 64-bit memory load, but I don't
1555 have the e500 timing specs. */
1556 if (TARGET_SPE && mode == V2SImode
1557 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1558 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1559 return 1;
1560
1561 if (TARGET_ALTIVEC && EASY_VECTOR_15 (cst, op, mode))
1562 return 1;
1563
1564 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1565 return 1;
1566
1567 return 0;
1568}
1569
1570/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1571
1572int
a2369ed3 1573easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1574{
1575 int cst;
1576
1577 if (!easy_vector_constant (op, mode))
1578 return 0;
1579
1580 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1581
1582 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1583}
1584
1585const char *
a2369ed3 1586output_vec_const_move (rtx *operands)
d744e06e
AH
1587{
1588 int cst, cst2;
1589 enum machine_mode mode;
1590 rtx dest, vec;
1591
1592 dest = operands[0];
1593 vec = operands[1];
69ef87e2 1594
d744e06e
AH
1595 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1596 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1597 mode = GET_MODE (dest);
69ef87e2 1598
d744e06e
AH
1599 if (TARGET_ALTIVEC)
1600 {
1601 if (zero_constant (vec, mode))
1602 return "vxor %0,%0,%0";
1603 else if (EASY_VECTOR_15 (cst, vec, mode))
98ef3137 1604 {
d744e06e
AH
1605 operands[1] = GEN_INT (cst);
1606 switch (mode)
1607 {
1608 case V4SImode:
1609 return "vspltisw %0,%1";
1610 case V8HImode:
1611 return "vspltish %0,%1";
1612 case V16QImode:
1613 return "vspltisb %0,%1";
1614 default:
1615 abort ();
1616 }
98ef3137 1617 }
d744e06e
AH
1618 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1619 return "#";
1620 else
1621 abort ();
69ef87e2
AH
1622 }
1623
d744e06e
AH
1624 if (TARGET_SPE)
1625 {
1626 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1627 pattern of V1DI, V4HI, and V2SF.
1628
c1207243 1629 FIXME: We should probably return # and add post reload
d744e06e
AH
1630 splitters for these, but this way is so easy ;-).
1631 */
1632 operands[1] = GEN_INT (cst);
1633 operands[2] = GEN_INT (cst2);
1634 if (cst == cst2)
1635 return "li %0,%1\n\tevmergelo %0,%0,%0";
1636 else
1637 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1638 }
1639
1640 abort ();
69ef87e2
AH
1641}
1642
1643/* Return 1 if the operand is the constant 0. This works for scalars
1644 as well as vectors. */
1645int
a2369ed3 1646zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1647{
1648 return op == CONST0_RTX (mode);
1649}
1650
50a0b056
GK
1651/* Return 1 if the operand is 0.0. */
1652int
a2369ed3 1653zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1654{
1655 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1656}
1657
a4f6c312
SS
1658/* Return 1 if the operand is in volatile memory. Note that during
1659 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1660 volatile memory references. So this function allows us to
1661 recognize volatile references where its safe. */
1662
1663int
a2369ed3 1664volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1665{
1666 if (GET_CODE (op) != MEM)
1667 return 0;
1668
1669 if (!MEM_VOLATILE_P (op))
1670 return 0;
1671
1672 if (mode != GET_MODE (op))
1673 return 0;
1674
1675 if (reload_completed)
1676 return memory_operand (op, mode);
1677
1678 if (reload_in_progress)
1679 return strict_memory_address_p (mode, XEXP (op, 0));
1680
1681 return memory_address_p (mode, XEXP (op, 0));
1682}
1683
97f6e72f 1684/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1685
1686int
a2369ed3 1687offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1688{
97f6e72f 1689 return ((GET_CODE (op) == MEM)
677a9668 1690 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1691 mode, XEXP (op, 0)));
914c2e77
RK
1692}
1693
9878760c
RK
1694/* Return 1 if the operand is either an easy FP constant (see above) or
1695 memory. */
1696
1697int
a2369ed3 1698mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
1699{
1700 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1701}
1702
1703/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1704 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1705
1706int
a2369ed3 1707add_operand (rtx op, enum machine_mode mode)
9878760c 1708{
2bfcf297 1709 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1710 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1711 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1712
1713 return gpc_reg_operand (op, mode);
9878760c
RK
1714}
1715
dcfedcd0
RK
1716/* Return 1 if OP is a constant but not a valid add_operand. */
1717
1718int
a2369ed3 1719non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1720{
1721 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1722 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1723 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1724}
1725
9878760c
RK
1726/* Return 1 if the operand is a non-special register or a constant that
1727 can be used as the operand of an OR or XOR insn on the RS/6000. */
1728
1729int
a2369ed3 1730logical_operand (rtx op, enum machine_mode mode)
9878760c 1731{
40501e5f 1732 HOST_WIDE_INT opl, oph;
1d328b19 1733
dfbdccdb
GK
1734 if (gpc_reg_operand (op, mode))
1735 return 1;
1d328b19 1736
dfbdccdb 1737 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1738 {
1739 opl = INTVAL (op) & GET_MODE_MASK (mode);
1740
1741#if HOST_BITS_PER_WIDE_INT <= 32
1742 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1743 return 0;
1744#endif
1745 }
dfbdccdb
GK
1746 else if (GET_CODE (op) == CONST_DOUBLE)
1747 {
1d328b19 1748 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1749 abort ();
1d328b19
GK
1750
1751 opl = CONST_DOUBLE_LOW (op);
1752 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1753 if (oph != 0)
38886f37 1754 return 0;
dfbdccdb
GK
1755 }
1756 else
1757 return 0;
1d328b19 1758
40501e5f
AM
1759 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1760 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1761}
1762
dcfedcd0 1763/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1764 above), but could be split into one. */
dcfedcd0
RK
1765
1766int
a2369ed3 1767non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 1768{
dfbdccdb 1769 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1770 && ! logical_operand (op, mode)
1771 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1772}
1773
19ba8161 1774/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1775 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1776 Reject all ones and all zeros, since these should have been optimized
1777 away and confuse the making of MB and ME. */
1778
1779int
a2369ed3 1780mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1781{
02071907 1782 HOST_WIDE_INT c, lsb;
9878760c 1783
19ba8161
DE
1784 if (GET_CODE (op) != CONST_INT)
1785 return 0;
1786
1787 c = INTVAL (op);
1788
57deb3a1
AM
1789 /* Fail in 64-bit mode if the mask wraps around because the upper
1790 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1791 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1792 return 0;
1793
c5059423
AM
1794 /* We don't change the number of transitions by inverting,
1795 so make sure we start with the LS bit zero. */
1796 if (c & 1)
1797 c = ~c;
1798
1799 /* Reject all zeros or all ones. */
1800 if (c == 0)
9878760c
RK
1801 return 0;
1802
c5059423
AM
1803 /* Find the first transition. */
1804 lsb = c & -c;
1805
1806 /* Invert to look for a second transition. */
1807 c = ~c;
9878760c 1808
c5059423
AM
1809 /* Erase first transition. */
1810 c &= -lsb;
9878760c 1811
c5059423
AM
1812 /* Find the second transition (if any). */
1813 lsb = c & -c;
1814
1815 /* Match if all the bits above are 1's (or c is zero). */
1816 return c == -lsb;
9878760c
RK
1817}
1818
0ba1b2ff
AM
1819/* Return 1 for the PowerPC64 rlwinm corner case. */
1820
1821int
a2369ed3 1822mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
1823{
1824 HOST_WIDE_INT c, lsb;
1825
1826 if (GET_CODE (op) != CONST_INT)
1827 return 0;
1828
1829 c = INTVAL (op);
1830
1831 if ((c & 0x80000001) != 0x80000001)
1832 return 0;
1833
1834 c = ~c;
1835 if (c == 0)
1836 return 0;
1837
1838 lsb = c & -c;
1839 c = ~c;
1840 c &= -lsb;
1841 lsb = c & -c;
1842 return c == -lsb;
1843}
1844
a260abc9
DE
1845/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1846 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
1847 Reject all zeros, since zero should have been optimized away and
1848 confuses the making of MB and ME. */
9878760c
RK
1849
1850int
a2369ed3 1851mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
1852{
1853 if (GET_CODE (op) == CONST_INT)
1854 {
02071907 1855 HOST_WIDE_INT c, lsb;
a260abc9 1856
c5059423 1857 c = INTVAL (op);
a260abc9 1858
0ba1b2ff 1859 /* Reject all zeros. */
c5059423 1860 if (c == 0)
e2c953b6
DE
1861 return 0;
1862
0ba1b2ff
AM
1863 /* We don't change the number of transitions by inverting,
1864 so make sure we start with the LS bit zero. */
1865 if (c & 1)
1866 c = ~c;
1867
c5059423
AM
1868 /* Find the transition, and check that all bits above are 1's. */
1869 lsb = c & -c;
e3981aab
DE
1870
1871 /* Match if all the bits above are 1's (or c is zero). */
c5059423 1872 return c == -lsb;
e2c953b6 1873 }
0ba1b2ff
AM
1874 return 0;
1875}
1876
1877/* Like mask64_operand, but allow up to three transitions. This
1878 predicate is used by insn patterns that generate two rldicl or
1879 rldicr machine insns. */
1880
1881int
a2369ed3 1882mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
1883{
1884 if (GET_CODE (op) == CONST_INT)
a260abc9 1885 {
0ba1b2ff 1886 HOST_WIDE_INT c, lsb;
a260abc9 1887
0ba1b2ff 1888 c = INTVAL (op);
a260abc9 1889
0ba1b2ff
AM
1890 /* Disallow all zeros. */
1891 if (c == 0)
1892 return 0;
a260abc9 1893
0ba1b2ff
AM
1894 /* We don't change the number of transitions by inverting,
1895 so make sure we start with the LS bit zero. */
1896 if (c & 1)
1897 c = ~c;
a260abc9 1898
0ba1b2ff
AM
1899 /* Find the first transition. */
1900 lsb = c & -c;
a260abc9 1901
0ba1b2ff
AM
1902 /* Invert to look for a second transition. */
1903 c = ~c;
1904
1905 /* Erase first transition. */
1906 c &= -lsb;
1907
1908 /* Find the second transition. */
1909 lsb = c & -c;
1910
1911 /* Invert to look for a third transition. */
1912 c = ~c;
1913
1914 /* Erase second transition. */
1915 c &= -lsb;
1916
1917 /* Find the third transition (if any). */
1918 lsb = c & -c;
1919
1920 /* Match if all the bits above are 1's (or c is zero). */
1921 return c == -lsb;
1922 }
1923 return 0;
1924}
1925
1926/* Generates shifts and masks for a pair of rldicl or rldicr insns to
1927 implement ANDing by the mask IN. */
1928void
a2369ed3 1929build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
1930{
1931#if HOST_BITS_PER_WIDE_INT >= 64
1932 unsigned HOST_WIDE_INT c, lsb, m1, m2;
1933 int shift;
1934
1935 if (GET_CODE (in) != CONST_INT)
1936 abort ();
1937
1938 c = INTVAL (in);
1939 if (c & 1)
1940 {
1941 /* Assume c initially something like 0x00fff000000fffff. The idea
1942 is to rotate the word so that the middle ^^^^^^ group of zeros
1943 is at the MS end and can be cleared with an rldicl mask. We then
1944 rotate back and clear off the MS ^^ group of zeros with a
1945 second rldicl. */
1946 c = ~c; /* c == 0xff000ffffff00000 */
1947 lsb = c & -c; /* lsb == 0x0000000000100000 */
1948 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
1949 c = ~c; /* c == 0x00fff000000fffff */
1950 c &= -lsb; /* c == 0x00fff00000000000 */
1951 lsb = c & -c; /* lsb == 0x0000100000000000 */
1952 c = ~c; /* c == 0xff000fffffffffff */
1953 c &= -lsb; /* c == 0xff00000000000000 */
1954 shift = 0;
1955 while ((lsb >>= 1) != 0)
1956 shift++; /* shift == 44 on exit from loop */
1957 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
1958 m1 = ~m1; /* m1 == 0x000000ffffffffff */
1959 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
1960 }
1961 else
0ba1b2ff
AM
1962 {
1963 /* Assume c initially something like 0xff000f0000000000. The idea
1964 is to rotate the word so that the ^^^ middle group of zeros
1965 is at the LS end and can be cleared with an rldicr mask. We then
1966 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
1967 a second rldicr. */
1968 lsb = c & -c; /* lsb == 0x0000010000000000 */
1969 m2 = -lsb; /* m2 == 0xffffff0000000000 */
1970 c = ~c; /* c == 0x00fff0ffffffffff */
1971 c &= -lsb; /* c == 0x00fff00000000000 */
1972 lsb = c & -c; /* lsb == 0x0000100000000000 */
1973 c = ~c; /* c == 0xff000fffffffffff */
1974 c &= -lsb; /* c == 0xff00000000000000 */
1975 shift = 0;
1976 while ((lsb >>= 1) != 0)
1977 shift++; /* shift == 44 on exit from loop */
1978 m1 = ~c; /* m1 == 0x00ffffffffffffff */
1979 m1 >>= shift; /* m1 == 0x0000000000000fff */
1980 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
1981 }
1982
1983 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
1984 masks will be all 1's. We are guaranteed more than one transition. */
1985 out[0] = GEN_INT (64 - shift);
1986 out[1] = GEN_INT (m1);
1987 out[2] = GEN_INT (shift);
1988 out[3] = GEN_INT (m2);
1989#else
045572c7
GK
1990 (void)in;
1991 (void)out;
0ba1b2ff
AM
1992 abort ();
1993#endif
a260abc9
DE
1994}
1995
1996/* Return 1 if the operand is either a non-special register or a constant
1997 that can be used as the operand of a PowerPC64 logical AND insn. */
1998
1999int
a2369ed3 2000and64_operand (rtx op, enum machine_mode mode)
9878760c 2001{
a4f6c312 2002 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2003 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2004
2005 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2006}
2007
0ba1b2ff
AM
2008/* Like the above, but also match constants that can be implemented
2009 with two rldicl or rldicr insns. */
2010
2011int
a2369ed3 2012and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff
AM
2013{
2014 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
2015 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2016
2017 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2018}
2019
a260abc9
DE
2020/* Return 1 if the operand is either a non-special register or a
2021 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2022
2023int
a2369ed3 2024and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2025{
a4f6c312 2026 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2027 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2028
2029 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2030}
2031
9878760c
RK
2032/* Return 1 if the operand is a general register or memory operand. */
2033
2034int
a2369ed3 2035reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2036{
b6c9286a
MM
2037 return (gpc_reg_operand (op, mode)
2038 || memory_operand (op, mode)
2039 || volatile_mem_operand (op, mode));
9878760c
RK
2040}
2041
a7a813f7 2042/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2043 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2044 instruction. */
2045
2046int
a2369ed3 2047lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2048{
2049 rtx inner = op;
2050
2051 if (reload_completed && GET_CODE (inner) == SUBREG)
2052 inner = SUBREG_REG (inner);
2053
2054 return gpc_reg_operand (inner, mode)
2055 || (memory_operand (inner, mode)
2056 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2057 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2058 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2059 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2060 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2061}
2062
cc4d5fec
JH
2063/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2064
2065int
a2369ed3 2066symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2067{
2068 if (mode != VOIDmode && GET_MODE (op) != mode)
2069 return 0;
2070
473f51b6
DE
2071 return (GET_CODE (op) == SYMBOL_REF
2072 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2073}
2074
9878760c 2075/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2076 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2077
2078int
a2369ed3 2079call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2080{
2081 if (mode != VOIDmode && GET_MODE (op) != mode)
2082 return 0;
2083
2084 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2085 || (GET_CODE (op) == REG
2086 && (REGNO (op) == LINK_REGISTER_REGNUM
2087 || REGNO (op) == COUNT_REGISTER_REGNUM
2088 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2089}
2090
2af3d377 2091/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2092 this file. */
2af3d377
RK
2093
2094int
a2369ed3
DJ
2095current_file_function_operand (rtx op,
2096 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2097{
473f51b6
DE
2098 return (GET_CODE (op) == SYMBOL_REF
2099 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2100 && (SYMBOL_REF_LOCAL_P (op)
2101 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2102}
2103
9878760c
RK
2104/* Return 1 if this operand is a valid input for a move insn. */
2105
2106int
a2369ed3 2107input_operand (rtx op, enum machine_mode mode)
9878760c 2108{
eb4e8003 2109 /* Memory is always valid. */
9878760c
RK
2110 if (memory_operand (op, mode))
2111 return 1;
2112
34792e82 2113 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2114 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2115 return 1;
2116
eb4e8003
RK
2117 /* For floating-point, easy constants are valid. */
2118 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2119 && CONSTANT_P (op)
2120 && easy_fp_constant (op, mode))
2121 return 1;
2122
4e74d8ec
MM
2123 /* Allow any integer constant. */
2124 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2125 && (GET_CODE (op) == CONST_INT
e675f625 2126 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2127 return 1;
2128
d744e06e
AH
2129 /* Allow easy vector constants. */
2130 if (GET_CODE (op) == CONST_VECTOR
2131 && easy_vector_constant (op, mode))
2132 return 1;
2133
eb4e8003
RK
2134 /* For floating-point or multi-word mode, the only remaining valid type
2135 is a register. */
9878760c
RK
2136 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2137 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2138 return register_operand (op, mode);
9878760c 2139
88fe15a1
RK
2140 /* The only cases left are integral modes one word or smaller (we
2141 do not get called for MODE_CC values). These can be in any
2142 register. */
2143 if (register_operand (op, mode))
a8b3aeda 2144 return 1;
88fe15a1 2145
84cf9dda 2146 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2147 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2148 return 1;
2149
9ebbca7d 2150 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2151 if (toc_relative_expr_p (op))
b6c9286a
MM
2152 return 1;
2153
88228c4b
MM
2154 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2155 to be valid. */
f607bc57 2156 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2157 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2158 && small_data_operand (op, Pmode))
2159 return 1;
2160
042259f2 2161 return 0;
9878760c 2162}
7509c759 2163
a4f6c312 2164/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2165
2166int
a2369ed3
DJ
2167small_data_operand (rtx op ATTRIBUTE_UNUSED,
2168 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2169{
38c1f2d7 2170#if TARGET_ELF
5f59ecb7 2171 rtx sym_ref;
7509c759 2172
d9407988 2173 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2174 return 0;
a54d04b7 2175
f607bc57 2176 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2177 return 0;
2178
88228c4b
MM
2179 if (GET_CODE (op) == SYMBOL_REF)
2180 sym_ref = op;
2181
2182 else if (GET_CODE (op) != CONST
2183 || GET_CODE (XEXP (op, 0)) != PLUS
2184 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2185 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2186 return 0;
2187
88228c4b 2188 else
dbf55e53
MM
2189 {
2190 rtx sum = XEXP (op, 0);
2191 HOST_WIDE_INT summand;
2192
2193 /* We have to be careful here, because it is the referenced address
2194 that must be 32k from _SDA_BASE_, not just the symbol. */
2195 summand = INTVAL (XEXP (sum, 1));
307b599c 2196 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2197 return 0;
2198
2199 sym_ref = XEXP (sum, 0);
2200 }
88228c4b 2201
20bfcd69 2202 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2203#else
2204 return 0;
2205#endif
7509c759 2206}
46c07df8 2207
3a1f863f 2208/* Return true if either operand is a general purpose register. */
46c07df8 2209
3a1f863f
DE
2210bool
2211gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2212{
3a1f863f
DE
2213 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2214 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2215}
2216
9ebbca7d 2217\f
4d588c14
RH
2218/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2219
9ebbca7d 2220static int
a2369ed3 2221constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2222{
2223 switch (GET_CODE(op))
2224 {
2225 case SYMBOL_REF:
c4501e62
JJ
2226 if (RS6000_SYMBOL_REF_TLS_P (op))
2227 return 0;
2228 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2229 {
2230 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2231 {
2232 *have_sym = 1;
2233 return 1;
2234 }
2235 else
2236 return 0;
2237 }
2238 else if (! strcmp (XSTR (op, 0), toc_label_name))
2239 {
2240 *have_toc = 1;
2241 return 1;
2242 }
2243 else
2244 return 0;
9ebbca7d
GK
2245 case PLUS:
2246 case MINUS:
c1f11548
DE
2247 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2248 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2249 case CONST:
a4f6c312 2250 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2251 case CONST_INT:
a4f6c312 2252 return 1;
9ebbca7d 2253 default:
a4f6c312 2254 return 0;
9ebbca7d
GK
2255 }
2256}
2257
4d588c14 2258static bool
a2369ed3 2259constant_pool_expr_p (rtx op)
9ebbca7d
GK
2260{
2261 int have_sym = 0;
2262 int have_toc = 0;
2263 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2264}
2265
4d588c14 2266static bool
a2369ed3 2267toc_relative_expr_p (rtx op)
9ebbca7d 2268{
4d588c14
RH
2269 int have_sym = 0;
2270 int have_toc = 0;
2271 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2272}
2273
2274/* SPE offset addressing is limited to 5-bits worth of double words. */
2275#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2276
2277bool
a2369ed3 2278legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2279{
2280 return (TARGET_TOC
2281 && GET_CODE (x) == PLUS
2282 && GET_CODE (XEXP (x, 0)) == REG
2283 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2284 && constant_pool_expr_p (XEXP (x, 1)));
2285}
2286
2287static bool
a2369ed3 2288legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2289{
2290 return (DEFAULT_ABI == ABI_V4
2291 && !flag_pic && !TARGET_TOC
2292 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2293 && small_data_operand (x, mode));
2294}
2295
2296static bool
a2369ed3 2297legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2298{
2299 unsigned HOST_WIDE_INT offset, extra;
2300
2301 if (GET_CODE (x) != PLUS)
2302 return false;
2303 if (GET_CODE (XEXP (x, 0)) != REG)
2304 return false;
2305 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2306 return false;
2307 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2308 return false;
2309
2310 offset = INTVAL (XEXP (x, 1));
2311 extra = 0;
2312 switch (mode)
2313 {
2314 case V16QImode:
2315 case V8HImode:
2316 case V4SFmode:
2317 case V4SImode:
2318 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2319 which leaves the only valid constant offset of zero, which by
2320 canonicalization rules is also invalid. */
2321 return false;
2322
2323 case V4HImode:
2324 case V2SImode:
2325 case V1DImode:
2326 case V2SFmode:
2327 /* SPE vector modes. */
2328 return SPE_CONST_OFFSET_OK (offset);
2329
2330 case DFmode:
2331 case DImode:
2332 if (TARGET_32BIT)
2333 extra = 4;
2334 else if (offset & 3)
2335 return false;
2336 break;
2337
2338 case TFmode:
2339 case TImode:
2340 if (TARGET_32BIT)
2341 extra = 12;
2342 else if (offset & 3)
2343 return false;
2344 else
2345 extra = 8;
2346 break;
2347
2348 default:
2349 break;
2350 }
2351
2352 return (offset + extra >= offset) && (offset + extra + 0x8000 < 0x10000);
2353}
2354
2355static bool
a2369ed3 2356legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2357{
2358 rtx op0, op1;
2359
2360 if (GET_CODE (x) != PLUS)
2361 return false;
2362 op0 = XEXP (x, 0);
2363 op1 = XEXP (x, 1);
2364
2365 if (!REG_P (op0) || !REG_P (op1))
2366 return false;
2367
2368 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2369 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2370 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2371 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2372}
2373
4d588c14 2374static inline bool
a2369ed3 2375legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2376{
2377 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2378}
2379
2380static bool
a2369ed3 2381legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2382{
2383 if (GET_CODE (x) != LO_SUM)
2384 return false;
2385 if (GET_CODE (XEXP (x, 0)) != REG)
2386 return false;
2387 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2388 return false;
2389 x = XEXP (x, 1);
2390
2391 if (TARGET_ELF)
2392 {
2393 if (DEFAULT_ABI != ABI_AIX && flag_pic)
2394 return false;
2395 if (TARGET_TOC)
2396 return false;
2397 if (GET_MODE_NUNITS (mode) != 1)
2398 return false;
2399 if (GET_MODE_BITSIZE (mode) > 32
2400 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2401 return false;
2402
2403 return CONSTANT_P (x);
2404 }
2405
2406 return false;
2407}
2408
2409
9ebbca7d
GK
2410/* Try machine-dependent ways of modifying an illegitimate address
2411 to be legitimate. If we find one, return the new, valid address.
2412 This is used from only one place: `memory_address' in explow.c.
2413
a4f6c312
SS
2414 OLDX is the address as it was before break_out_memory_refs was
2415 called. In some cases it is useful to look at this to decide what
2416 needs to be done.
9ebbca7d 2417
a4f6c312 2418 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2419
a4f6c312
SS
2420 It is always safe for this function to do nothing. It exists to
2421 recognize opportunities to optimize the output.
9ebbca7d
GK
2422
2423 On RS/6000, first check for the sum of a register with a constant
2424 integer that is out of range. If so, generate code to add the
2425 constant with the low-order 16 bits masked to the register and force
2426 this result into another register (this can be done with `cau').
2427 Then generate an address of REG+(CONST&0xffff), allowing for the
2428 possibility of bit 16 being a one.
2429
2430 Then check for the sum of a register and something not constant, try to
2431 load the other things into a register and return the sum. */
4d588c14 2432
9ebbca7d 2433rtx
a2369ed3
DJ
2434rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2435 enum machine_mode mode)
0ac081f6 2436{
c4501e62
JJ
2437 if (GET_CODE (x) == SYMBOL_REF)
2438 {
2439 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2440 if (model != 0)
2441 return rs6000_legitimize_tls_address (x, model);
2442 }
2443
9ebbca7d
GK
2444 if (GET_CODE (x) == PLUS
2445 && GET_CODE (XEXP (x, 0)) == REG
2446 && GET_CODE (XEXP (x, 1)) == CONST_INT
2447 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2448 {
2449 HOST_WIDE_INT high_int, low_int;
2450 rtx sum;
a65c591c
DE
2451 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2452 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2453 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2454 GEN_INT (high_int)), 0);
2455 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2456 }
2457 else if (GET_CODE (x) == PLUS
2458 && GET_CODE (XEXP (x, 0)) == REG
2459 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2460 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2461 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2462 || TARGET_POWERPC64
fcce224d 2463 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2464 && (TARGET_POWERPC64 || mode != DImode)
2465 && mode != TImode)
2466 {
2467 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2468 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2469 }
0ac081f6
AH
2470 else if (ALTIVEC_VECTOR_MODE (mode))
2471 {
2472 rtx reg;
2473
2474 /* Make sure both operands are registers. */
2475 if (GET_CODE (x) == PLUS)
9f85ed45 2476 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2477 force_reg (Pmode, XEXP (x, 1)));
2478
2479 reg = force_reg (Pmode, x);
2480 return reg;
2481 }
a3170dc6
AH
2482 else if (SPE_VECTOR_MODE (mode))
2483 {
2484 /* We accept [reg + reg] and [reg + OFFSET]. */
2485
2486 if (GET_CODE (x) == PLUS)
2487 {
2488 rtx op1 = XEXP (x, 0);
2489 rtx op2 = XEXP (x, 1);
2490
2491 op1 = force_reg (Pmode, op1);
2492
2493 if (GET_CODE (op2) != REG
2494 && (GET_CODE (op2) != CONST_INT
2495 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2496 op2 = force_reg (Pmode, op2);
2497
2498 return gen_rtx_PLUS (Pmode, op1, op2);
2499 }
2500
2501 return force_reg (Pmode, x);
2502 }
f1384257
AM
2503 else if (TARGET_ELF
2504 && TARGET_32BIT
2505 && TARGET_NO_TOC
2506 && ! flag_pic
9ebbca7d
GK
2507 && GET_CODE (x) != CONST_INT
2508 && GET_CODE (x) != CONST_DOUBLE
2509 && CONSTANT_P (x)
6ac7bf2c
GK
2510 && GET_MODE_NUNITS (mode) == 1
2511 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2512 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2513 {
2514 rtx reg = gen_reg_rtx (Pmode);
2515 emit_insn (gen_elf_high (reg, (x)));
2516 return gen_rtx_LO_SUM (Pmode, reg, (x));
2517 }
ee890fe2
SS
2518 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2519 && ! flag_pic
ab82a49f
AP
2520#if TARGET_MACHO
2521 && ! MACHO_DYNAMIC_NO_PIC_P
2522#endif
ee890fe2
SS
2523 && GET_CODE (x) != CONST_INT
2524 && GET_CODE (x) != CONST_DOUBLE
2525 && CONSTANT_P (x)
a3170dc6 2526 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2527 && mode != DImode
2528 && mode != TImode)
2529 {
2530 rtx reg = gen_reg_rtx (Pmode);
2531 emit_insn (gen_macho_high (reg, (x)));
2532 return gen_rtx_LO_SUM (Pmode, reg, (x));
2533 }
9ebbca7d 2534 else if (TARGET_TOC
4d588c14 2535 && constant_pool_expr_p (x)
a9098fd0 2536 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2537 {
2538 return create_TOC_reference (x);
2539 }
2540 else
2541 return NULL_RTX;
2542}
258bfae2 2543
c4501e62
JJ
2544/* Construct the SYMBOL_REF for the tls_get_addr function. */
2545
2546static GTY(()) rtx rs6000_tls_symbol;
2547static rtx
863d938c 2548rs6000_tls_get_addr (void)
c4501e62
JJ
2549{
2550 if (!rs6000_tls_symbol)
2551 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2552
2553 return rs6000_tls_symbol;
2554}
2555
2556/* Construct the SYMBOL_REF for TLS GOT references. */
2557
2558static GTY(()) rtx rs6000_got_symbol;
2559static rtx
863d938c 2560rs6000_got_sym (void)
c4501e62
JJ
2561{
2562 if (!rs6000_got_symbol)
2563 {
2564 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2565 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2566 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2567 }
2568
2569 return rs6000_got_symbol;
2570}
2571
2572/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2573 this (thread-local) address. */
2574
2575static rtx
a2369ed3 2576rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2577{
2578 rtx dest, insn;
2579
2580 dest = gen_reg_rtx (Pmode);
2581 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2582 {
2583 rtx tlsreg;
2584
2585 if (TARGET_64BIT)
2586 {
2587 tlsreg = gen_rtx_REG (Pmode, 13);
2588 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2589 }
2590 else
2591 {
2592 tlsreg = gen_rtx_REG (Pmode, 2);
2593 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2594 }
2595 emit_insn (insn);
2596 }
2597 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2598 {
2599 rtx tlsreg, tmp;
2600
2601 tmp = gen_reg_rtx (Pmode);
2602 if (TARGET_64BIT)
2603 {
2604 tlsreg = gen_rtx_REG (Pmode, 13);
2605 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2606 }
2607 else
2608 {
2609 tlsreg = gen_rtx_REG (Pmode, 2);
2610 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2611 }
2612 emit_insn (insn);
2613 if (TARGET_64BIT)
2614 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2615 else
2616 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2617 emit_insn (insn);
2618 }
2619 else
2620 {
2621 rtx r3, got, tga, tmp1, tmp2, eqv;
2622
2623 if (TARGET_64BIT)
2624 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2625 else
2626 {
2627 if (flag_pic == 1)
2628 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2629 else
2630 {
2631 rtx gsym = rs6000_got_sym ();
2632 got = gen_reg_rtx (Pmode);
2633 if (flag_pic == 0)
2634 rs6000_emit_move (got, gsym, Pmode);
2635 else
2636 {
2637 char buf[30];
2638 static int tls_got_labelno = 0;
2639 rtx tempLR, lab, tmp3, mem;
2640 rtx first, last;
2641
2642 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2643 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2644 tempLR = gen_reg_rtx (Pmode);
2645 tmp1 = gen_reg_rtx (Pmode);
2646 tmp2 = gen_reg_rtx (Pmode);
2647 tmp3 = gen_reg_rtx (Pmode);
2648 mem = gen_rtx_MEM (Pmode, tmp1);
2649 RTX_UNCHANGING_P (mem) = 1;
2650
2651 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2652 gsym));
2653 emit_move_insn (tmp1, tempLR);
2654 emit_move_insn (tmp2, mem);
2655 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2656 last = emit_move_insn (got, tmp3);
2657 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2658 REG_NOTES (last));
2659 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2660 REG_NOTES (first));
2661 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2662 REG_NOTES (last));
2663 }
2664 }
2665 }
2666
2667 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2668 {
2669 r3 = gen_rtx_REG (Pmode, 3);
2670 if (TARGET_64BIT)
2671 insn = gen_tls_gd_64 (r3, got, addr);
2672 else
2673 insn = gen_tls_gd_32 (r3, got, addr);
2674 start_sequence ();
2675 emit_insn (insn);
2676 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2677 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2678 insn = emit_call_insn (insn);
2679 CONST_OR_PURE_CALL_P (insn) = 1;
2680 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2681 insn = get_insns ();
2682 end_sequence ();
2683 emit_libcall_block (insn, dest, r3, addr);
2684 }
2685 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2686 {
2687 r3 = gen_rtx_REG (Pmode, 3);
2688 if (TARGET_64BIT)
2689 insn = gen_tls_ld_64 (r3, got);
2690 else
2691 insn = gen_tls_ld_32 (r3, got);
2692 start_sequence ();
2693 emit_insn (insn);
2694 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2695 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2696 insn = emit_call_insn (insn);
2697 CONST_OR_PURE_CALL_P (insn) = 1;
2698 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2699 insn = get_insns ();
2700 end_sequence ();
2701 tmp1 = gen_reg_rtx (Pmode);
2702 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2703 UNSPEC_TLSLD);
2704 emit_libcall_block (insn, tmp1, r3, eqv);
2705 if (rs6000_tls_size == 16)
2706 {
2707 if (TARGET_64BIT)
2708 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
2709 else
2710 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
2711 }
2712 else if (rs6000_tls_size == 32)
2713 {
2714 tmp2 = gen_reg_rtx (Pmode);
2715 if (TARGET_64BIT)
2716 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
2717 else
2718 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
2719 emit_insn (insn);
2720 if (TARGET_64BIT)
2721 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
2722 else
2723 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
2724 }
2725 else
2726 {
2727 tmp2 = gen_reg_rtx (Pmode);
2728 if (TARGET_64BIT)
2729 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
2730 else
2731 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
2732 emit_insn (insn);
2733 insn = gen_rtx_SET (Pmode, dest,
2734 gen_rtx_PLUS (Pmode, tmp2, tmp1));
2735 }
2736 emit_insn (insn);
2737 }
2738 else
2739 {
2740 /* IE, or 64 bit offset LE. */
2741 tmp2 = gen_reg_rtx (Pmode);
2742 if (TARGET_64BIT)
2743 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
2744 else
2745 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
2746 emit_insn (insn);
2747 if (TARGET_64BIT)
2748 insn = gen_tls_tls_64 (dest, tmp2, addr);
2749 else
2750 insn = gen_tls_tls_32 (dest, tmp2, addr);
2751 emit_insn (insn);
2752 }
2753 }
2754
2755 return dest;
2756}
2757
2758/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
2759 instruction definitions. */
2760
2761int
a2369ed3 2762rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
2763{
2764 return RS6000_SYMBOL_REF_TLS_P (x);
2765}
2766
2767/* Return 1 if X contains a thread-local symbol. */
2768
2769bool
a2369ed3 2770rs6000_tls_referenced_p (rtx x)
c4501e62
JJ
2771{
2772 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
2773}
2774
2775/* Return 1 if *X is a thread-local symbol. This is the same as
2776 rs6000_tls_symbol_ref except for the type of the unused argument. */
2777
2778static inline int
a2369ed3 2779rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
2780{
2781 return RS6000_SYMBOL_REF_TLS_P (*x);
2782}
2783
24ea750e
DJ
2784/* The convention appears to be to define this wherever it is used.
2785 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2786 is now used here. */
2787#ifndef REG_MODE_OK_FOR_BASE_P
2788#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2789#endif
2790
2791/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2792 replace the input X, or the original X if no replacement is called for.
2793 The output parameter *WIN is 1 if the calling macro should goto WIN,
2794 0 if it should not.
2795
2796 For RS/6000, we wish to handle large displacements off a base
2797 register by splitting the addend across an addiu/addis and the mem insn.
2798 This cuts number of extra insns needed from 3 to 1.
2799
2800 On Darwin, we use this to generate code for floating point constants.
2801 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2802 The Darwin code is inside #if TARGET_MACHO because only then is
2803 machopic_function_base_name() defined. */
2804rtx
a2369ed3
DJ
2805rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
2806 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
2807{
2808 /* We must recognize output that we have already generated ourselves. */
2809 if (GET_CODE (x) == PLUS
2810 && GET_CODE (XEXP (x, 0)) == PLUS
2811 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2812 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2813 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2814 {
2815 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2816 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2817 opnum, (enum reload_type)type);
2818 *win = 1;
2819 return x;
2820 }
3deb2758 2821
24ea750e
DJ
2822#if TARGET_MACHO
2823 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2824 && GET_CODE (x) == LO_SUM
2825 && GET_CODE (XEXP (x, 0)) == PLUS
2826 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2827 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2828 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2829 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2830 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2831 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2832 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2833 {
2834 /* Result of previous invocation of this function on Darwin
6f317ef3 2835 floating point constant. */
24ea750e
DJ
2836 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2837 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2838 opnum, (enum reload_type)type);
2839 *win = 1;
2840 return x;
2841 }
2842#endif
2843 if (GET_CODE (x) == PLUS
2844 && GET_CODE (XEXP (x, 0)) == REG
2845 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2846 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 2847 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 2848 && !SPE_VECTOR_MODE (mode)
78c875e8 2849 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
2850 {
2851 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2852 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2853 HOST_WIDE_INT high
2854 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2855
2856 /* Check for 32-bit overflow. */
2857 if (high + low != val)
2858 {
2859 *win = 0;
2860 return x;
2861 }
2862
2863 /* Reload the high part into a base reg; leave the low part
2864 in the mem directly. */
2865
2866 x = gen_rtx_PLUS (GET_MODE (x),
2867 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2868 GEN_INT (high)),
2869 GEN_INT (low));
2870
2871 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2872 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2873 opnum, (enum reload_type)type);
2874 *win = 1;
2875 return x;
2876 }
2877#if TARGET_MACHO
2878 if (GET_CODE (x) == SYMBOL_REF
2879 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 2880 && !ALTIVEC_VECTOR_MODE (mode)
24ea750e
DJ
2881 && flag_pic)
2882 {
2883 /* Darwin load of floating point constant. */
2884 rtx offset = gen_rtx (CONST, Pmode,
2885 gen_rtx (MINUS, Pmode, x,
2886 gen_rtx (SYMBOL_REF, Pmode,
2887 machopic_function_base_name ())));
2888 x = gen_rtx (LO_SUM, GET_MODE (x),
2889 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
2890 gen_rtx (HIGH, Pmode, offset)), offset);
2891 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2892 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2893 opnum, (enum reload_type)type);
2894 *win = 1;
2895 return x;
2896 }
ab82a49f
AP
2897 if (GET_CODE (x) == SYMBOL_REF
2898 && DEFAULT_ABI == ABI_DARWIN
2899 && !ALTIVEC_VECTOR_MODE (mode)
2900 && MACHO_DYNAMIC_NO_PIC_P)
2901 {
2902 /* Darwin load of floating point constant. */
2903 x = gen_rtx (LO_SUM, GET_MODE (x),
2904 gen_rtx (HIGH, Pmode, x), x);
2905 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2906 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2907 opnum, (enum reload_type)type);
2908 *win = 1;
2909 return x;
2910 }
24ea750e
DJ
2911#endif
2912 if (TARGET_TOC
4d588c14 2913 && constant_pool_expr_p (x)
c1f11548 2914 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
2915 {
2916 (x) = create_TOC_reference (x);
2917 *win = 1;
2918 return x;
2919 }
2920 *win = 0;
2921 return x;
2922}
2923
258bfae2
FS
2924/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2925 that is a valid memory address for an instruction.
2926 The MODE argument is the machine mode for the MEM expression
2927 that wants to use this address.
2928
2929 On the RS/6000, there are four valid address: a SYMBOL_REF that
2930 refers to a constant pool entry of an address (or the sum of it
2931 plus a constant), a short (16-bit signed) constant plus a register,
2932 the sum of two registers, or a register indirect, possibly with an
5bdc5878 2933 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
2934 we must ensure that both words are addressable or PowerPC64 with offset
2935 word aligned.
2936
2937 For modes spanning multiple registers (DFmode in 32-bit GPRs,
2938 32-bit DImode, TImode), indexed addressing cannot be used because
2939 adjacent memory cells are accessed by adding word-sized offsets
2940 during assembly output. */
2941int
a2369ed3 2942rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 2943{
c4501e62
JJ
2944 if (RS6000_SYMBOL_REF_TLS_P (x))
2945 return 0;
4d588c14 2946 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
2947 return 1;
2948 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 2949 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 2950 && !SPE_VECTOR_MODE (mode)
258bfae2 2951 && TARGET_UPDATE
4d588c14 2952 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 2953 return 1;
4d588c14 2954 if (legitimate_small_data_p (mode, x))
258bfae2 2955 return 1;
4d588c14 2956 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
2957 return 1;
2958 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
2959 if (! reg_ok_strict
2960 && GET_CODE (x) == PLUS
2961 && GET_CODE (XEXP (x, 0)) == REG
2962 && XEXP (x, 0) == virtual_stack_vars_rtx
2963 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2964 return 1;
4d588c14 2965 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
2966 return 1;
2967 if (mode != TImode
a3170dc6
AH
2968 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2969 || TARGET_POWERPC64
fcce224d 2970 || (mode != DFmode && mode != TFmode))
258bfae2 2971 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 2972 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 2973 return 1;
4d588c14 2974 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
2975 return 1;
2976 return 0;
2977}
4d588c14
RH
2978
2979/* Go to LABEL if ADDR (a legitimate address expression)
2980 has an effect that depends on the machine mode it is used for.
2981
2982 On the RS/6000 this is true of all integral offsets (since AltiVec
2983 modes don't allow them) or is a pre-increment or decrement.
2984
2985 ??? Except that due to conceptual problems in offsettable_address_p
2986 we can't really report the problems of integral offsets. So leave
2987 this assuming that the adjustable offset must be valid for the
2988 sub-words of a TFmode operand, which is what we had before. */
2989
2990bool
a2369ed3 2991rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
2992{
2993 switch (GET_CODE (addr))
2994 {
2995 case PLUS:
2996 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2997 {
2998 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
2999 return val + 12 + 0x8000 >= 0x10000;
3000 }
3001 break;
3002
3003 case LO_SUM:
3004 return true;
3005
3006 case PRE_INC:
3007 case PRE_DEC:
3008 return TARGET_UPDATE;
3009
3010 default:
3011 break;
3012 }
3013
3014 return false;
3015}
fb4d4348 3016\f
a4f6c312
SS
3017/* Try to output insns to set TARGET equal to the constant C if it can
3018 be done in less than N insns. Do all computations in MODE.
3019 Returns the place where the output has been placed if it can be
3020 done and the insns have been emitted. If it would take more than N
3021 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3022
3023rtx
a2369ed3
DJ
3024rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3025 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3026{
af8cb5c5 3027 rtx result, insn, set;
2bfcf297
DB
3028 HOST_WIDE_INT c0, c1;
3029
af8cb5c5 3030 if (mode == QImode || mode == HImode)
2bfcf297
DB
3031 {
3032 if (dest == NULL)
3033 dest = gen_reg_rtx (mode);
3034 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3035 return dest;
3036 }
af8cb5c5 3037 else if (mode == SImode)
2bfcf297 3038 {
af8cb5c5
DE
3039 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3040
3041 emit_insn (gen_rtx_SET (VOIDmode, result,
3042 GEN_INT (INTVAL (source)
3043 & (~ (HOST_WIDE_INT) 0xffff))));
3044 emit_insn (gen_rtx_SET (VOIDmode, dest,
3045 gen_rtx_IOR (SImode, result,
3046 GEN_INT (INTVAL (source) & 0xffff))));
3047 result = dest;
2bfcf297 3048 }
af8cb5c5 3049 else if (mode == DImode)
2bfcf297 3050 {
af8cb5c5
DE
3051 if (GET_CODE (source) == CONST_INT)
3052 {
3053 c0 = INTVAL (source);
3054 c1 = -(c0 < 0);
3055 }
3056 else if (GET_CODE (source) == CONST_DOUBLE)
3057 {
2bfcf297 3058#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3059 c0 = CONST_DOUBLE_LOW (source);
3060 c1 = -(c0 < 0);
2bfcf297 3061#else
af8cb5c5
DE
3062 c0 = CONST_DOUBLE_LOW (source);
3063 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3064#endif
af8cb5c5
DE
3065 }
3066 else
3067 abort ();
3068
3069 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3070 }
3071 else
a4f6c312 3072 abort ();
2bfcf297 3073
af8cb5c5
DE
3074 insn = get_last_insn ();
3075 set = single_set (insn);
3076 if (! CONSTANT_P (SET_SRC (set)))
3077 set_unique_reg_note (insn, REG_EQUAL, source);
3078
3079 return result;
2bfcf297
DB
3080}
3081
3082/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3083 fall back to a straight forward decomposition. We do this to avoid
3084 exponential run times encountered when looking for longer sequences
3085 with rs6000_emit_set_const. */
3086static rtx
a2369ed3 3087rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3088{
3089 if (!TARGET_POWERPC64)
3090 {
3091 rtx operand1, operand2;
3092
3093 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3094 DImode);
3095 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3096 DImode);
3097 emit_move_insn (operand1, GEN_INT (c1));
3098 emit_move_insn (operand2, GEN_INT (c2));
3099 }
3100 else
3101 {
bc06712d 3102 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3103
bc06712d
TR
3104 ud1 = c1 & 0xffff;
3105 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3106#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3107 c2 = c1 >> 32;
2bfcf297 3108#endif
bc06712d
TR
3109 ud3 = c2 & 0xffff;
3110 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3111
bc06712d
TR
3112 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3113 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3114 {
bc06712d
TR
3115 if (ud1 & 0x8000)
3116 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
3117 else
3118 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3119 }
2bfcf297 3120
bc06712d
TR
3121 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3122 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3123 {
bc06712d
TR
3124 if (ud2 & 0x8000)
3125 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3126 - 0x80000000));
252b88f7 3127 else
bc06712d
TR
3128 emit_move_insn (dest, GEN_INT (ud2 << 16));
3129 if (ud1 != 0)
3130 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3131 }
bc06712d
TR
3132 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3133 || (ud4 == 0 && ! (ud3 & 0x8000)))
3134 {
3135 if (ud3 & 0x8000)
3136 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3137 - 0x80000000));
3138 else
3139 emit_move_insn (dest, GEN_INT (ud3 << 16));
3140
3141 if (ud2 != 0)
3142 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3143 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3144 if (ud1 != 0)
3145 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3146 }
3147 else
3148 {
3149 if (ud4 & 0x8000)
3150 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3151 - 0x80000000));
3152 else
3153 emit_move_insn (dest, GEN_INT (ud4 << 16));
3154
3155 if (ud3 != 0)
3156 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3157
bc06712d
TR
3158 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3159 if (ud2 != 0)
3160 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3161 GEN_INT (ud2 << 16)));
3162 if (ud1 != 0)
3163 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3164 }
3165 }
2bfcf297
DB
3166 return dest;
3167}
3168
fb4d4348
GK
3169/* Emit a move from SOURCE to DEST in mode MODE. */
3170void
a2369ed3 3171rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3172{
3173 rtx operands[2];
3174 operands[0] = dest;
3175 operands[1] = source;
3176
3177 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3178 if (GET_CODE (operands[1]) == CONST_DOUBLE
3179 && ! FLOAT_MODE_P (mode)
3180 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3181 {
3182 /* FIXME. This should never happen. */
3183 /* Since it seems that it does, do the safe thing and convert
3184 to a CONST_INT. */
2496c7bd 3185 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3186 }
3187 if (GET_CODE (operands[1]) == CONST_DOUBLE
3188 && ! FLOAT_MODE_P (mode)
3189 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3190 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3191 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3192 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3193 abort ();
c9e8cb32
DD
3194
3195 /* Check if GCC is setting up a block move that will end up using FP
3196 registers as temporaries. We must make sure this is acceptable. */
3197 if (GET_CODE (operands[0]) == MEM
3198 && GET_CODE (operands[1]) == MEM
3199 && mode == DImode
41543739
GK
3200 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3201 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3202 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3203 ? 32 : MEM_ALIGN (operands[0])))
3204 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3205 ? 32
3206 : MEM_ALIGN (operands[1]))))
3207 && ! MEM_VOLATILE_P (operands [0])
3208 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3209 {
41543739
GK
3210 emit_move_insn (adjust_address (operands[0], SImode, 0),
3211 adjust_address (operands[1], SImode, 0));
3212 emit_move_insn (adjust_address (operands[0], SImode, 4),
3213 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3214 return;
3215 }
fb4d4348 3216
67cef334
DE
3217 if (!no_new_pseudos)
3218 {
3219 if (GET_CODE (operands[1]) == MEM && optimize > 0
3220 && (mode == QImode || mode == HImode || mode == SImode)
3221 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3222 {
3223 rtx reg = gen_reg_rtx (word_mode);
3224
3225 emit_insn (gen_rtx_SET (word_mode, reg,
3226 gen_rtx_ZERO_EXTEND (word_mode,
3227 operands[1])));
3228 operands[1] = gen_lowpart (mode, reg);
3229 }
3230 if (GET_CODE (operands[0]) != REG)
3231 operands[1] = force_reg (mode, operands[1]);
3232 }
a9098fd0 3233
a3170dc6
AH
3234 if (mode == SFmode && ! TARGET_POWERPC
3235 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3236 && GET_CODE (operands[0]) == MEM)
fb4d4348 3237 {
ffc14f31
GK
3238 int regnum;
3239
3240 if (reload_in_progress || reload_completed)
3241 regnum = true_regnum (operands[1]);
3242 else if (GET_CODE (operands[1]) == REG)
3243 regnum = REGNO (operands[1]);
3244 else
3245 regnum = -1;
fb4d4348
GK
3246
3247 /* If operands[1] is a register, on POWER it may have
3248 double-precision data in it, so truncate it to single
3249 precision. */
3250 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3251 {
3252 rtx newreg;
3253 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3254 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3255 operands[1] = newreg;
3256 }
3257 }
3258
c4501e62
JJ
3259 /* Recognize the case where operand[1] is a reference to thread-local
3260 data and load its address to a register. */
3261 if (GET_CODE (operands[1]) == SYMBOL_REF)
3262 {
3263 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3264 if (model != 0)
3265 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3266 }
3267
8f4e6caf
RH
3268 /* Handle the case where reload calls us with an invalid address. */
3269 if (reload_in_progress && mode == Pmode
69ef87e2 3270 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3271 || ! nonimmediate_operand (operands[0], mode)))
3272 goto emit_set;
3273
3274 /* Handle the case of CONSTANT_P_RTX. */
3275 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3276 goto emit_set;
a9098fd0 3277
fb4d4348
GK
3278 /* FIXME: In the long term, this switch statement should go away
3279 and be replaced by a sequence of tests based on things like
3280 mode == Pmode. */
3281 switch (mode)
3282 {
3283 case HImode:
3284 case QImode:
3285 if (CONSTANT_P (operands[1])
3286 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3287 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3288 break;
3289
06f4e019 3290 case TFmode:
fb4d4348
GK
3291 case DFmode:
3292 case SFmode:
3293 if (CONSTANT_P (operands[1])
3294 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3295 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3296 break;
3297
0ac081f6
AH
3298 case V16QImode:
3299 case V8HImode:
3300 case V4SFmode:
3301 case V4SImode:
a3170dc6
AH
3302 case V4HImode:
3303 case V2SFmode:
3304 case V2SImode:
00a892b8 3305 case V1DImode:
69ef87e2 3306 if (CONSTANT_P (operands[1])
d744e06e 3307 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3308 operands[1] = force_const_mem (mode, operands[1]);
3309 break;
3310
fb4d4348 3311 case SImode:
a9098fd0 3312 case DImode:
fb4d4348
GK
3313 /* Use default pattern for address of ELF small data */
3314 if (TARGET_ELF
a9098fd0 3315 && mode == Pmode
f607bc57 3316 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3317 && (GET_CODE (operands[1]) == SYMBOL_REF
3318 || GET_CODE (operands[1]) == CONST)
3319 && small_data_operand (operands[1], mode))
fb4d4348
GK
3320 {
3321 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3322 return;
3323 }
3324
f607bc57 3325 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3326 && mode == Pmode && mode == SImode
3327 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3328 {
3329 emit_insn (gen_movsi_got (operands[0], operands[1]));
3330 return;
3331 }
3332
ee890fe2 3333 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3334 && TARGET_NO_TOC
3335 && ! flag_pic
a9098fd0 3336 && mode == Pmode
fb4d4348
GK
3337 && CONSTANT_P (operands[1])
3338 && GET_CODE (operands[1]) != HIGH
3339 && GET_CODE (operands[1]) != CONST_INT)
3340 {
a9098fd0 3341 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3342
3343 /* If this is a function address on -mcall-aixdesc,
3344 convert it to the address of the descriptor. */
3345 if (DEFAULT_ABI == ABI_AIX
3346 && GET_CODE (operands[1]) == SYMBOL_REF
3347 && XSTR (operands[1], 0)[0] == '.')
3348 {
3349 const char *name = XSTR (operands[1], 0);
3350 rtx new_ref;
3351 while (*name == '.')
3352 name++;
3353 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3354 CONSTANT_POOL_ADDRESS_P (new_ref)
3355 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3356 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3357 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3358 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3359 operands[1] = new_ref;
3360 }
7509c759 3361
ee890fe2
SS
3362 if (DEFAULT_ABI == ABI_DARWIN)
3363 {
ab82a49f
AP
3364#if TARGET_MACHO
3365 if (MACHO_DYNAMIC_NO_PIC_P)
3366 {
3367 /* Take care of any required data indirection. */
3368 operands[1] = rs6000_machopic_legitimize_pic_address (
3369 operands[1], mode, operands[0]);
3370 if (operands[0] != operands[1])
3371 emit_insn (gen_rtx_SET (VOIDmode,
3372 operands[0], operands[1]));
3373 return;
3374 }
3375#endif
ee890fe2
SS
3376 emit_insn (gen_macho_high (target, operands[1]));
3377 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3378 return;
3379 }
3380
fb4d4348
GK
3381 emit_insn (gen_elf_high (target, operands[1]));
3382 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3383 return;
3384 }
3385
a9098fd0
GK
3386 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3387 and we have put it in the TOC, we just need to make a TOC-relative
3388 reference to it. */
3389 if (TARGET_TOC
3390 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3391 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3392 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3393 get_pool_mode (operands[1])))
fb4d4348 3394 {
a9098fd0 3395 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3396 }
a9098fd0
GK
3397 else if (mode == Pmode
3398 && CONSTANT_P (operands[1])
38886f37
AO
3399 && ((GET_CODE (operands[1]) != CONST_INT
3400 && ! easy_fp_constant (operands[1], mode))
3401 || (GET_CODE (operands[1]) == CONST_INT
3402 && num_insns_constant (operands[1], mode) > 2)
3403 || (GET_CODE (operands[0]) == REG
3404 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3405 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3406 && ! legitimate_constant_pool_address_p (operands[1])
3407 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3408 {
3409 /* Emit a USE operation so that the constant isn't deleted if
3410 expensive optimizations are turned on because nobody
3411 references it. This should only be done for operands that
3412 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3413 This should not be done for operands that contain LABEL_REFs.
3414 For now, we just handle the obvious case. */
3415 if (GET_CODE (operands[1]) != LABEL_REF)
3416 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3417
c859cda6 3418#if TARGET_MACHO
ee890fe2 3419 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3420 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3421 {
ee890fe2
SS
3422 operands[1] =
3423 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3424 operands[0]);
3425 if (operands[0] != operands[1])
3426 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3427 return;
3428 }
c859cda6 3429#endif
ee890fe2 3430
fb4d4348
GK
3431 /* If we are to limit the number of things we put in the TOC and
3432 this is a symbol plus a constant we can add in one insn,
3433 just put the symbol in the TOC and add the constant. Don't do
3434 this if reload is in progress. */
3435 if (GET_CODE (operands[1]) == CONST
3436 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3437 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3438 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3439 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3440 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3441 && ! side_effects_p (operands[0]))
3442 {
a4f6c312
SS
3443 rtx sym =
3444 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3445 rtx other = XEXP (XEXP (operands[1], 0), 1);
3446
a9098fd0
GK
3447 sym = force_reg (mode, sym);
3448 if (mode == SImode)
3449 emit_insn (gen_addsi3 (operands[0], sym, other));
3450 else
3451 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3452 return;
3453 }
3454
a9098fd0 3455 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3456
3457 if (TARGET_TOC
4d588c14 3458 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3459 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3460 get_pool_constant (XEXP (operands[1], 0)),
3461 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3462 {
ba4828e0
RK
3463 operands[1]
3464 = gen_rtx_MEM (mode,
3465 create_TOC_reference (XEXP (operands[1], 0)));
3466 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3467 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3468 }
fb4d4348
GK
3469 }
3470 break;
a9098fd0 3471
fb4d4348
GK
3472 case TImode:
3473 if (GET_CODE (operands[0]) == MEM
3474 && GET_CODE (XEXP (operands[0], 0)) != REG
3475 && ! reload_in_progress)
792760b9
RK
3476 operands[0]
3477 = replace_equiv_address (operands[0],
3478 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3479
3480 if (GET_CODE (operands[1]) == MEM
3481 && GET_CODE (XEXP (operands[1], 0)) != REG
3482 && ! reload_in_progress)
792760b9
RK
3483 operands[1]
3484 = replace_equiv_address (operands[1],
3485 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3486 if (TARGET_POWER)
3487 {
3488 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3489 gen_rtvec (2,
3490 gen_rtx_SET (VOIDmode,
3491 operands[0], operands[1]),
3492 gen_rtx_CLOBBER (VOIDmode,
3493 gen_rtx_SCRATCH (SImode)))));
3494 return;
3495 }
fb4d4348
GK
3496 break;
3497
3498 default:
3499 abort ();
3500 }
3501
a9098fd0
GK
3502 /* Above, we may have called force_const_mem which may have returned
3503 an invalid address. If we can, fix this up; otherwise, reload will
3504 have to deal with it. */
8f4e6caf
RH
3505 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3506 operands[1] = validize_mem (operands[1]);
a9098fd0 3507
8f4e6caf 3508 emit_set:
fb4d4348
GK
3509 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3510}
4697a36c
MM
3511\f
3512/* Initialize a variable CUM of type CUMULATIVE_ARGS
3513 for a call to a function whose data type is FNTYPE.
3514 For a library call, FNTYPE is 0.
3515
3516 For incoming args we set the number of arguments in the prototype large
1c20ae99 3517 so we never return a PARALLEL. */
4697a36c
MM
3518
3519void
a2369ed3
DJ
3520init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
3521 rtx libname ATTRIBUTE_UNUSED, int incoming, int libcall)
4697a36c
MM
3522{
3523 static CUMULATIVE_ARGS zero_cumulative;
3524
3525 *cum = zero_cumulative;
3526 cum->words = 0;
3527 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3528 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3529 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3530 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3531 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3532 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3533 cum->stdarg = fntype
3534 && (TYPE_ARG_TYPES (fntype) != 0
3535 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3536 != void_type_node));
4697a36c
MM
3537
3538 if (incoming)
bd227acc 3539 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
3540
3541 else if (cum->prototype)
3542 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
3543 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
3544 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
3545
3546 else
3547 cum->nargs_prototype = 0;
3548
a5c76ee6
ZW
3549 /* Check for a longcall attribute. */
3550 if (fntype
3551 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3552 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3553 cum->call_cookie = CALL_LONG;
3554
4697a36c
MM
3555 if (TARGET_DEBUG_ARG)
3556 {
3557 fprintf (stderr, "\ninit_cumulative_args:");
3558 if (fntype)
3559 {
3560 tree ret_type = TREE_TYPE (fntype);
3561 fprintf (stderr, " ret code = %s,",
3562 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3563 }
3564
6a4cee5f
MM
3565 if (cum->call_cookie & CALL_LONG)
3566 fprintf (stderr, " longcall,");
3567
4697a36c
MM
3568 fprintf (stderr, " proto = %d, nargs = %d\n",
3569 cum->prototype, cum->nargs_prototype);
3570 }
3571}
3572\f
c229cba9
DE
3573/* If defined, a C expression which determines whether, and in which
3574 direction, to pad out an argument with extra space. The value
3575 should be of type `enum direction': either `upward' to pad above
3576 the argument, `downward' to pad below, or `none' to inhibit
3577 padding.
3578
3579 For the AIX ABI structs are always stored left shifted in their
3580 argument slot. */
3581
9ebbca7d 3582enum direction
a2369ed3 3583function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3584{
6e985040
AM
3585#ifndef AGGREGATE_PADDING_FIXED
3586#define AGGREGATE_PADDING_FIXED 0
3587#endif
3588#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3589#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3590#endif
3591
3592 if (!AGGREGATE_PADDING_FIXED)
3593 {
3594 /* GCC used to pass structures of the same size as integer types as
3595 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3596 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3597 passed padded downward, except that -mstrict-align further
3598 muddied the water in that multi-component structures of 2 and 4
3599 bytes in size were passed padded upward.
3600
3601 The following arranges for best compatibility with previous
3602 versions of gcc, but removes the -mstrict-align dependency. */
3603 if (BYTES_BIG_ENDIAN)
3604 {
3605 HOST_WIDE_INT size = 0;
3606
3607 if (mode == BLKmode)
3608 {
3609 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3610 size = int_size_in_bytes (type);
3611 }
3612 else
3613 size = GET_MODE_SIZE (mode);
3614
3615 if (size == 1 || size == 2 || size == 4)
3616 return downward;
3617 }
3618 return upward;
3619 }
3620
3621 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3622 {
3623 if (type != 0 && AGGREGATE_TYPE_P (type))
3624 return upward;
3625 }
c229cba9 3626
d3704c46
KH
3627 /* Fall back to the default. */
3628 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
3629}
3630
b6c9286a
MM
3631/* If defined, a C expression that gives the alignment boundary, in bits,
3632 of an argument with the specified mode and type. If it is not defined,
3633 PARM_BOUNDARY is used for all arguments.
3634
2310f99a 3635 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3636
3637int
a2369ed3 3638function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 3639{
f607bc57 3640 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3641 return 64;
a3170dc6
AH
3642 else if (SPE_VECTOR_MODE (mode))
3643 return 64;
0ac081f6
AH
3644 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3645 return 128;
9ebbca7d 3646 else
b6c9286a 3647 return PARM_BOUNDARY;
b6c9286a
MM
3648}
3649\f
4697a36c
MM
3650/* Update the data in CUM to advance over an argument
3651 of mode MODE and data type TYPE.
3652 (TYPE is null for libcalls where that information may not be available.) */
3653
3654void
a2369ed3
DJ
3655function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3656 tree type, int named)
4697a36c
MM
3657{
3658 cum->nargs_prototype--;
3659
0ac081f6
AH
3660 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3661 {
3662 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
3663 cum->vregno++;
3664 else
3665 cum->words += RS6000_ARG_SIZE (mode, type);
3666 }
a4b0320c 3667 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
3668 && !cum->stdarg
3669 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 3670 cum->sysv_gregno++;
f607bc57 3671 else if (DEFAULT_ABI == ABI_V4)
4697a36c 3672 {
a3170dc6 3673 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 3674 && (mode == SFmode || mode == DFmode))
4697a36c 3675 {
4cc833b7
RH
3676 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3677 cum->fregno++;
3678 else
3679 {
3680 if (mode == DFmode)
3681 cum->words += cum->words & 1;
d34c5b80 3682 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 3683 }
4697a36c 3684 }
4cc833b7
RH
3685 else
3686 {
3687 int n_words;
3688 int gregno = cum->sysv_gregno;
3689
3690 /* Aggregates and IEEE quad get passed by reference. */
3691 if ((type && AGGREGATE_TYPE_P (type))
3692 || mode == TFmode)
3693 n_words = 1;
3694 else
d34c5b80 3695 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3696
a4b0320c 3697 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3698 if (n_words == 2 && (gregno & 1) == 0)
3699 gregno += 1;
3700
a4b0320c
AH
3701 /* Long long and SPE vectors are not split between registers
3702 and stack. */
4cc833b7
RH
3703 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
3704 {
3705 /* Long long is aligned on the stack. */
3706 if (n_words == 2)
3707 cum->words += cum->words & 1;
3708 cum->words += n_words;
3709 }
4697a36c 3710
4cc833b7
RH
3711 /* Note: continuing to accumulate gregno past when we've started
3712 spilling to the stack indicates the fact that we've started
3713 spilling to the stack to expand_builtin_saveregs. */
3714 cum->sysv_gregno = gregno + n_words;
3715 }
4697a36c 3716
4cc833b7
RH
3717 if (TARGET_DEBUG_ARG)
3718 {
3719 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3720 cum->words, cum->fregno);
3721 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
3722 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
3723 fprintf (stderr, "mode = %4s, named = %d\n",
3724 GET_MODE_NAME (mode), named);
3725 }
4697a36c
MM
3726 }
3727 else
4cc833b7
RH
3728 {
3729 int align = (TARGET_32BIT && (cum->words & 1) != 0
3730 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 3731
d34c5b80 3732 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 3733
a3170dc6
AH
3734 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3735 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 3736 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
3737
3738 if (TARGET_DEBUG_ARG)
3739 {
3740 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3741 cum->words, cum->fregno);
3742 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
3743 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
3744 fprintf (stderr, "named = %d, align = %d\n", named, align);
3745 }
3746 }
4697a36c 3747}
a6c9bed4
AH
3748
3749/* Determine where to put a SIMD argument on the SPE. */
3750static rtx
a2369ed3
DJ
3751rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3752 tree type)
a6c9bed4
AH
3753{
3754 if (cum->stdarg)
3755 {
3756 int gregno = cum->sysv_gregno;
3757 int n_words = RS6000_ARG_SIZE (mode, type);
3758
3759 /* SPE vectors are put in odd registers. */
3760 if (n_words == 2 && (gregno & 1) == 0)
3761 gregno += 1;
3762
3763 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
3764 {
3765 rtx r1, r2;
3766 enum machine_mode m = SImode;
3767
3768 r1 = gen_rtx_REG (m, gregno);
3769 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
3770 r2 = gen_rtx_REG (m, gregno + 1);
3771 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
3772 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
3773 }
3774 else
3775 return NULL;
3776 }
3777 else
3778 {
3779 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
3780 return gen_rtx_REG (mode, cum->sysv_gregno);
3781 else
3782 return NULL;
3783 }
3784}
3785
4697a36c
MM
3786/* Determine where to put an argument to a function.
3787 Value is zero to push the argument on the stack,
3788 or a hard register in which to store the argument.
3789
3790 MODE is the argument's machine mode.
3791 TYPE is the data type of the argument (as a tree).
3792 This is null for libcalls where that information may
3793 not be available.
3794 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3795 the preceding args and about the function being called.
3796 NAMED is nonzero if this argument is a named parameter
3797 (otherwise it is an extra parameter matching an ellipsis).
3798
3799 On RS/6000 the first eight words of non-FP are normally in registers
3800 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
3801 Under V.4, the first 8 FP args are in registers.
3802
3803 If this is floating-point and no prototype is specified, we use
3804 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 3805 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 3806 so we can pass the FP value just in one register. emit_library_function
1c20ae99 3807 doesn't support PARALLEL anyway. */
4697a36c
MM
3808
3809struct rtx_def *
a2369ed3
DJ
3810function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3811 tree type, int named)
4697a36c 3812{
4cc833b7 3813 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 3814
a4f6c312
SS
3815 /* Return a marker to indicate whether CR1 needs to set or clear the
3816 bit that V.4 uses to say fp args were passed in registers.
3817 Assume that we don't need the marker for software floating point,
3818 or compiler generated library calls. */
4697a36c
MM
3819 if (mode == VOIDmode)
3820 {
f607bc57 3821 if (abi == ABI_V4
7509c759 3822 && cum->nargs_prototype < 0
b9599e46
FS
3823 && (cum->call_cookie & CALL_LIBCALL) == 0
3824 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 3825 {
a3170dc6
AH
3826 /* For the SPE, we need to crxor CR6 always. */
3827 if (TARGET_SPE_ABI)
3828 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
3829 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
3830 return GEN_INT (cum->call_cookie
3831 | ((cum->fregno == FP_ARG_MIN_REG)
3832 ? CALL_V4_SET_FP_ARGS
3833 : CALL_V4_CLEAR_FP_ARGS));
7509c759 3834 }
4697a36c 3835
7509c759 3836 return GEN_INT (cum->call_cookie);
4697a36c
MM
3837 }
3838
0ac081f6
AH
3839 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3840 {
20c29ebe 3841 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
3842 return gen_rtx_REG (mode, cum->vregno);
3843 else
3844 return NULL;
3845 }
a6c9bed4
AH
3846 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
3847 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 3848 else if (abi == ABI_V4)
4697a36c 3849 {
a3170dc6 3850 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
3851 && (mode == SFmode || mode == DFmode))
3852 {
3853 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3854 return gen_rtx_REG (mode, cum->fregno);
3855 else
3856 return NULL;
3857 }
3858 else
3859 {
3860 int n_words;
3861 int gregno = cum->sysv_gregno;
3862
3863 /* Aggregates and IEEE quad get passed by reference. */
3864 if ((type && AGGREGATE_TYPE_P (type))
3865 || mode == TFmode)
3866 n_words = 1;
3867 else
d34c5b80 3868 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3869
a4b0320c 3870 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3871 if (n_words == 2 && (gregno & 1) == 0)
3872 gregno += 1;
3873
a6c9bed4 3874 /* Long long do not split between registers and stack. */
4cc833b7 3875 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 3876 return gen_rtx_REG (mode, gregno);
4cc833b7
RH
3877 else
3878 return NULL;
3879 }
4697a36c 3880 }
4cc833b7
RH
3881 else
3882 {
3883 int align = (TARGET_32BIT && (cum->words & 1) != 0
3884 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
3885 int align_words = cum->words + align;
4697a36c 3886
4cc833b7
RH
3887 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3888 return NULL_RTX;
3889
3890 if (USE_FP_FOR_ARG_P (*cum, mode, type))
3891 {
3892 if (! type
3893 || ((cum->nargs_prototype > 0)
3894 /* IBM AIX extended its linkage convention definition always
3895 to require FP args after register save area hole on the
3896 stack. */
3897 && (DEFAULT_ABI != ABI_AIX
3898 || ! TARGET_XL_CALL
3899 || (align_words < GP_ARG_NUM_REG))))
3900 return gen_rtx_REG (mode, cum->fregno);
3901
3902 return gen_rtx_PARALLEL (mode,
3903 gen_rtvec (2,
39403d82 3904 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
3905 ((align_words >= GP_ARG_NUM_REG)
3906 ? NULL_RTX
3907 : (align_words
d34c5b80 3908 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
3909 > GP_ARG_NUM_REG
3910 /* If this is partially on the stack, then
3911 we only include the portion actually
3912 in registers here. */
39403d82 3913 ? gen_rtx_REG (SImode,
1c20ae99 3914 GP_ARG_MIN_REG + align_words)
39403d82 3915 : gen_rtx_REG (mode,
1c20ae99
JW
3916 GP_ARG_MIN_REG + align_words))),
3917 const0_rtx),
39403d82
DE
3918 gen_rtx_EXPR_LIST (VOIDmode,
3919 gen_rtx_REG (mode, cum->fregno),
1c20ae99 3920 const0_rtx)));
4cc833b7
RH
3921 }
3922 else if (align_words < GP_ARG_NUM_REG)
3923 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
3924 else
3925 return NULL_RTX;
4697a36c 3926 }
4697a36c
MM
3927}
3928\f
3929/* For an arg passed partly in registers and partly in memory,
3930 this is the number of registers used.
3931 For args passed entirely in registers or entirely in memory, zero. */
3932
3933int
a2369ed3
DJ
3934function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3935 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 3936{
f607bc57 3937 if (DEFAULT_ABI == ABI_V4)
4697a36c 3938 return 0;
4697a36c 3939
0ac081f6
AH
3940 if (USE_FP_FOR_ARG_P (*cum, mode, type)
3941 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
3942 {
3943 if (cum->nargs_prototype >= 0)
3944 return 0;
3945 }
3946
3947 if (cum->words < GP_ARG_NUM_REG
d34c5b80 3948 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
3949 {
3950 int ret = GP_ARG_NUM_REG - cum->words;
3951 if (ret && TARGET_DEBUG_ARG)
3952 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3953
3954 return ret;
3955 }
3956
3957 return 0;
3958}
3959\f
3960/* A C expression that indicates when an argument must be passed by
3961 reference. If nonzero for an argument, a copy of that argument is
3962 made in memory and a pointer to the argument is passed instead of
3963 the argument itself. The pointer is passed in whatever way is
3964 appropriate for passing a pointer to that type.
3965
c8c99a68
DE
3966 Under V.4, structures and unions are passed by reference.
3967
3968 As an extension to all ABIs, variable sized types are passed by
3969 reference. */
4697a36c
MM
3970
3971int
a2369ed3
DJ
3972function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
3973 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 3974 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 3975{
f607bc57 3976 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
3977 && ((type && AGGREGATE_TYPE_P (type))
3978 || mode == TFmode))
4697a36c
MM
3979 {
3980 if (TARGET_DEBUG_ARG)
3981 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
3982
3983 return 1;
3984 }
fff2cb99 3985 return type && int_size_in_bytes (type) < 0;
4697a36c 3986}
4697a36c
MM
3987\f
3988/* Perform any needed actions needed for a function that is receiving a
3989 variable number of arguments.
3990
3991 CUM is as above.
3992
3993 MODE and TYPE are the mode and type of the current parameter.
3994
3995 PRETEND_SIZE is a variable that should be set to the amount of stack
3996 that must be pushed by the prolog to pretend that our caller pushed
3997 it.
3998
3999 Normally, this macro will push all remaining incoming registers on the
4000 stack and set PRETEND_SIZE to the length of the registers pushed. */
4001
4002void
a2369ed3
DJ
4003setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4004 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4005{
4cc833b7
RH
4006 CUMULATIVE_ARGS next_cum;
4007 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4008 rtx save_area = NULL_RTX, mem;
dfafc897 4009 int first_reg_offset, set;
d34c5b80
DE
4010 tree fntype;
4011 int stdarg_p;
4697a36c 4012
d34c5b80
DE
4013 fntype = TREE_TYPE (current_function_decl);
4014 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
4015 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4016 != void_type_node));
4cc833b7 4017
d34c5b80
DE
4018 /* For varargs, we do not want to skip the dummy va_dcl argument.
4019 For stdargs, we do want to skip the last named argument. */
4020 next_cum = *cum;
4021 if (stdarg_p)
4022 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4023
f607bc57 4024 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4025 {
4cc833b7 4026 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4027 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4028 if (! no_rtl)
2c4974b7 4029 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4030 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4031
4032 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4033 }
60e2d0ca 4034 else
4697a36c 4035 {
d34c5b80 4036 first_reg_offset = next_cum.words;
4cc833b7 4037 save_area = virtual_incoming_args_rtx;
00dba523 4038 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4039
4040 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 4041 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 4042 }
4697a36c 4043
dfafc897 4044 set = get_varargs_alias_set ();
c81fc13e 4045 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4046 {
dfafc897
FS
4047 mem = gen_rtx_MEM (BLKmode,
4048 plus_constant (save_area,
4049 first_reg_offset * reg_size)),
ba4828e0 4050 set_mem_alias_set (mem, set);
8ac61af7 4051 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4052
c6b97fac
AM
4053 move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4054 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4055 }
4056
4697a36c 4057 /* Save FP registers if needed. */
f607bc57 4058 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4059 && TARGET_HARD_FLOAT && TARGET_FPRS
4060 && ! no_rtl
4cc833b7 4061 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4062 {
4cc833b7 4063 int fregno = next_cum.fregno;
9ebbca7d 4064 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4065 rtx lab = gen_label_rtx ();
4066 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4067
4cc833b7 4068 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4069 pc_rtx,
39403d82 4070 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4071 gen_rtx_NE (VOIDmode, cr1,
4072 const0_rtx),
39403d82 4073 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4074 pc_rtx)));
4075
4cc833b7
RH
4076 while (fregno <= FP_ARG_V4_MAX_REG)
4077 {
dfafc897 4078 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4079 set_mem_alias_set (mem, set);
dfafc897 4080 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4081 fregno++;
4082 off += 8;
4697a36c 4083 }
4cc833b7
RH
4084
4085 emit_label (lab);
4697a36c 4086 }
4697a36c 4087}
4697a36c 4088
dfafc897 4089/* Create the va_list data type. */
2c4974b7 4090
dfafc897 4091tree
863d938c 4092rs6000_build_va_list (void)
dfafc897 4093{
64c2816f 4094 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4095
9ebbca7d
GK
4096 /* For AIX, prefer 'char *' because that's what the system
4097 header files like. */
f607bc57 4098 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4099 return build_pointer_type (char_type_node);
dfafc897 4100
f1e639b1 4101 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4102 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4103
9ebbca7d
GK
4104 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4105 unsigned_char_type_node);
4106 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4107 unsigned_char_type_node);
64c2816f
DT
4108 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4109 every user file. */
4110 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4111 short_unsigned_type_node);
dfafc897
FS
4112 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4113 ptr_type_node);
4114 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4115 ptr_type_node);
4116
4117 DECL_FIELD_CONTEXT (f_gpr) = record;
4118 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4119 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4120 DECL_FIELD_CONTEXT (f_ovf) = record;
4121 DECL_FIELD_CONTEXT (f_sav) = record;
4122
bab45a51
FS
4123 TREE_CHAIN (record) = type_decl;
4124 TYPE_NAME (record) = type_decl;
dfafc897
FS
4125 TYPE_FIELDS (record) = f_gpr;
4126 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4127 TREE_CHAIN (f_fpr) = f_res;
4128 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4129 TREE_CHAIN (f_ovf) = f_sav;
4130
4131 layout_type (record);
4132
4133 /* The correct type is an array type of one element. */
4134 return build_array_type (record, build_index_type (size_zero_node));
4135}
4136
4137/* Implement va_start. */
4138
4139void
a2369ed3 4140rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4141{
dfafc897 4142 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4143 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4144 tree gpr, fpr, ovf, sav, t;
2c4974b7 4145
dfafc897 4146 /* Only SVR4 needs something special. */
f607bc57 4147 if (DEFAULT_ABI != ABI_V4)
dfafc897 4148 {
e5faf155 4149 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4150 return;
4151 }
4152
973a648b 4153 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4154 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4155 f_res = TREE_CHAIN (f_fpr);
4156 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4157 f_sav = TREE_CHAIN (f_ovf);
4158
8ebecc3b 4159 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4160 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4161 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4162 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4163 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4164
4165 /* Count number of gp and fp argument registers used. */
4cc833b7 4166 words = current_function_args_info.words;
dfafc897
FS
4167 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4168 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4169
4170 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4171 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4172 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4173 words, n_gpr, n_fpr);
dfafc897
FS
4174
4175 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4176 TREE_SIDE_EFFECTS (t) = 1;
4177 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4178
4179 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4180 TREE_SIDE_EFFECTS (t) = 1;
4181 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4182
4183 /* Find the overflow area. */
4184 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4185 if (words != 0)
4186 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4187 build_int_2 (words * UNITS_PER_WORD, 0));
4188 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4189 TREE_SIDE_EFFECTS (t) = 1;
4190 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4191
4192 /* Find the register save area. */
4193 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4194 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4195 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4196 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4197 TREE_SIDE_EFFECTS (t) = 1;
4198 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4199}
4200
4201/* Implement va_arg. */
4202
4203rtx
a2369ed3 4204rs6000_va_arg (tree valist, tree type)
dfafc897 4205{
c566f9bd 4206 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4207 tree gpr, fpr, ovf, sav, reg, t, u;
4208 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4209 rtx lab_false, lab_over, addr_rtx, r;
4210
f607bc57 4211 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4212 {
4213 /* Variable sized types are passed by reference. */
fff2cb99 4214 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4215 {
4216 u = build_pointer_type (type);
4217
4218 /* Args grow upward. */
4219 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4220 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4221 TREE_SIDE_EFFECTS (t) = 1;
4222
4223 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4224 TREE_SIDE_EFFECTS (t) = 1;
4225
4226 t = build1 (INDIRECT_REF, u, t);
4227 TREE_SIDE_EFFECTS (t) = 1;
4228
4229 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4230 }
4231 else
4232 return std_expand_builtin_va_arg (valist, type);
4233 }
dfafc897 4234
973a648b 4235 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4236 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4237 f_res = TREE_CHAIN (f_fpr);
4238 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4239 f_sav = TREE_CHAIN (f_ovf);
4240
8ebecc3b 4241 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4242 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4243 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4244 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4245 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4246
4247 size = int_size_in_bytes (type);
4248 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4249
dfafc897 4250 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4251 {
dfafc897
FS
4252 /* Aggregates and long doubles are passed by reference. */
4253 indirect_p = 1;
4254 reg = gpr;
4255 n_reg = 1;
4256 sav_ofs = 0;
4257 sav_scale = 4;
d3294cd9
FS
4258 size = UNITS_PER_WORD;
4259 rsize = 1;
dfafc897 4260 }
a3170dc6 4261 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4262 {
4263 /* FP args go in FP registers, if present. */
4264 indirect_p = 0;
4265 reg = fpr;
4266 n_reg = 1;
4267 sav_ofs = 8*4;
4268 sav_scale = 8;
4cc833b7 4269 }
dfafc897
FS
4270 else
4271 {
4272 /* Otherwise into GP registers. */
4273 indirect_p = 0;
4274 reg = gpr;
4275 n_reg = rsize;
4276 sav_ofs = 0;
4277 sav_scale = 4;
4278 }
4279
a4f6c312 4280 /* Pull the value out of the saved registers ... */
dfafc897
FS
4281
4282 lab_false = gen_label_rtx ();
4283 lab_over = gen_label_rtx ();
4284 addr_rtx = gen_reg_rtx (Pmode);
4285
16861f33
AH
4286 /* AltiVec vectors never go in registers. */
4287 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4288 {
41daaf0e
AH
4289 TREE_THIS_VOLATILE (reg) = 1;
4290 emit_cmp_and_jump_insns
4291 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4292 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4293 lab_false);
dfafc897 4294
41daaf0e
AH
4295 /* Long long is aligned in the registers. */
4296 if (n_reg > 1)
4297 {
4298 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4299 build_int_2 (n_reg - 1, 0));
4300 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4301 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4302 TREE_SIDE_EFFECTS (u) = 1;
4303 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4304 }
2c4974b7 4305
41daaf0e
AH
4306 if (sav_ofs)
4307 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4308 else
4309 t = sav;
2c4974b7 4310
41daaf0e
AH
4311 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4312 build_int_2 (n_reg, 0));
4313 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4314
41daaf0e
AH
4315 u = build1 (CONVERT_EXPR, integer_type_node, u);
4316 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4317
41daaf0e
AH
4318 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4319 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4320
41daaf0e
AH
4321 t = build (PLUS_EXPR, ptr_type_node, t, u);
4322 TREE_SIDE_EFFECTS (t) = 1;
4323
4324 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4325 if (r != addr_rtx)
4326 emit_move_insn (addr_rtx, r);
4327
4328 emit_jump_insn (gen_jump (lab_over));
4329 emit_barrier ();
4330 }
dfafc897 4331
dfafc897
FS
4332 emit_label (lab_false);
4333
a4f6c312 4334 /* ... otherwise out of the overflow area. */
dfafc897 4335
41daaf0e
AH
4336 /* Make sure we don't find reg 7 for the next int arg.
4337
4338 All AltiVec vectors go in the overflow area. So in the AltiVec
4339 case we need to get the vectors from the overflow area, but
4340 remember where the GPRs and FPRs are. */
16861f33
AH
4341 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
4342 || !TARGET_ALTIVEC))
dfafc897
FS
4343 {
4344 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
4345 TREE_SIDE_EFFECTS (t) = 1;
4346 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4347 }
4348
4349 /* Care for on-stack alignment if needed. */
4350 if (rsize <= 1)
4351 t = ovf;
4352 else
4353 {
41daaf0e
AH
4354 int align;
4355
16861f33
AH
4356 /* AltiVec vectors are 16 byte aligned. */
4357 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
4358 align = 15;
4359 else
4360 align = 7;
4361
4362 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
4363 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
4364 }
4365 t = save_expr (t);
4366
4367 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4368 if (r != addr_rtx)
4369 emit_move_insn (addr_rtx, r);
4370
4371 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
4372 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4373 TREE_SIDE_EFFECTS (t) = 1;
4374 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4375
4376 emit_label (lab_over);
4377
4378 if (indirect_p)
4379 {
4380 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 4381 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
4382 emit_move_insn (addr_rtx, r);
4383 }
4384
4385 return addr_rtx;
4697a36c 4386}
0ac081f6
AH
4387
4388/* Builtins. */
4389
6a2dd09a
RS
4390#define def_builtin(MASK, NAME, TYPE, CODE) \
4391do { \
4392 if ((MASK) & target_flags) \
4393 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
4394 NULL, NULL_TREE); \
0ac081f6
AH
4395} while (0)
4396
24408032
AH
4397/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
4398
2212663f 4399static const struct builtin_description bdesc_3arg[] =
24408032
AH
4400{
4401 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
4402 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
4403 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
4404 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
4405 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
4406 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
4407 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
4408 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
4409 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
4410 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
4411 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
4412 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
4413 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
4414 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
4415 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
4416 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
4417 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
4418 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
4419 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
4420 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
4421 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
4422 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
4423 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
4424};
2212663f 4425
95385cbb
AH
4426/* DST operations: void foo (void *, const int, const char). */
4427
4428static const struct builtin_description bdesc_dst[] =
4429{
4430 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
4431 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
4432 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
4433 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
4434};
4435
2212663f 4436/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 4437
a3170dc6 4438static struct builtin_description bdesc_2arg[] =
0ac081f6 4439{
f18c054f
DB
4440 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
4441 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
4442 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
4443 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
4444 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
4445 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
4446 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
4447 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
4448 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
4449 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
4450 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 4451 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
4452 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
4453 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
4454 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
4455 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
4456 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
4457 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
4458 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
4459 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
4460 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
4461 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
4462 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
4463 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
4464 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
4465 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
4466 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
4467 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
4468 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
4469 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
4470 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
4471 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
4472 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
4473 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
4474 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
4475 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
4476 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
4477 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
4478 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
4479 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
4480 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
4481 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
4482 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
4483 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
4484 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
4485 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
4486 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
4487 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
4488 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
4489 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
4490 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
4491 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
4492 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
4493 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
4494 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
4495 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
4496 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
4497 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
4498 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
4499 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
4500 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
4501 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
4502 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
4503 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
4504 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 4505 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
4506 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
4507 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
4508 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
4509 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
4510 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
4511 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
4512 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
4513 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
4514 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
4515 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
4516 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
4517 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
4518 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
4519 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
4520 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
4521 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
4522 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
4523 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
4524 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
4525 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
4526 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
4527 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 4528 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
4529 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
4530 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
4531 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
4532 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
4533 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
4534 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
4535 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
4536 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
4537 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
4538 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
4539 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
4540 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
4541 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
4542 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
4543 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
4544 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
4545 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
4546 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
4547 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
4548 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
4549 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
4550 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
4551 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 4552 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
4553
4554 /* Place holder, leave as first spe builtin. */
4555 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
4556 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
4557 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
4558 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
4559 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
4560 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
4561 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
4562 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
4563 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
4564 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
4565 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
4566 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
4567 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
4568 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
4569 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
4570 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
4571 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
4572 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
4573 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
4574 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
4575 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
4576 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
4577 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
4578 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
4579 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
4580 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
4581 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
4582 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
4583 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
4584 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
4585 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
4586 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
4587 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
4588 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
4589 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
4590 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
4591 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
4592 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
4593 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
4594 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
4595 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
4596 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
4597 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
4598 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
4599 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
4600 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
4601 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
4602 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
4603 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
4604 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
4605 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
4606 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
4607 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
4608 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
4609 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
4610 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
4611 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
4612 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
4613 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
4614 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
4615 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
4616 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
4617 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
4618 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
4619 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
4620 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
4621 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
4622 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
4623 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
4624 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
4625 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
4626 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
4627 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
4628 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
4629 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
4630 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
4631 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
4632 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
4633 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
4634 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
4635 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
4636 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
4637 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
4638 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
4639 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
4640 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
4641 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
4642 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
4643 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
4644 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
4645 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
4646 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
4647 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
4648 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
4649 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
4650 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
4651 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
4652 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
4653 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
4654 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
4655 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
4656 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
4657 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
4658 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
4659 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
4660 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
4661 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
4662 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
4663 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
4664
4665 /* SPE binary operations expecting a 5-bit unsigned literal. */
4666 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
4667
4668 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
4669 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
4670 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
4671 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
4672 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
4673 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
4674 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
4675 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
4676 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
4677 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
4678 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
4679 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
4680 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
4681 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
4682 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
4683 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
4684 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
4685 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
4686 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
4687 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
4688 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
4689 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
4690 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
4691 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
4692 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
4693 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
4694
4695 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 4696 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
4697};
4698
4699/* AltiVec predicates. */
4700
4701struct builtin_description_predicates
4702{
4703 const unsigned int mask;
4704 const enum insn_code icode;
4705 const char *opcode;
4706 const char *const name;
4707 const enum rs6000_builtins code;
4708};
4709
4710static const struct builtin_description_predicates bdesc_altivec_preds[] =
4711{
4712 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
4713 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
4714 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
4715 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
4716 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
4717 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
4718 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
4719 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
4720 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
4721 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
4722 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
4723 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
4724 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 4725};
24408032 4726
a3170dc6
AH
4727/* SPE predicates. */
4728static struct builtin_description bdesc_spe_predicates[] =
4729{
4730 /* Place-holder. Leave as first. */
4731 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
4732 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
4733 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
4734 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
4735 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
4736 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
4737 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
4738 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
4739 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
4740 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
4741 /* Place-holder. Leave as last. */
4742 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
4743};
4744
4745/* SPE evsel predicates. */
4746static struct builtin_description bdesc_spe_evsel[] =
4747{
4748 /* Place-holder. Leave as first. */
4749 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
4750 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
4751 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
4752 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
4753 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
4754 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
4755 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
4756 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
4757 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
4758 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
4759 /* Place-holder. Leave as last. */
4760 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
4761};
4762
b6d08ca1 4763/* ABS* operations. */
100c4561
AH
4764
4765static const struct builtin_description bdesc_abs[] =
4766{
4767 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
4768 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
4769 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
4770 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
4771 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
4772 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
4773 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
4774};
4775
617e0e1d
DB
4776/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
4777 foo (VECa). */
24408032 4778
a3170dc6 4779static struct builtin_description bdesc_1arg[] =
2212663f 4780{
617e0e1d
DB
4781 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
4782 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
4783 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
4784 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
4785 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
4786 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
4787 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
4788 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
4789 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
4790 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
4791 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
4792 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
4793 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
4794 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
4795 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
4796 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
4797 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
4798
4799 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
4800 end with SPE_BUILTIN_EVSUBFUSIAAW. */
4801 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
4802 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
4803 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
4804 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
4805 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
4806 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
4807 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
4808 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
4809 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
4810 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
4811 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
4812 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
4813 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
4814 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
4815 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
4816 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
4817 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
4818 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
4819 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
4820 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
4821 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
4822 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
4823 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
4824 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
4825 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
4826 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
4827 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
4828 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
4829
4830 /* Place-holder. Leave as last unary SPE builtin. */
4831 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
4832};
4833
4834static rtx
a2369ed3 4835rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
4836{
4837 rtx pat;
4838 tree arg0 = TREE_VALUE (arglist);
4839 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4840 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4841 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4842
0559cc77
DE
4843 if (icode == CODE_FOR_nothing)
4844 /* Builtin not supported on this processor. */
4845 return 0;
4846
20e26713
AH
4847 /* If we got invalid arguments bail out before generating bad rtl. */
4848 if (arg0 == error_mark_node)
9a171fcd 4849 return const0_rtx;
20e26713 4850
0559cc77
DE
4851 if (icode == CODE_FOR_altivec_vspltisb
4852 || icode == CODE_FOR_altivec_vspltish
4853 || icode == CODE_FOR_altivec_vspltisw
4854 || icode == CODE_FOR_spe_evsplatfi
4855 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
4856 {
4857 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
4858 if (GET_CODE (op0) != CONST_INT
4859 || INTVAL (op0) > 0x1f
4860 || INTVAL (op0) < -0x1f)
4861 {
4862 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 4863 return const0_rtx;
b44140e7 4864 }
b44140e7
AH
4865 }
4866
c62f2db5 4867 if (target == 0
2212663f
DB
4868 || GET_MODE (target) != tmode
4869 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4870 target = gen_reg_rtx (tmode);
4871
4872 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4873 op0 = copy_to_mode_reg (mode0, op0);
4874
4875 pat = GEN_FCN (icode) (target, op0);
4876 if (! pat)
4877 return 0;
4878 emit_insn (pat);
0ac081f6 4879
2212663f
DB
4880 return target;
4881}
ae4b4a02 4882
100c4561 4883static rtx
a2369ed3 4884altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
4885{
4886 rtx pat, scratch1, scratch2;
4887 tree arg0 = TREE_VALUE (arglist);
4888 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4889 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4890 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4891
4892 /* If we have invalid arguments, bail out before generating bad rtl. */
4893 if (arg0 == error_mark_node)
9a171fcd 4894 return const0_rtx;
100c4561
AH
4895
4896 if (target == 0
4897 || GET_MODE (target) != tmode
4898 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4899 target = gen_reg_rtx (tmode);
4900
4901 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4902 op0 = copy_to_mode_reg (mode0, op0);
4903
4904 scratch1 = gen_reg_rtx (mode0);
4905 scratch2 = gen_reg_rtx (mode0);
4906
4907 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
4908 if (! pat)
4909 return 0;
4910 emit_insn (pat);
4911
4912 return target;
4913}
4914
0ac081f6 4915static rtx
a2369ed3 4916rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
4917{
4918 rtx pat;
4919 tree arg0 = TREE_VALUE (arglist);
4920 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4921 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4922 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4923 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4924 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4925 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4926
0559cc77
DE
4927 if (icode == CODE_FOR_nothing)
4928 /* Builtin not supported on this processor. */
4929 return 0;
4930
20e26713
AH
4931 /* If we got invalid arguments bail out before generating bad rtl. */
4932 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4933 return const0_rtx;
20e26713 4934
0559cc77
DE
4935 if (icode == CODE_FOR_altivec_vcfux
4936 || icode == CODE_FOR_altivec_vcfsx
4937 || icode == CODE_FOR_altivec_vctsxs
4938 || icode == CODE_FOR_altivec_vctuxs
4939 || icode == CODE_FOR_altivec_vspltb
4940 || icode == CODE_FOR_altivec_vsplth
4941 || icode == CODE_FOR_altivec_vspltw
4942 || icode == CODE_FOR_spe_evaddiw
4943 || icode == CODE_FOR_spe_evldd
4944 || icode == CODE_FOR_spe_evldh
4945 || icode == CODE_FOR_spe_evldw
4946 || icode == CODE_FOR_spe_evlhhesplat
4947 || icode == CODE_FOR_spe_evlhhossplat
4948 || icode == CODE_FOR_spe_evlhhousplat
4949 || icode == CODE_FOR_spe_evlwhe
4950 || icode == CODE_FOR_spe_evlwhos
4951 || icode == CODE_FOR_spe_evlwhou
4952 || icode == CODE_FOR_spe_evlwhsplat
4953 || icode == CODE_FOR_spe_evlwwsplat
4954 || icode == CODE_FOR_spe_evrlwi
4955 || icode == CODE_FOR_spe_evslwi
4956 || icode == CODE_FOR_spe_evsrwis
f5119d10 4957 || icode == CODE_FOR_spe_evsubifw
0559cc77 4958 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
4959 {
4960 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
4961 if (TREE_CODE (arg1) != INTEGER_CST
4962 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4963 {
4964 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 4965 return const0_rtx;
b44140e7 4966 }
b44140e7
AH
4967 }
4968
c62f2db5 4969 if (target == 0
0ac081f6
AH
4970 || GET_MODE (target) != tmode
4971 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4972 target = gen_reg_rtx (tmode);
4973
4974 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4975 op0 = copy_to_mode_reg (mode0, op0);
4976 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4977 op1 = copy_to_mode_reg (mode1, op1);
4978
4979 pat = GEN_FCN (icode) (target, op0, op1);
4980 if (! pat)
4981 return 0;
4982 emit_insn (pat);
4983
4984 return target;
4985}
6525c0e7 4986
ae4b4a02 4987static rtx
a2369ed3
DJ
4988altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
4989 tree arglist, rtx target)
ae4b4a02
AH
4990{
4991 rtx pat, scratch;
4992 tree cr6_form = TREE_VALUE (arglist);
4993 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
4994 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4995 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4996 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4997 enum machine_mode tmode = SImode;
4998 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4999 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5000 int cr6_form_int;
5001
5002 if (TREE_CODE (cr6_form) != INTEGER_CST)
5003 {
5004 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5005 return const0_rtx;
ae4b4a02
AH
5006 }
5007 else
5008 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5009
5010 if (mode0 != mode1)
5011 abort ();
5012
5013 /* If we have invalid arguments, bail out before generating bad rtl. */
5014 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5015 return const0_rtx;
ae4b4a02
AH
5016
5017 if (target == 0
5018 || GET_MODE (target) != tmode
5019 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5020 target = gen_reg_rtx (tmode);
5021
5022 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5023 op0 = copy_to_mode_reg (mode0, op0);
5024 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5025 op1 = copy_to_mode_reg (mode1, op1);
5026
5027 scratch = gen_reg_rtx (mode0);
5028
5029 pat = GEN_FCN (icode) (scratch, op0, op1,
5030 gen_rtx (SYMBOL_REF, Pmode, opcode));
5031 if (! pat)
5032 return 0;
5033 emit_insn (pat);
5034
5035 /* The vec_any* and vec_all* predicates use the same opcodes for two
5036 different operations, but the bits in CR6 will be different
5037 depending on what information we want. So we have to play tricks
5038 with CR6 to get the right bits out.
5039
5040 If you think this is disgusting, look at the specs for the
5041 AltiVec predicates. */
5042
5043 switch (cr6_form_int)
5044 {
5045 case 0:
5046 emit_insn (gen_cr6_test_for_zero (target));
5047 break;
5048 case 1:
5049 emit_insn (gen_cr6_test_for_zero_reverse (target));
5050 break;
5051 case 2:
5052 emit_insn (gen_cr6_test_for_lt (target));
5053 break;
5054 case 3:
5055 emit_insn (gen_cr6_test_for_lt_reverse (target));
5056 break;
5057 default:
5058 error ("argument 1 of __builtin_altivec_predicate is out of range");
5059 break;
5060 }
5061
5062 return target;
5063}
5064
6525c0e7 5065static rtx
a2369ed3 5066altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5067{
5068 tree arg0 = TREE_VALUE (arglist);
5069 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5070 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5071 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5072 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5073 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5074 rtx pat;
5075 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
5076 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
5077 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
5078
5079 /* Invalid arguments. Bail before doing anything stoopid! */
5080 if (arg0 == error_mark_node
5081 || arg1 == error_mark_node
5082 || arg2 == error_mark_node)
9a171fcd 5083 return const0_rtx;
6525c0e7
AH
5084
5085 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
5086 op0 = copy_to_mode_reg (mode2, op0);
5087 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
5088 op1 = copy_to_mode_reg (mode0, op1);
5089 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5090 op2 = copy_to_mode_reg (mode1, op2);
5091
5092 pat = GEN_FCN (icode) (op1, op2, op0);
5093 if (pat)
5094 emit_insn (pat);
5095 return NULL_RTX;
5096}
5097
2212663f 5098static rtx
a2369ed3 5099rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5100{
5101 rtx pat;
5102 tree arg0 = TREE_VALUE (arglist);
5103 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5104 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5105 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5106 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5107 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5108 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5109 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5110 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5111 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5112
774b5662
DE
5113 if (icode == CODE_FOR_nothing)
5114 /* Builtin not supported on this processor. */
5115 return 0;
5116
20e26713
AH
5117 /* If we got invalid arguments bail out before generating bad rtl. */
5118 if (arg0 == error_mark_node
5119 || arg1 == error_mark_node
5120 || arg2 == error_mark_node)
9a171fcd 5121 return const0_rtx;
20e26713 5122
774b5662
DE
5123 if (icode == CODE_FOR_altivec_vsldoi_4sf
5124 || icode == CODE_FOR_altivec_vsldoi_4si
5125 || icode == CODE_FOR_altivec_vsldoi_8hi
5126 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5127 {
5128 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
5129 if (TREE_CODE (arg2) != INTEGER_CST
5130 || TREE_INT_CST_LOW (arg2) & ~0xf)
5131 {
5132 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5133 return const0_rtx;
b44140e7 5134 }
b44140e7
AH
5135 }
5136
c62f2db5 5137 if (target == 0
2212663f
DB
5138 || GET_MODE (target) != tmode
5139 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5140 target = gen_reg_rtx (tmode);
5141
5142 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5143 op0 = copy_to_mode_reg (mode0, op0);
5144 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5145 op1 = copy_to_mode_reg (mode1, op1);
5146 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5147 op2 = copy_to_mode_reg (mode2, op2);
5148
5149 pat = GEN_FCN (icode) (target, op0, op1, op2);
5150 if (! pat)
5151 return 0;
5152 emit_insn (pat);
5153
5154 return target;
5155}
92898235 5156
3a9b8c7e 5157/* Expand the lvx builtins. */
0ac081f6 5158static rtx
a2369ed3 5159altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5160{
0ac081f6
AH
5161 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5162 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5163 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5164 tree arg0;
5165 enum machine_mode tmode, mode0;
7c3abc73 5166 rtx pat, op0;
3a9b8c7e 5167 enum insn_code icode;
92898235 5168
0ac081f6
AH
5169 switch (fcode)
5170 {
f18c054f
DB
5171 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5172 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5173 break;
f18c054f
DB
5174 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5175 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5176 break;
5177 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5178 icode = CODE_FOR_altivec_lvx_4si;
5179 break;
5180 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5181 icode = CODE_FOR_altivec_lvx_4sf;
5182 break;
5183 default:
5184 *expandedp = false;
5185 return NULL_RTX;
5186 }
0ac081f6 5187
3a9b8c7e 5188 *expandedp = true;
f18c054f 5189
3a9b8c7e
AH
5190 arg0 = TREE_VALUE (arglist);
5191 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5192 tmode = insn_data[icode].operand[0].mode;
5193 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5194
3a9b8c7e
AH
5195 if (target == 0
5196 || GET_MODE (target) != tmode
5197 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5198 target = gen_reg_rtx (tmode);
24408032 5199
3a9b8c7e
AH
5200 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5201 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5202
3a9b8c7e
AH
5203 pat = GEN_FCN (icode) (target, op0);
5204 if (! pat)
5205 return 0;
5206 emit_insn (pat);
5207 return target;
5208}
f18c054f 5209
3a9b8c7e
AH
5210/* Expand the stvx builtins. */
5211static rtx
a2369ed3
DJ
5212altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5213 bool *expandedp)
3a9b8c7e
AH
5214{
5215 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5216 tree arglist = TREE_OPERAND (exp, 1);
5217 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5218 tree arg0, arg1;
5219 enum machine_mode mode0, mode1;
7c3abc73 5220 rtx pat, op0, op1;
3a9b8c7e 5221 enum insn_code icode;
f18c054f 5222
3a9b8c7e
AH
5223 switch (fcode)
5224 {
5225 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5226 icode = CODE_FOR_altivec_stvx_16qi;
5227 break;
5228 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5229 icode = CODE_FOR_altivec_stvx_8hi;
5230 break;
5231 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5232 icode = CODE_FOR_altivec_stvx_4si;
5233 break;
5234 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5235 icode = CODE_FOR_altivec_stvx_4sf;
5236 break;
5237 default:
5238 *expandedp = false;
5239 return NULL_RTX;
5240 }
24408032 5241
3a9b8c7e
AH
5242 arg0 = TREE_VALUE (arglist);
5243 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5244 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5245 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5246 mode0 = insn_data[icode].operand[0].mode;
5247 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5248
3a9b8c7e
AH
5249 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5250 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5251 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5252 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5253
3a9b8c7e
AH
5254 pat = GEN_FCN (icode) (op0, op1);
5255 if (pat)
5256 emit_insn (pat);
f18c054f 5257
3a9b8c7e
AH
5258 *expandedp = true;
5259 return NULL_RTX;
5260}
f18c054f 5261
3a9b8c7e
AH
5262/* Expand the dst builtins. */
5263static rtx
a2369ed3
DJ
5264altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5265 bool *expandedp)
3a9b8c7e
AH
5266{
5267 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5268 tree arglist = TREE_OPERAND (exp, 1);
5269 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5270 tree arg0, arg1, arg2;
5271 enum machine_mode mode0, mode1, mode2;
7c3abc73 5272 rtx pat, op0, op1, op2;
3a9b8c7e 5273 struct builtin_description *d;
a3170dc6 5274 size_t i;
f18c054f 5275
3a9b8c7e 5276 *expandedp = false;
f18c054f 5277
3a9b8c7e
AH
5278 /* Handle DST variants. */
5279 d = (struct builtin_description *) bdesc_dst;
5280 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
5281 if (d->code == fcode)
5282 {
5283 arg0 = TREE_VALUE (arglist);
5284 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5285 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5286 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5287 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5288 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5289 mode0 = insn_data[d->icode].operand[0].mode;
5290 mode1 = insn_data[d->icode].operand[1].mode;
5291 mode2 = insn_data[d->icode].operand[2].mode;
24408032 5292
3a9b8c7e
AH
5293 /* Invalid arguments, bail out before generating bad rtl. */
5294 if (arg0 == error_mark_node
5295 || arg1 == error_mark_node
5296 || arg2 == error_mark_node)
5297 return const0_rtx;
f18c054f 5298
3a9b8c7e
AH
5299 if (TREE_CODE (arg2) != INTEGER_CST
5300 || TREE_INT_CST_LOW (arg2) & ~0x3)
5301 {
5302 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
5303 return const0_rtx;
5304 }
f18c054f 5305
3a9b8c7e
AH
5306 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
5307 op0 = copy_to_mode_reg (mode0, op0);
5308 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
5309 op1 = copy_to_mode_reg (mode1, op1);
24408032 5310
3a9b8c7e
AH
5311 pat = GEN_FCN (d->icode) (op0, op1, op2);
5312 if (pat != 0)
5313 emit_insn (pat);
f18c054f 5314
3a9b8c7e
AH
5315 *expandedp = true;
5316 return NULL_RTX;
5317 }
f18c054f 5318
3a9b8c7e
AH
5319 return NULL_RTX;
5320}
24408032 5321
3a9b8c7e
AH
5322/* Expand the builtin in EXP and store the result in TARGET. Store
5323 true in *EXPANDEDP if we found a builtin to expand. */
5324static rtx
a2369ed3 5325altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
5326{
5327 struct builtin_description *d;
5328 struct builtin_description_predicates *dp;
5329 size_t i;
5330 enum insn_code icode;
5331 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5332 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
5333 tree arg0;
5334 rtx op0, pat;
5335 enum machine_mode tmode, mode0;
3a9b8c7e 5336 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 5337
3a9b8c7e
AH
5338 target = altivec_expand_ld_builtin (exp, target, expandedp);
5339 if (*expandedp)
5340 return target;
0ac081f6 5341
3a9b8c7e
AH
5342 target = altivec_expand_st_builtin (exp, target, expandedp);
5343 if (*expandedp)
5344 return target;
5345
5346 target = altivec_expand_dst_builtin (exp, target, expandedp);
5347 if (*expandedp)
5348 return target;
5349
5350 *expandedp = true;
95385cbb 5351
3a9b8c7e
AH
5352 switch (fcode)
5353 {
6525c0e7
AH
5354 case ALTIVEC_BUILTIN_STVX:
5355 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
5356 case ALTIVEC_BUILTIN_STVEBX:
5357 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
5358 case ALTIVEC_BUILTIN_STVEHX:
5359 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
5360 case ALTIVEC_BUILTIN_STVEWX:
5361 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
5362 case ALTIVEC_BUILTIN_STVXL:
5363 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 5364
95385cbb
AH
5365 case ALTIVEC_BUILTIN_MFVSCR:
5366 icode = CODE_FOR_altivec_mfvscr;
5367 tmode = insn_data[icode].operand[0].mode;
5368
5369 if (target == 0
5370 || GET_MODE (target) != tmode
5371 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5372 target = gen_reg_rtx (tmode);
5373
5374 pat = GEN_FCN (icode) (target);
0ac081f6
AH
5375 if (! pat)
5376 return 0;
5377 emit_insn (pat);
95385cbb
AH
5378 return target;
5379
5380 case ALTIVEC_BUILTIN_MTVSCR:
5381 icode = CODE_FOR_altivec_mtvscr;
5382 arg0 = TREE_VALUE (arglist);
5383 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5384 mode0 = insn_data[icode].operand[0].mode;
5385
5386 /* If we got invalid arguments bail out before generating bad rtl. */
5387 if (arg0 == error_mark_node)
9a171fcd 5388 return const0_rtx;
95385cbb
AH
5389
5390 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5391 op0 = copy_to_mode_reg (mode0, op0);
5392
5393 pat = GEN_FCN (icode) (op0);
5394 if (pat)
5395 emit_insn (pat);
5396 return NULL_RTX;
3a9b8c7e 5397
95385cbb
AH
5398 case ALTIVEC_BUILTIN_DSSALL:
5399 emit_insn (gen_altivec_dssall ());
5400 return NULL_RTX;
5401
5402 case ALTIVEC_BUILTIN_DSS:
5403 icode = CODE_FOR_altivec_dss;
5404 arg0 = TREE_VALUE (arglist);
5405 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5406 mode0 = insn_data[icode].operand[0].mode;
5407
5408 /* If we got invalid arguments bail out before generating bad rtl. */
5409 if (arg0 == error_mark_node)
9a171fcd 5410 return const0_rtx;
95385cbb 5411
b44140e7
AH
5412 if (TREE_CODE (arg0) != INTEGER_CST
5413 || TREE_INT_CST_LOW (arg0) & ~0x3)
5414 {
5415 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 5416 return const0_rtx;
b44140e7
AH
5417 }
5418
95385cbb
AH
5419 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5420 op0 = copy_to_mode_reg (mode0, op0);
5421
5422 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
5423 return NULL_RTX;
5424 }
24408032 5425
100c4561
AH
5426 /* Expand abs* operations. */
5427 d = (struct builtin_description *) bdesc_abs;
ca7558fc 5428 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
5429 if (d->code == fcode)
5430 return altivec_expand_abs_builtin (d->icode, arglist, target);
5431
ae4b4a02
AH
5432 /* Expand the AltiVec predicates. */
5433 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 5434 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
5435 if (dp->code == fcode)
5436 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
5437
6525c0e7
AH
5438 /* LV* are funky. We initialized them differently. */
5439 switch (fcode)
5440 {
5441 case ALTIVEC_BUILTIN_LVSL:
92898235 5442 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
5443 arglist, target);
5444 case ALTIVEC_BUILTIN_LVSR:
92898235
AH
5445 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
5446 arglist, target);
6525c0e7 5447 case ALTIVEC_BUILTIN_LVEBX:
92898235
AH
5448 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
5449 arglist, target);
6525c0e7 5450 case ALTIVEC_BUILTIN_LVEHX:
92898235
AH
5451 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
5452 arglist, target);
6525c0e7 5453 case ALTIVEC_BUILTIN_LVEWX:
92898235
AH
5454 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
5455 arglist, target);
6525c0e7 5456 case ALTIVEC_BUILTIN_LVXL:
92898235
AH
5457 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
5458 arglist, target);
6525c0e7 5459 case ALTIVEC_BUILTIN_LVX:
92898235
AH
5460 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
5461 arglist, target);
6525c0e7
AH
5462 default:
5463 break;
5464 /* Fall through. */
5465 }
95385cbb 5466
92898235 5467 *expandedp = false;
0ac081f6
AH
5468 return NULL_RTX;
5469}
5470
a3170dc6
AH
5471/* Binops that need to be initialized manually, but can be expanded
5472 automagically by rs6000_expand_binop_builtin. */
5473static struct builtin_description bdesc_2arg_spe[] =
5474{
5475 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
5476 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
5477 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
5478 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
5479 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
5480 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
5481 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
5482 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
5483 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
5484 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
5485 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
5486 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
5487 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
5488 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
5489 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
5490 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
5491 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
5492 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
5493 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
5494 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
5495 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
5496 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
5497};
5498
5499/* Expand the builtin in EXP and store the result in TARGET. Store
5500 true in *EXPANDEDP if we found a builtin to expand.
5501
5502 This expands the SPE builtins that are not simple unary and binary
5503 operations. */
5504static rtx
a2369ed3 5505spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
5506{
5507 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5508 tree arglist = TREE_OPERAND (exp, 1);
5509 tree arg1, arg0;
5510 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5511 enum insn_code icode;
5512 enum machine_mode tmode, mode0;
5513 rtx pat, op0;
5514 struct builtin_description *d;
5515 size_t i;
5516
5517 *expandedp = true;
5518
5519 /* Syntax check for a 5-bit unsigned immediate. */
5520 switch (fcode)
5521 {
5522 case SPE_BUILTIN_EVSTDD:
5523 case SPE_BUILTIN_EVSTDH:
5524 case SPE_BUILTIN_EVSTDW:
5525 case SPE_BUILTIN_EVSTWHE:
5526 case SPE_BUILTIN_EVSTWHO:
5527 case SPE_BUILTIN_EVSTWWE:
5528 case SPE_BUILTIN_EVSTWWO:
5529 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5530 if (TREE_CODE (arg1) != INTEGER_CST
5531 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5532 {
5533 error ("argument 2 must be a 5-bit unsigned literal");
5534 return const0_rtx;
5535 }
5536 break;
5537 default:
5538 break;
5539 }
5540
00332c9f
AH
5541 /* The evsplat*i instructions are not quite generic. */
5542 switch (fcode)
5543 {
5544 case SPE_BUILTIN_EVSPLATFI:
5545 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
5546 arglist, target);
5547 case SPE_BUILTIN_EVSPLATI:
5548 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
5549 arglist, target);
5550 default:
5551 break;
5552 }
5553
a3170dc6
AH
5554 d = (struct builtin_description *) bdesc_2arg_spe;
5555 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
5556 if (d->code == fcode)
5557 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5558
5559 d = (struct builtin_description *) bdesc_spe_predicates;
5560 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
5561 if (d->code == fcode)
5562 return spe_expand_predicate_builtin (d->icode, arglist, target);
5563
5564 d = (struct builtin_description *) bdesc_spe_evsel;
5565 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
5566 if (d->code == fcode)
5567 return spe_expand_evsel_builtin (d->icode, arglist, target);
5568
5569 switch (fcode)
5570 {
5571 case SPE_BUILTIN_EVSTDDX:
5572 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
5573 case SPE_BUILTIN_EVSTDHX:
5574 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
5575 case SPE_BUILTIN_EVSTDWX:
5576 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
5577 case SPE_BUILTIN_EVSTWHEX:
5578 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
5579 case SPE_BUILTIN_EVSTWHOX:
5580 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
5581 case SPE_BUILTIN_EVSTWWEX:
5582 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
5583 case SPE_BUILTIN_EVSTWWOX:
5584 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
5585 case SPE_BUILTIN_EVSTDD:
5586 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
5587 case SPE_BUILTIN_EVSTDH:
5588 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
5589 case SPE_BUILTIN_EVSTDW:
5590 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
5591 case SPE_BUILTIN_EVSTWHE:
5592 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
5593 case SPE_BUILTIN_EVSTWHO:
5594 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
5595 case SPE_BUILTIN_EVSTWWE:
5596 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
5597 case SPE_BUILTIN_EVSTWWO:
5598 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
5599 case SPE_BUILTIN_MFSPEFSCR:
5600 icode = CODE_FOR_spe_mfspefscr;
5601 tmode = insn_data[icode].operand[0].mode;
5602
5603 if (target == 0
5604 || GET_MODE (target) != tmode
5605 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5606 target = gen_reg_rtx (tmode);
5607
5608 pat = GEN_FCN (icode) (target);
5609 if (! pat)
5610 return 0;
5611 emit_insn (pat);
5612 return target;
5613 case SPE_BUILTIN_MTSPEFSCR:
5614 icode = CODE_FOR_spe_mtspefscr;
5615 arg0 = TREE_VALUE (arglist);
5616 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5617 mode0 = insn_data[icode].operand[0].mode;
5618
5619 if (arg0 == error_mark_node)
5620 return const0_rtx;
5621
5622 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5623 op0 = copy_to_mode_reg (mode0, op0);
5624
5625 pat = GEN_FCN (icode) (op0);
5626 if (pat)
5627 emit_insn (pat);
5628 return NULL_RTX;
5629 default:
5630 break;
5631 }
5632
5633 *expandedp = false;
5634 return NULL_RTX;
5635}
5636
5637static rtx
a2369ed3 5638spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
5639{
5640 rtx pat, scratch, tmp;
5641 tree form = TREE_VALUE (arglist);
5642 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5643 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5644 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5645 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5646 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5647 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5648 int form_int;
5649 enum rtx_code code;
5650
5651 if (TREE_CODE (form) != INTEGER_CST)
5652 {
5653 error ("argument 1 of __builtin_spe_predicate must be a constant");
5654 return const0_rtx;
5655 }
5656 else
5657 form_int = TREE_INT_CST_LOW (form);
5658
5659 if (mode0 != mode1)
5660 abort ();
5661
5662 if (arg0 == error_mark_node || arg1 == error_mark_node)
5663 return const0_rtx;
5664
5665 if (target == 0
5666 || GET_MODE (target) != SImode
5667 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
5668 target = gen_reg_rtx (SImode);
5669
5670 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5671 op0 = copy_to_mode_reg (mode0, op0);
5672 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5673 op1 = copy_to_mode_reg (mode1, op1);
5674
5675 scratch = gen_reg_rtx (CCmode);
5676
5677 pat = GEN_FCN (icode) (scratch, op0, op1);
5678 if (! pat)
5679 return const0_rtx;
5680 emit_insn (pat);
5681
5682 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
5683 _lower_. We use one compare, but look in different bits of the
5684 CR for each variant.
5685
5686 There are 2 elements in each SPE simd type (upper/lower). The CR
5687 bits are set as follows:
5688
5689 BIT0 | BIT 1 | BIT 2 | BIT 3
5690 U | L | (U | L) | (U & L)
5691
5692 So, for an "all" relationship, BIT 3 would be set.
5693 For an "any" relationship, BIT 2 would be set. Etc.
5694
5695 Following traditional nomenclature, these bits map to:
5696
5697 BIT0 | BIT 1 | BIT 2 | BIT 3
5698 LT | GT | EQ | OV
5699
5700 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
5701 */
5702
5703 switch (form_int)
5704 {
5705 /* All variant. OV bit. */
5706 case 0:
5707 /* We need to get to the OV bit, which is the ORDERED bit. We
5708 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
5709 that's ugly and will trigger a validate_condition_mode abort.
5710 So let's just use another pattern. */
5711 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
5712 return target;
5713 /* Any variant. EQ bit. */
5714 case 1:
5715 code = EQ;
5716 break;
5717 /* Upper variant. LT bit. */
5718 case 2:
5719 code = LT;
5720 break;
5721 /* Lower variant. GT bit. */
5722 case 3:
5723 code = GT;
5724 break;
5725 default:
5726 error ("argument 1 of __builtin_spe_predicate is out of range");
5727 return const0_rtx;
5728 }
5729
5730 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
5731 emit_move_insn (target, tmp);
5732
5733 return target;
5734}
5735
5736/* The evsel builtins look like this:
5737
5738 e = __builtin_spe_evsel_OP (a, b, c, d);
5739
5740 and work like this:
5741
5742 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
5743 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
5744*/
5745
5746static rtx
a2369ed3 5747spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
5748{
5749 rtx pat, scratch;
5750 tree arg0 = TREE_VALUE (arglist);
5751 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5752 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5753 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
5754 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5755 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5756 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5757 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
5758 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5759 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5760
5761 if (mode0 != mode1)
5762 abort ();
5763
5764 if (arg0 == error_mark_node || arg1 == error_mark_node
5765 || arg2 == error_mark_node || arg3 == error_mark_node)
5766 return const0_rtx;
5767
5768 if (target == 0
5769 || GET_MODE (target) != mode0
5770 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
5771 target = gen_reg_rtx (mode0);
5772
5773 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5774 op0 = copy_to_mode_reg (mode0, op0);
5775 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5776 op1 = copy_to_mode_reg (mode0, op1);
5777 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5778 op2 = copy_to_mode_reg (mode0, op2);
5779 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
5780 op3 = copy_to_mode_reg (mode0, op3);
5781
5782 /* Generate the compare. */
5783 scratch = gen_reg_rtx (CCmode);
5784 pat = GEN_FCN (icode) (scratch, op0, op1);
5785 if (! pat)
5786 return const0_rtx;
5787 emit_insn (pat);
5788
5789 if (mode0 == V2SImode)
5790 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
5791 else
5792 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
5793
5794 return target;
5795}
5796
0ac081f6
AH
5797/* Expand an expression EXP that calls a built-in function,
5798 with result going to TARGET if that's convenient
5799 (and in mode MODE if that's convenient).
5800 SUBTARGET may be used as the target for computing one of EXP's operands.
5801 IGNORE is nonzero if the value is to be ignored. */
5802
5803static rtx
a2369ed3
DJ
5804rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
5805 enum machine_mode mode ATTRIBUTE_UNUSED,
5806 int ignore ATTRIBUTE_UNUSED)
0ac081f6 5807{
92898235
AH
5808 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5809 tree arglist = TREE_OPERAND (exp, 1);
5810 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5811 struct builtin_description *d;
5812 size_t i;
5813 rtx ret;
5814 bool success;
5815
0ac081f6 5816 if (TARGET_ALTIVEC)
92898235
AH
5817 {
5818 ret = altivec_expand_builtin (exp, target, &success);
5819
a3170dc6
AH
5820 if (success)
5821 return ret;
5822 }
5823 if (TARGET_SPE)
5824 {
5825 ret = spe_expand_builtin (exp, target, &success);
5826
92898235
AH
5827 if (success)
5828 return ret;
5829 }
5830
0559cc77
DE
5831 if (TARGET_ALTIVEC || TARGET_SPE)
5832 {
5833 /* Handle simple unary operations. */
5834 d = (struct builtin_description *) bdesc_1arg;
5835 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
5836 if (d->code == fcode)
5837 return rs6000_expand_unop_builtin (d->icode, arglist, target);
5838
5839 /* Handle simple binary operations. */
5840 d = (struct builtin_description *) bdesc_2arg;
5841 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
5842 if (d->code == fcode)
5843 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5844
5845 /* Handle simple ternary operations. */
5846 d = (struct builtin_description *) bdesc_3arg;
5847 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
5848 if (d->code == fcode)
5849 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
5850 }
0ac081f6
AH
5851
5852 abort ();
92898235 5853 return NULL_RTX;
0ac081f6
AH
5854}
5855
5856static void
863d938c 5857rs6000_init_builtins (void)
0ac081f6 5858{
3fdaa45a
AH
5859 opaque_V2SI_type_node = copy_node (V2SI_type_node);
5860 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 5861 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 5862
a3170dc6 5863 if (TARGET_SPE)
3fdaa45a 5864 spe_init_builtins ();
0ac081f6
AH
5865 if (TARGET_ALTIVEC)
5866 altivec_init_builtins ();
0559cc77
DE
5867 if (TARGET_ALTIVEC || TARGET_SPE)
5868 rs6000_common_init_builtins ();
0ac081f6
AH
5869}
5870
a3170dc6
AH
5871/* Search through a set of builtins and enable the mask bits.
5872 DESC is an array of builtins.
b6d08ca1 5873 SIZE is the total number of builtins.
a3170dc6
AH
5874 START is the builtin enum at which to start.
5875 END is the builtin enum at which to end. */
0ac081f6 5876static void
a2369ed3
DJ
5877enable_mask_for_builtins (struct builtin_description *desc, int size,
5878 enum rs6000_builtins start,
5879 enum rs6000_builtins end)
a3170dc6
AH
5880{
5881 int i;
5882
5883 for (i = 0; i < size; ++i)
5884 if (desc[i].code == start)
5885 break;
5886
5887 if (i == size)
5888 return;
5889
5890 for (; i < size; ++i)
5891 {
5892 /* Flip all the bits on. */
5893 desc[i].mask = target_flags;
5894 if (desc[i].code == end)
5895 break;
5896 }
5897}
5898
5899static void
863d938c 5900spe_init_builtins (void)
0ac081f6 5901{
a3170dc6
AH
5902 tree endlink = void_list_node;
5903 tree puint_type_node = build_pointer_type (unsigned_type_node);
5904 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 5905 struct builtin_description *d;
0ac081f6
AH
5906 size_t i;
5907
a3170dc6
AH
5908 tree v2si_ftype_4_v2si
5909 = build_function_type
3fdaa45a
AH
5910 (opaque_V2SI_type_node,
5911 tree_cons (NULL_TREE, opaque_V2SI_type_node,
5912 tree_cons (NULL_TREE, opaque_V2SI_type_node,
5913 tree_cons (NULL_TREE, opaque_V2SI_type_node,
5914 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
5915 endlink)))));
5916
5917 tree v2sf_ftype_4_v2sf
5918 = build_function_type
3fdaa45a
AH
5919 (opaque_V2SF_type_node,
5920 tree_cons (NULL_TREE, opaque_V2SF_type_node,
5921 tree_cons (NULL_TREE, opaque_V2SF_type_node,
5922 tree_cons (NULL_TREE, opaque_V2SF_type_node,
5923 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
5924 endlink)))));
5925
5926 tree int_ftype_int_v2si_v2si
5927 = build_function_type
5928 (integer_type_node,
5929 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
5930 tree_cons (NULL_TREE, opaque_V2SI_type_node,
5931 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
5932 endlink))));
5933
5934 tree int_ftype_int_v2sf_v2sf
5935 = build_function_type
5936 (integer_type_node,
5937 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
5938 tree_cons (NULL_TREE, opaque_V2SF_type_node,
5939 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
5940 endlink))));
5941
5942 tree void_ftype_v2si_puint_int
5943 = build_function_type (void_type_node,
3fdaa45a 5944 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
5945 tree_cons (NULL_TREE, puint_type_node,
5946 tree_cons (NULL_TREE,
5947 integer_type_node,
5948 endlink))));
5949
5950 tree void_ftype_v2si_puint_char
5951 = build_function_type (void_type_node,
3fdaa45a 5952 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
5953 tree_cons (NULL_TREE, puint_type_node,
5954 tree_cons (NULL_TREE,
5955 char_type_node,
5956 endlink))));
5957
5958 tree void_ftype_v2si_pv2si_int
5959 = build_function_type (void_type_node,
3fdaa45a 5960 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 5961 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
5962 tree_cons (NULL_TREE,
5963 integer_type_node,
5964 endlink))));
5965
5966 tree void_ftype_v2si_pv2si_char
5967 = build_function_type (void_type_node,
3fdaa45a 5968 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 5969 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
5970 tree_cons (NULL_TREE,
5971 char_type_node,
5972 endlink))));
5973
5974 tree void_ftype_int
5975 = build_function_type (void_type_node,
5976 tree_cons (NULL_TREE, integer_type_node, endlink));
5977
5978 tree int_ftype_void
36e8d515 5979 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
5980
5981 tree v2si_ftype_pv2si_int
3fdaa45a 5982 = build_function_type (opaque_V2SI_type_node,
6035d635 5983 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
5984 tree_cons (NULL_TREE, integer_type_node,
5985 endlink)));
5986
5987 tree v2si_ftype_puint_int
3fdaa45a 5988 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
5989 tree_cons (NULL_TREE, puint_type_node,
5990 tree_cons (NULL_TREE, integer_type_node,
5991 endlink)));
5992
5993 tree v2si_ftype_pushort_int
3fdaa45a 5994 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
5995 tree_cons (NULL_TREE, pushort_type_node,
5996 tree_cons (NULL_TREE, integer_type_node,
5997 endlink)));
5998
00332c9f
AH
5999 tree v2si_ftype_signed_char
6000 = build_function_type (opaque_V2SI_type_node,
6001 tree_cons (NULL_TREE, signed_char_type_node,
6002 endlink));
6003
a3170dc6
AH
6004 /* The initialization of the simple binary and unary builtins is
6005 done in rs6000_common_init_builtins, but we have to enable the
6006 mask bits here manually because we have run out of `target_flags'
6007 bits. We really need to redesign this mask business. */
6008
6009 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6010 ARRAY_SIZE (bdesc_2arg),
6011 SPE_BUILTIN_EVADDW,
6012 SPE_BUILTIN_EVXOR);
6013 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6014 ARRAY_SIZE (bdesc_1arg),
6015 SPE_BUILTIN_EVABS,
6016 SPE_BUILTIN_EVSUBFUSIAAW);
6017 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6018 ARRAY_SIZE (bdesc_spe_predicates),
6019 SPE_BUILTIN_EVCMPEQ,
6020 SPE_BUILTIN_EVFSTSTLT);
6021 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6022 ARRAY_SIZE (bdesc_spe_evsel),
6023 SPE_BUILTIN_EVSEL_CMPGTS,
6024 SPE_BUILTIN_EVSEL_FSTSTEQ);
6025
36252949
AH
6026 (*lang_hooks.decls.pushdecl)
6027 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6028 opaque_V2SI_type_node));
6029
a3170dc6
AH
6030 /* Initialize irregular SPE builtins. */
6031
6032 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6033 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6034 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6035 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6036 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6037 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6038 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6039 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6040 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6041 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6042 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6043 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6044 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6045 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6046 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6047 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6048 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6049 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6050
6051 /* Loads. */
6052 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6053 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6054 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6055 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6056 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6057 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6058 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6059 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6060 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6061 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6062 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6063 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6064 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6065 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6066 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6067 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6068 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6069 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6070 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6071 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6072 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6073 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6074
6075 /* Predicates. */
6076 d = (struct builtin_description *) bdesc_spe_predicates;
6077 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6078 {
6079 tree type;
6080
6081 switch (insn_data[d->icode].operand[1].mode)
6082 {
6083 case V2SImode:
6084 type = int_ftype_int_v2si_v2si;
6085 break;
6086 case V2SFmode:
6087 type = int_ftype_int_v2sf_v2sf;
6088 break;
6089 default:
6090 abort ();
6091 }
6092
6093 def_builtin (d->mask, d->name, type, d->code);
6094 }
6095
6096 /* Evsel predicates. */
6097 d = (struct builtin_description *) bdesc_spe_evsel;
6098 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6099 {
6100 tree type;
6101
6102 switch (insn_data[d->icode].operand[1].mode)
6103 {
6104 case V2SImode:
6105 type = v2si_ftype_4_v2si;
6106 break;
6107 case V2SFmode:
6108 type = v2sf_ftype_4_v2sf;
6109 break;
6110 default:
6111 abort ();
6112 }
6113
6114 def_builtin (d->mask, d->name, type, d->code);
6115 }
6116}
6117
6118static void
863d938c 6119altivec_init_builtins (void)
a3170dc6
AH
6120{
6121 struct builtin_description *d;
6122 struct builtin_description_predicates *dp;
6123 size_t i;
6124 tree pfloat_type_node = build_pointer_type (float_type_node);
6125 tree pint_type_node = build_pointer_type (integer_type_node);
6126 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6127 tree pchar_type_node = build_pointer_type (char_type_node);
6128
6129 tree pvoid_type_node = build_pointer_type (void_type_node);
6130
0dbc3651
ZW
6131 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6132 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6133 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6134 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6135
6136 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6137
a3170dc6
AH
6138 tree int_ftype_int_v4si_v4si
6139 = build_function_type_list (integer_type_node,
6140 integer_type_node, V4SI_type_node,
6141 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6142 tree v4sf_ftype_pcfloat
6143 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6144 tree void_ftype_pfloat_v4sf
b4de2f7d 6145 = build_function_type_list (void_type_node,
a3170dc6 6146 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6147 tree v4si_ftype_pcint
6148 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6149 tree void_ftype_pint_v4si
b4de2f7d
AH
6150 = build_function_type_list (void_type_node,
6151 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6152 tree v8hi_ftype_pcshort
6153 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6154 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6155 = build_function_type_list (void_type_node,
6156 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6157 tree v16qi_ftype_pcchar
6158 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6159 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6160 = build_function_type_list (void_type_node,
6161 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6162 tree void_ftype_v4si
b4de2f7d 6163 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6164 tree v8hi_ftype_void
6165 = build_function_type (V8HI_type_node, void_list_node);
6166 tree void_ftype_void
6167 = build_function_type (void_type_node, void_list_node);
6168 tree void_ftype_qi
6169 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651
ZW
6170
6171 tree v16qi_ftype_int_pcvoid
a3170dc6 6172 = build_function_type_list (V16QI_type_node,
0dbc3651
ZW
6173 integer_type_node, pcvoid_type_node, NULL_TREE);
6174 tree v8hi_ftype_int_pcvoid
a3170dc6 6175 = build_function_type_list (V8HI_type_node,
0dbc3651
ZW
6176 integer_type_node, pcvoid_type_node, NULL_TREE);
6177 tree v4si_ftype_int_pcvoid
a3170dc6 6178 = build_function_type_list (V4SI_type_node,
0dbc3651
ZW
6179 integer_type_node, pcvoid_type_node, NULL_TREE);
6180
14b32f4e 6181 tree void_ftype_v4si_int_pvoid
b4de2f7d
AH
6182 = build_function_type_list (void_type_node,
6183 V4SI_type_node, integer_type_node,
6184 pvoid_type_node, NULL_TREE);
6525c0e7 6185 tree void_ftype_v16qi_int_pvoid
b4de2f7d
AH
6186 = build_function_type_list (void_type_node,
6187 V16QI_type_node, integer_type_node,
6188 pvoid_type_node, NULL_TREE);
6525c0e7 6189 tree void_ftype_v8hi_int_pvoid
b4de2f7d
AH
6190 = build_function_type_list (void_type_node,
6191 V8HI_type_node, integer_type_node,
6192 pvoid_type_node, NULL_TREE);
a3170dc6
AH
6193 tree int_ftype_int_v8hi_v8hi
6194 = build_function_type_list (integer_type_node,
6195 integer_type_node, V8HI_type_node,
6196 V8HI_type_node, NULL_TREE);
6197 tree int_ftype_int_v16qi_v16qi
6198 = build_function_type_list (integer_type_node,
6199 integer_type_node, V16QI_type_node,
6200 V16QI_type_node, NULL_TREE);
6201 tree int_ftype_int_v4sf_v4sf
6202 = build_function_type_list (integer_type_node,
6203 integer_type_node, V4SF_type_node,
6204 V4SF_type_node, NULL_TREE);
6205 tree v4si_ftype_v4si
6206 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
6207 tree v8hi_ftype_v8hi
6208 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
6209 tree v16qi_ftype_v16qi
6210 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
6211 tree v4sf_ftype_v4sf
6212 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 6213 tree void_ftype_pcvoid_int_char
a3170dc6 6214 = build_function_type_list (void_type_node,
0dbc3651 6215 pcvoid_type_node, integer_type_node,
a3170dc6 6216 char_type_node, NULL_TREE);
0dbc3651
ZW
6217
6218 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
6219 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
6220 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
6221 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
6222 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
6223 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
6224 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
6225 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
6226 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
6227 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
6228 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
6229 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
6230 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
6231 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
6232 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
6233 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
6234 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
6235 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
6236 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
6237 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
0dbc3651
ZW
6238 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL);
6239 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR);
6240 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX);
6241 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX);
6242 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX);
6243 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL);
6244 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX);
a3170dc6
AH
6245 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX);
6246 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX);
6247 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL);
6248 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX);
6249 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX);
6250
6251 /* Add the DST variants. */
6252 d = (struct builtin_description *) bdesc_dst;
6253 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 6254 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
6255
6256 /* Initialize the predicates. */
6257 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
6258 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
6259 {
6260 enum machine_mode mode1;
6261 tree type;
6262
6263 mode1 = insn_data[dp->icode].operand[1].mode;
6264
6265 switch (mode1)
6266 {
6267 case V4SImode:
6268 type = int_ftype_int_v4si_v4si;
6269 break;
6270 case V8HImode:
6271 type = int_ftype_int_v8hi_v8hi;
6272 break;
6273 case V16QImode:
6274 type = int_ftype_int_v16qi_v16qi;
6275 break;
6276 case V4SFmode:
6277 type = int_ftype_int_v4sf_v4sf;
6278 break;
6279 default:
6280 abort ();
6281 }
6282
6283 def_builtin (dp->mask, dp->name, type, dp->code);
6284 }
6285
6286 /* Initialize the abs* operators. */
6287 d = (struct builtin_description *) bdesc_abs;
6288 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
6289 {
6290 enum machine_mode mode0;
6291 tree type;
6292
6293 mode0 = insn_data[d->icode].operand[0].mode;
6294
6295 switch (mode0)
6296 {
6297 case V4SImode:
6298 type = v4si_ftype_v4si;
6299 break;
6300 case V8HImode:
6301 type = v8hi_ftype_v8hi;
6302 break;
6303 case V16QImode:
6304 type = v16qi_ftype_v16qi;
6305 break;
6306 case V4SFmode:
6307 type = v4sf_ftype_v4sf;
6308 break;
6309 default:
6310 abort ();
6311 }
6312
6313 def_builtin (d->mask, d->name, type, d->code);
6314 }
6315}
6316
6317static void
863d938c 6318rs6000_common_init_builtins (void)
a3170dc6
AH
6319{
6320 struct builtin_description *d;
6321 size_t i;
6322
6323 tree v4sf_ftype_v4sf_v4sf_v16qi
6324 = build_function_type_list (V4SF_type_node,
6325 V4SF_type_node, V4SF_type_node,
6326 V16QI_type_node, NULL_TREE);
6327 tree v4si_ftype_v4si_v4si_v16qi
6328 = build_function_type_list (V4SI_type_node,
6329 V4SI_type_node, V4SI_type_node,
6330 V16QI_type_node, NULL_TREE);
6331 tree v8hi_ftype_v8hi_v8hi_v16qi
6332 = build_function_type_list (V8HI_type_node,
6333 V8HI_type_node, V8HI_type_node,
6334 V16QI_type_node, NULL_TREE);
6335 tree v16qi_ftype_v16qi_v16qi_v16qi
6336 = build_function_type_list (V16QI_type_node,
6337 V16QI_type_node, V16QI_type_node,
6338 V16QI_type_node, NULL_TREE);
6339 tree v4si_ftype_char
6340 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
6341 tree v8hi_ftype_char
6342 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
6343 tree v16qi_ftype_char
6344 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
6345 tree v8hi_ftype_v16qi
6346 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
6347 tree v4sf_ftype_v4sf
6348 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
6349
6350 tree v2si_ftype_v2si_v2si
2abe3e28
AH
6351 = build_function_type_list (opaque_V2SI_type_node,
6352 opaque_V2SI_type_node,
6353 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6354
6355 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
6356 = build_function_type_list (opaque_V2SF_type_node,
6357 opaque_V2SF_type_node,
6358 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6359
6360 tree v2si_ftype_int_int
2abe3e28 6361 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6362 integer_type_node, integer_type_node,
6363 NULL_TREE);
6364
6365 tree v2si_ftype_v2si
2abe3e28
AH
6366 = build_function_type_list (opaque_V2SI_type_node,
6367 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6368
6369 tree v2sf_ftype_v2sf
2abe3e28
AH
6370 = build_function_type_list (opaque_V2SF_type_node,
6371 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6372
6373 tree v2sf_ftype_v2si
2abe3e28
AH
6374 = build_function_type_list (opaque_V2SF_type_node,
6375 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6376
6377 tree v2si_ftype_v2sf
2abe3e28
AH
6378 = build_function_type_list (opaque_V2SI_type_node,
6379 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6380
6381 tree v2si_ftype_v2si_char
2abe3e28
AH
6382 = build_function_type_list (opaque_V2SI_type_node,
6383 opaque_V2SI_type_node,
6384 char_type_node, NULL_TREE);
a3170dc6
AH
6385
6386 tree v2si_ftype_int_char
2abe3e28 6387 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6388 integer_type_node, char_type_node, NULL_TREE);
6389
6390 tree v2si_ftype_char
2abe3e28
AH
6391 = build_function_type_list (opaque_V2SI_type_node,
6392 char_type_node, NULL_TREE);
a3170dc6
AH
6393
6394 tree int_ftype_int_int
6395 = build_function_type_list (integer_type_node,
6396 integer_type_node, integer_type_node,
6397 NULL_TREE);
95385cbb 6398
0ac081f6 6399 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
6400 = build_function_type_list (V4SI_type_node,
6401 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 6402 tree v4sf_ftype_v4si_char
b4de2f7d
AH
6403 = build_function_type_list (V4SF_type_node,
6404 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 6405 tree v4si_ftype_v4sf_char
b4de2f7d
AH
6406 = build_function_type_list (V4SI_type_node,
6407 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 6408 tree v4si_ftype_v4si_char
b4de2f7d
AH
6409 = build_function_type_list (V4SI_type_node,
6410 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 6411 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
6412 = build_function_type_list (V8HI_type_node,
6413 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 6414 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
6415 = build_function_type_list (V16QI_type_node,
6416 V16QI_type_node, char_type_node, NULL_TREE);
24408032 6417 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
6418 = build_function_type_list (V16QI_type_node,
6419 V16QI_type_node, V16QI_type_node,
6420 char_type_node, NULL_TREE);
24408032 6421 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
6422 = build_function_type_list (V8HI_type_node,
6423 V8HI_type_node, V8HI_type_node,
6424 char_type_node, NULL_TREE);
24408032 6425 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
6426 = build_function_type_list (V4SI_type_node,
6427 V4SI_type_node, V4SI_type_node,
6428 char_type_node, NULL_TREE);
24408032 6429 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
6430 = build_function_type_list (V4SF_type_node,
6431 V4SF_type_node, V4SF_type_node,
6432 char_type_node, NULL_TREE);
0ac081f6 6433 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
6434 = build_function_type_list (V4SF_type_node,
6435 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 6436 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
6437 = build_function_type_list (V4SF_type_node,
6438 V4SF_type_node, V4SF_type_node,
6439 V4SI_type_node, NULL_TREE);
2212663f 6440 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
6441 = build_function_type_list (V4SF_type_node,
6442 V4SF_type_node, V4SF_type_node,
6443 V4SF_type_node, NULL_TREE);
617e0e1d 6444 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
6445 = build_function_type_list (V4SI_type_node,
6446 V4SI_type_node, V4SI_type_node,
6447 V4SI_type_node, NULL_TREE);
0ac081f6 6448 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
6449 = build_function_type_list (V8HI_type_node,
6450 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 6451 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
6452 = build_function_type_list (V8HI_type_node,
6453 V8HI_type_node, V8HI_type_node,
6454 V8HI_type_node, NULL_TREE);
2212663f 6455 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
6456 = build_function_type_list (V4SI_type_node,
6457 V8HI_type_node, V8HI_type_node,
6458 V4SI_type_node, NULL_TREE);
2212663f 6459 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
6460 = build_function_type_list (V4SI_type_node,
6461 V16QI_type_node, V16QI_type_node,
6462 V4SI_type_node, NULL_TREE);
0ac081f6 6463 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
6464 = build_function_type_list (V16QI_type_node,
6465 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6466 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
6467 = build_function_type_list (V4SI_type_node,
6468 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 6469 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
6470 = build_function_type_list (V8HI_type_node,
6471 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6472 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
6473 = build_function_type_list (V4SI_type_node,
6474 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6475 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
6476 = build_function_type_list (V8HI_type_node,
6477 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 6478 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
6479 = build_function_type_list (V16QI_type_node,
6480 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6481 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
6482 = build_function_type_list (V4SI_type_node,
6483 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 6484 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
6485 = build_function_type_list (V4SI_type_node,
6486 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6487 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
6488 = build_function_type_list (V4SI_type_node,
6489 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6490 tree v4si_ftype_v8hi
6491 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
6492 tree int_ftype_v4si_v4si
6493 = build_function_type_list (integer_type_node,
6494 V4SI_type_node, V4SI_type_node, NULL_TREE);
6495 tree int_ftype_v4sf_v4sf
6496 = build_function_type_list (integer_type_node,
6497 V4SF_type_node, V4SF_type_node, NULL_TREE);
6498 tree int_ftype_v16qi_v16qi
6499 = build_function_type_list (integer_type_node,
6500 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 6501 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
6502 = build_function_type_list (integer_type_node,
6503 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 6504
6f317ef3 6505 /* Add the simple ternary operators. */
2212663f 6506 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 6507 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
6508 {
6509
6510 enum machine_mode mode0, mode1, mode2, mode3;
6511 tree type;
6512
0559cc77 6513 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6514 continue;
6515
6516 mode0 = insn_data[d->icode].operand[0].mode;
6517 mode1 = insn_data[d->icode].operand[1].mode;
6518 mode2 = insn_data[d->icode].operand[2].mode;
6519 mode3 = insn_data[d->icode].operand[3].mode;
6520
6521 /* When all four are of the same mode. */
6522 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
6523 {
6524 switch (mode0)
6525 {
617e0e1d
DB
6526 case V4SImode:
6527 type = v4si_ftype_v4si_v4si_v4si;
6528 break;
2212663f
DB
6529 case V4SFmode:
6530 type = v4sf_ftype_v4sf_v4sf_v4sf;
6531 break;
6532 case V8HImode:
6533 type = v8hi_ftype_v8hi_v8hi_v8hi;
6534 break;
6535 case V16QImode:
6536 type = v16qi_ftype_v16qi_v16qi_v16qi;
6537 break;
6538 default:
6539 abort();
6540 }
6541 }
6542 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
6543 {
6544 switch (mode0)
6545 {
6546 case V4SImode:
6547 type = v4si_ftype_v4si_v4si_v16qi;
6548 break;
6549 case V4SFmode:
6550 type = v4sf_ftype_v4sf_v4sf_v16qi;
6551 break;
6552 case V8HImode:
6553 type = v8hi_ftype_v8hi_v8hi_v16qi;
6554 break;
6555 case V16QImode:
6556 type = v16qi_ftype_v16qi_v16qi_v16qi;
6557 break;
6558 default:
6559 abort();
6560 }
6561 }
6562 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
6563 && mode3 == V4SImode)
24408032 6564 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
6565 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
6566 && mode3 == V4SImode)
24408032 6567 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
6568 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
6569 && mode3 == V4SImode)
24408032
AH
6570 type = v4sf_ftype_v4sf_v4sf_v4si;
6571
6572 /* vchar, vchar, vchar, 4 bit literal. */
6573 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
6574 && mode3 == QImode)
6575 type = v16qi_ftype_v16qi_v16qi_char;
6576
6577 /* vshort, vshort, vshort, 4 bit literal. */
6578 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
6579 && mode3 == QImode)
6580 type = v8hi_ftype_v8hi_v8hi_char;
6581
6582 /* vint, vint, vint, 4 bit literal. */
6583 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
6584 && mode3 == QImode)
6585 type = v4si_ftype_v4si_v4si_char;
6586
6587 /* vfloat, vfloat, vfloat, 4 bit literal. */
6588 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
6589 && mode3 == QImode)
6590 type = v4sf_ftype_v4sf_v4sf_char;
6591
2212663f
DB
6592 else
6593 abort ();
6594
6595 def_builtin (d->mask, d->name, type, d->code);
6596 }
6597
0ac081f6 6598 /* Add the simple binary operators. */
00b960c7 6599 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 6600 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
6601 {
6602 enum machine_mode mode0, mode1, mode2;
6603 tree type;
6604
0559cc77 6605 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
6606 continue;
6607
6608 mode0 = insn_data[d->icode].operand[0].mode;
6609 mode1 = insn_data[d->icode].operand[1].mode;
6610 mode2 = insn_data[d->icode].operand[2].mode;
6611
6612 /* When all three operands are of the same mode. */
6613 if (mode0 == mode1 && mode1 == mode2)
6614 {
6615 switch (mode0)
6616 {
6617 case V4SFmode:
6618 type = v4sf_ftype_v4sf_v4sf;
6619 break;
6620 case V4SImode:
6621 type = v4si_ftype_v4si_v4si;
6622 break;
6623 case V16QImode:
6624 type = v16qi_ftype_v16qi_v16qi;
6625 break;
6626 case V8HImode:
6627 type = v8hi_ftype_v8hi_v8hi;
6628 break;
a3170dc6
AH
6629 case V2SImode:
6630 type = v2si_ftype_v2si_v2si;
6631 break;
6632 case V2SFmode:
6633 type = v2sf_ftype_v2sf_v2sf;
6634 break;
6635 case SImode:
6636 type = int_ftype_int_int;
6637 break;
0ac081f6
AH
6638 default:
6639 abort ();
6640 }
6641 }
6642
6643 /* A few other combos we really don't want to do manually. */
6644
6645 /* vint, vfloat, vfloat. */
6646 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
6647 type = v4si_ftype_v4sf_v4sf;
6648
6649 /* vshort, vchar, vchar. */
6650 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
6651 type = v8hi_ftype_v16qi_v16qi;
6652
6653 /* vint, vshort, vshort. */
6654 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
6655 type = v4si_ftype_v8hi_v8hi;
6656
6657 /* vshort, vint, vint. */
6658 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
6659 type = v8hi_ftype_v4si_v4si;
6660
6661 /* vchar, vshort, vshort. */
6662 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
6663 type = v16qi_ftype_v8hi_v8hi;
6664
6665 /* vint, vchar, vint. */
6666 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
6667 type = v4si_ftype_v16qi_v4si;
6668
fa066a23
AH
6669 /* vint, vchar, vchar. */
6670 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
6671 type = v4si_ftype_v16qi_v16qi;
6672
0ac081f6
AH
6673 /* vint, vshort, vint. */
6674 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
6675 type = v4si_ftype_v8hi_v4si;
2212663f
DB
6676
6677 /* vint, vint, 5 bit literal. */
6678 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
6679 type = v4si_ftype_v4si_char;
6680
6681 /* vshort, vshort, 5 bit literal. */
6682 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
6683 type = v8hi_ftype_v8hi_char;
6684
6685 /* vchar, vchar, 5 bit literal. */
6686 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
6687 type = v16qi_ftype_v16qi_char;
0ac081f6 6688
617e0e1d
DB
6689 /* vfloat, vint, 5 bit literal. */
6690 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
6691 type = v4sf_ftype_v4si_char;
6692
6693 /* vint, vfloat, 5 bit literal. */
6694 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
6695 type = v4si_ftype_v4sf_char;
6696
a3170dc6
AH
6697 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
6698 type = v2si_ftype_int_int;
6699
6700 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
6701 type = v2si_ftype_v2si_char;
6702
6703 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
6704 type = v2si_ftype_int_char;
6705
0ac081f6
AH
6706 /* int, x, x. */
6707 else if (mode0 == SImode)
6708 {
6709 switch (mode1)
6710 {
6711 case V4SImode:
6712 type = int_ftype_v4si_v4si;
6713 break;
6714 case V4SFmode:
6715 type = int_ftype_v4sf_v4sf;
6716 break;
6717 case V16QImode:
6718 type = int_ftype_v16qi_v16qi;
6719 break;
6720 case V8HImode:
6721 type = int_ftype_v8hi_v8hi;
6722 break;
6723 default:
6724 abort ();
6725 }
6726 }
6727
6728 else
6729 abort ();
6730
2212663f
DB
6731 def_builtin (d->mask, d->name, type, d->code);
6732 }
24408032 6733
2212663f
DB
6734 /* Add the simple unary operators. */
6735 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 6736 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
6737 {
6738 enum machine_mode mode0, mode1;
6739 tree type;
6740
0559cc77 6741 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6742 continue;
6743
6744 mode0 = insn_data[d->icode].operand[0].mode;
6745 mode1 = insn_data[d->icode].operand[1].mode;
6746
6747 if (mode0 == V4SImode && mode1 == QImode)
6748 type = v4si_ftype_char;
6749 else if (mode0 == V8HImode && mode1 == QImode)
6750 type = v8hi_ftype_char;
6751 else if (mode0 == V16QImode && mode1 == QImode)
6752 type = v16qi_ftype_char;
617e0e1d
DB
6753 else if (mode0 == V4SFmode && mode1 == V4SFmode)
6754 type = v4sf_ftype_v4sf;
20e26713
AH
6755 else if (mode0 == V8HImode && mode1 == V16QImode)
6756 type = v8hi_ftype_v16qi;
6757 else if (mode0 == V4SImode && mode1 == V8HImode)
6758 type = v4si_ftype_v8hi;
a3170dc6
AH
6759 else if (mode0 == V2SImode && mode1 == V2SImode)
6760 type = v2si_ftype_v2si;
6761 else if (mode0 == V2SFmode && mode1 == V2SFmode)
6762 type = v2sf_ftype_v2sf;
6763 else if (mode0 == V2SFmode && mode1 == V2SImode)
6764 type = v2sf_ftype_v2si;
6765 else if (mode0 == V2SImode && mode1 == V2SFmode)
6766 type = v2si_ftype_v2sf;
6767 else if (mode0 == V2SImode && mode1 == QImode)
6768 type = v2si_ftype_char;
2212663f
DB
6769 else
6770 abort ();
6771
0ac081f6
AH
6772 def_builtin (d->mask, d->name, type, d->code);
6773 }
6774}
6775
c15c90bb
ZW
6776static void
6777rs6000_init_libfuncs (void)
6778{
6779 if (!TARGET_HARD_FLOAT)
6780 return;
6781
c9034561 6782 if (DEFAULT_ABI != ABI_V4)
c15c90bb 6783 {
c9034561 6784 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 6785 {
c9034561 6786 /* AIX library routines for float->int conversion. */
c15c90bb
ZW
6787 fixdfsi_libfunc = init_one_libfunc ("__itrunc");
6788 fixunsdfsi_libfunc = init_one_libfunc ("__uitrunc");
6789 }
6790
c9034561 6791 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
6792 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
6793 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
6794 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
6795 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
6796 }
c9034561 6797 else
c15c90bb 6798 {
c9034561 6799 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
6800
6801 set_optab_libfunc (add_optab, TFmode, "_q_add");
6802 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
6803 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
6804 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
6805 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
6806 if (TARGET_PPC_GPOPT || TARGET_POWER2)
6807 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
6808
c9034561
ZW
6809 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
6810 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
6811 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
6812 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
6813 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
6814 set_optab_libfunc (le_optab, TFmode, "_q_fle");
6815
c15c90bb
ZW
6816 trunctfsf2_libfunc = init_one_libfunc ("_q_qtos");
6817 trunctfdf2_libfunc = init_one_libfunc ("_q_qtod");
6818 extendsftf2_libfunc = init_one_libfunc ("_q_stoq");
6819 extenddftf2_libfunc = init_one_libfunc ("_q_dtoq");
6820 floatsitf_libfunc = init_one_libfunc ("_q_itoq");
6821 fixtfsi_libfunc = init_one_libfunc ("_q_qtoi");
6822 fixunstfsi_libfunc = init_one_libfunc ("_q_qtou");
6823 }
6824}
6825
6826
35aff10b 6827\f
7e69e155
MM
6828/* Expand a block move operation, and return 1 if successful. Return 0
6829 if we should let the compiler generate normal code.
6830
6831 operands[0] is the destination
6832 operands[1] is the source
6833 operands[2] is the length
6834 operands[3] is the alignment */
6835
3933e0e1
MM
6836#define MAX_MOVE_REG 4
6837
7e69e155 6838int
a2369ed3 6839expand_block_move (rtx operands[])
7e69e155 6840{
b6c9286a
MM
6841 rtx orig_dest = operands[0];
6842 rtx orig_src = operands[1];
7e69e155 6843 rtx bytes_rtx = operands[2];
7e69e155 6844 rtx align_rtx = operands[3];
3933e0e1 6845 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 6846 int align;
3933e0e1
MM
6847 int bytes;
6848 int offset;
7e69e155 6849 int move_bytes;
cabfd258
GK
6850 rtx stores[MAX_MOVE_REG];
6851 int num_reg = 0;
7e69e155 6852
3933e0e1 6853 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 6854 if (! constp)
3933e0e1
MM
6855 return 0;
6856
5ee95df6
FS
6857 /* If this is not a fixed size alignment, abort */
6858 if (GET_CODE (align_rtx) != CONST_INT)
6859 abort ();
6860 align = INTVAL (align_rtx);
6861
7e69e155 6862 /* Anything to move? */
3933e0e1
MM
6863 bytes = INTVAL (bytes_rtx);
6864 if (bytes <= 0)
7e69e155
MM
6865 return 1;
6866
ea9982a8 6867 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 6868 reg_parm_stack_space. */
ea9982a8 6869 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
6870 return 0;
6871
cabfd258 6872 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6873 {
cabfd258 6874 union {
a2369ed3
DJ
6875 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
6876 rtx (*mov) (rtx, rtx);
cabfd258
GK
6877 } gen_func;
6878 enum machine_mode mode = BLKmode;
6879 rtx src, dest;
6880
6881 if (TARGET_STRING
6882 && bytes > 24 /* move up to 32 bytes at a time */
6883 && ! fixed_regs[5]
6884 && ! fixed_regs[6]
6885 && ! fixed_regs[7]
6886 && ! fixed_regs[8]
6887 && ! fixed_regs[9]
6888 && ! fixed_regs[10]
6889 && ! fixed_regs[11]
6890 && ! fixed_regs[12])
7e69e155 6891 {
cabfd258
GK
6892 move_bytes = (bytes > 32) ? 32 : bytes;
6893 gen_func.movstrsi = gen_movstrsi_8reg;
6894 }
6895 else if (TARGET_STRING
6896 && bytes > 16 /* move up to 24 bytes at a time */
6897 && ! fixed_regs[5]
6898 && ! fixed_regs[6]
6899 && ! fixed_regs[7]
6900 && ! fixed_regs[8]
6901 && ! fixed_regs[9]
6902 && ! fixed_regs[10])
6903 {
6904 move_bytes = (bytes > 24) ? 24 : bytes;
6905 gen_func.movstrsi = gen_movstrsi_6reg;
6906 }
6907 else if (TARGET_STRING
6908 && bytes > 8 /* move up to 16 bytes at a time */
6909 && ! fixed_regs[5]
6910 && ! fixed_regs[6]
6911 && ! fixed_regs[7]
6912 && ! fixed_regs[8])
6913 {
6914 move_bytes = (bytes > 16) ? 16 : bytes;
6915 gen_func.movstrsi = gen_movstrsi_4reg;
6916 }
6917 else if (bytes >= 8 && TARGET_POWERPC64
6918 /* 64-bit loads and stores require word-aligned
6919 displacements. */
6920 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
6921 {
6922 move_bytes = 8;
6923 mode = DImode;
6924 gen_func.mov = gen_movdi;
6925 }
6926 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
6927 { /* move up to 8 bytes at a time */
6928 move_bytes = (bytes > 8) ? 8 : bytes;
6929 gen_func.movstrsi = gen_movstrsi_2reg;
6930 }
6931 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
6932 { /* move 4 bytes */
6933 move_bytes = 4;
6934 mode = SImode;
6935 gen_func.mov = gen_movsi;
6936 }
6937 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
6938 { /* move 2 bytes */
6939 move_bytes = 2;
6940 mode = HImode;
6941 gen_func.mov = gen_movhi;
6942 }
6943 else if (TARGET_STRING && bytes > 1)
6944 { /* move up to 4 bytes at a time */
6945 move_bytes = (bytes > 4) ? 4 : bytes;
6946 gen_func.movstrsi = gen_movstrsi_1reg;
6947 }
6948 else /* move 1 byte at a time */
6949 {
6950 move_bytes = 1;
6951 mode = QImode;
6952 gen_func.mov = gen_movqi;
6953 }
6954
6955 src = adjust_address (orig_src, mode, offset);
6956 dest = adjust_address (orig_dest, mode, offset);
6957
6958 if (mode != BLKmode)
6959 {
6960 rtx tmp_reg = gen_reg_rtx (mode);
6961
6962 emit_insn ((*gen_func.mov) (tmp_reg, src));
6963 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 6964 }
3933e0e1 6965
cabfd258
GK
6966 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
6967 {
6968 int i;
6969 for (i = 0; i < num_reg; i++)
6970 emit_insn (stores[i]);
6971 num_reg = 0;
6972 }
35aff10b 6973
cabfd258 6974 if (mode == BLKmode)
7e69e155 6975 {
cabfd258
GK
6976 /* Move the address into scratch registers. The movstrsi
6977 patterns require zero offset. */
6978 if (!REG_P (XEXP (src, 0)))
b6c9286a 6979 {
cabfd258
GK
6980 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
6981 src = replace_equiv_address (src, src_reg);
b6c9286a 6982 }
cabfd258
GK
6983 set_mem_size (src, GEN_INT (move_bytes));
6984
6985 if (!REG_P (XEXP (dest, 0)))
3933e0e1 6986 {
cabfd258
GK
6987 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
6988 dest = replace_equiv_address (dest, dest_reg);
7e69e155 6989 }
cabfd258
GK
6990 set_mem_size (dest, GEN_INT (move_bytes));
6991
6992 emit_insn ((*gen_func.movstrsi) (dest, src,
6993 GEN_INT (move_bytes & 31),
6994 align_rtx));
7e69e155 6995 }
7e69e155
MM
6996 }
6997
6998 return 1;
6999}
7000
9878760c
RK
7001\f
7002/* Return 1 if OP is a load multiple operation. It is known to be a
7003 PARALLEL and the first section will be tested. */
7004
7005int
a2369ed3 7006load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7007{
7008 int count = XVECLEN (op, 0);
e2c953b6 7009 unsigned int dest_regno;
9878760c
RK
7010 rtx src_addr;
7011 int i;
7012
7013 /* Perform a quick check so we don't blow up below. */
7014 if (count <= 1
7015 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7016 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7017 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7018 return 0;
7019
7020 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7021 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7022
7023 for (i = 1; i < count; i++)
7024 {
7025 rtx elt = XVECEXP (op, 0, i);
7026
7027 if (GET_CODE (elt) != SET
7028 || GET_CODE (SET_DEST (elt)) != REG
7029 || GET_MODE (SET_DEST (elt)) != SImode
7030 || REGNO (SET_DEST (elt)) != dest_regno + i
7031 || GET_CODE (SET_SRC (elt)) != MEM
7032 || GET_MODE (SET_SRC (elt)) != SImode
7033 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7034 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7035 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7036 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7037 return 0;
7038 }
7039
7040 return 1;
7041}
7042
7043/* Similar, but tests for store multiple. Here, the second vector element
7044 is a CLOBBER. It will be tested later. */
7045
7046int
a2369ed3 7047store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7048{
7049 int count = XVECLEN (op, 0) - 1;
e2c953b6 7050 unsigned int src_regno;
9878760c
RK
7051 rtx dest_addr;
7052 int i;
7053
7054 /* Perform a quick check so we don't blow up below. */
7055 if (count <= 1
7056 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7057 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7058 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7059 return 0;
7060
7061 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7062 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7063
7064 for (i = 1; i < count; i++)
7065 {
7066 rtx elt = XVECEXP (op, 0, i + 1);
7067
7068 if (GET_CODE (elt) != SET
7069 || GET_CODE (SET_SRC (elt)) != REG
7070 || GET_MODE (SET_SRC (elt)) != SImode
7071 || REGNO (SET_SRC (elt)) != src_regno + i
7072 || GET_CODE (SET_DEST (elt)) != MEM
7073 || GET_MODE (SET_DEST (elt)) != SImode
7074 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7075 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7076 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7077 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7078 return 0;
7079 }
7080
7081 return 1;
7082}
9ebbca7d 7083
9caa3eb2
DE
7084/* Return a string to perform a load_multiple operation.
7085 operands[0] is the vector.
7086 operands[1] is the source address.
7087 operands[2] is the first destination register. */
7088
7089const char *
a2369ed3 7090rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7091{
7092 /* We have to handle the case where the pseudo used to contain the address
7093 is assigned to one of the output registers. */
7094 int i, j;
7095 int words = XVECLEN (operands[0], 0);
7096 rtx xop[10];
7097
7098 if (XVECLEN (operands[0], 0) == 1)
7099 return "{l|lwz} %2,0(%1)";
7100
7101 for (i = 0; i < words; i++)
7102 if (refers_to_regno_p (REGNO (operands[2]) + i,
7103 REGNO (operands[2]) + i + 1, operands[1], 0))
7104 {
7105 if (i == words-1)
7106 {
7107 xop[0] = GEN_INT (4 * (words-1));
7108 xop[1] = operands[1];
7109 xop[2] = operands[2];
7110 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7111 return "";
7112 }
7113 else if (i == 0)
7114 {
7115 xop[0] = GEN_INT (4 * (words-1));
7116 xop[1] = operands[1];
7117 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7118 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);
7119 return "";
7120 }
7121 else
7122 {
7123 for (j = 0; j < words; j++)
7124 if (j != i)
7125 {
7126 xop[0] = GEN_INT (j * 4);
7127 xop[1] = operands[1];
7128 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7129 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7130 }
7131 xop[0] = GEN_INT (i * 4);
7132 xop[1] = operands[1];
7133 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7134 return "";
7135 }
7136 }
7137
7138 return "{lsi|lswi} %2,%1,%N0";
7139}
7140
00b960c7
AH
7141/* Return 1 for a parallel vrsave operation. */
7142
7143int
a2369ed3 7144vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
7145{
7146 int count = XVECLEN (op, 0);
7147 unsigned int dest_regno, src_regno;
7148 int i;
7149
7150 if (count <= 1
7151 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7152 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7153 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7154 return 0;
7155
7156 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7157 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7158
7159 if (dest_regno != VRSAVE_REGNO
7160 && src_regno != VRSAVE_REGNO)
7161 return 0;
7162
7163 for (i = 1; i < count; i++)
7164 {
7165 rtx elt = XVECEXP (op, 0, i);
7166
9aa86737
AH
7167 if (GET_CODE (elt) != CLOBBER
7168 && GET_CODE (elt) != SET)
00b960c7
AH
7169 return 0;
7170 }
7171
7172 return 1;
7173}
7174
2c4a9cff
DE
7175/* Return 1 for an PARALLEL suitable for mfcr. */
7176
7177int
a2369ed3 7178mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
7179{
7180 int count = XVECLEN (op, 0);
7181 int i;
7182
7183 /* Perform a quick check so we don't blow up below. */
7184 if (count < 1
7185 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7186 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7187 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
7188 return 0;
7189
7190 for (i = 0; i < count; i++)
7191 {
7192 rtx exp = XVECEXP (op, 0, i);
7193 rtx unspec;
7194 int maskval;
7195 rtx src_reg;
7196
7197 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
7198
7199 if (GET_CODE (src_reg) != REG
7200 || GET_MODE (src_reg) != CCmode
7201 || ! CR_REGNO_P (REGNO (src_reg)))
7202 return 0;
7203
7204 if (GET_CODE (exp) != SET
7205 || GET_CODE (SET_DEST (exp)) != REG
7206 || GET_MODE (SET_DEST (exp)) != SImode
7207 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
7208 return 0;
7209 unspec = SET_SRC (exp);
7210 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
7211
7212 if (GET_CODE (unspec) != UNSPEC
7213 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
7214 || XVECLEN (unspec, 0) != 2
7215 || XVECEXP (unspec, 0, 0) != src_reg
7216 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7217 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7218 return 0;
7219 }
7220 return 1;
7221}
7222
a4f6c312 7223/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
7224
7225int
a2369ed3 7226mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7227{
7228 int count = XVECLEN (op, 0);
7229 int i;
9ebbca7d
GK
7230 rtx src_reg;
7231
7232 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
7233 if (count < 1
7234 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7235 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7236 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 7237 return 0;
e35b9579 7238 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
7239
7240 if (GET_CODE (src_reg) != REG
7241 || GET_MODE (src_reg) != SImode
7242 || ! INT_REGNO_P (REGNO (src_reg)))
7243 return 0;
7244
e35b9579 7245 for (i = 0; i < count; i++)
9ebbca7d
GK
7246 {
7247 rtx exp = XVECEXP (op, 0, i);
7248 rtx unspec;
7249 int maskval;
7250
7251 if (GET_CODE (exp) != SET
7252 || GET_CODE (SET_DEST (exp)) != REG
7253 || GET_MODE (SET_DEST (exp)) != CCmode
7254 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
7255 return 0;
7256 unspec = SET_SRC (exp);
7257 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
7258
7259 if (GET_CODE (unspec) != UNSPEC
615158e2 7260 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
7261 || XVECLEN (unspec, 0) != 2
7262 || XVECEXP (unspec, 0, 0) != src_reg
7263 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7264 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7265 return 0;
7266 }
e35b9579 7267 return 1;
9ebbca7d
GK
7268}
7269
a4f6c312 7270/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
7271
7272int
a2369ed3 7273lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7274{
7275 int count = XVECLEN (op, 0);
e2c953b6 7276 unsigned int dest_regno;
9ebbca7d 7277 rtx src_addr;
e2c953b6 7278 unsigned int base_regno;
9ebbca7d
GK
7279 HOST_WIDE_INT offset;
7280 int i;
7281
7282 /* Perform a quick check so we don't blow up below. */
7283 if (count <= 1
7284 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7285 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7286 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7287 return 0;
7288
7289 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7290 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7291
7292 if (dest_regno > 31
e2c953b6 7293 || count != 32 - (int) dest_regno)
9ebbca7d
GK
7294 return 0;
7295
4d588c14 7296 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
7297 {
7298 offset = 0;
7299 base_regno = REGNO (src_addr);
7300 if (base_regno == 0)
7301 return 0;
7302 }
4d588c14 7303 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
7304 {
7305 offset = INTVAL (XEXP (src_addr, 1));
7306 base_regno = REGNO (XEXP (src_addr, 0));
7307 }
7308 else
7309 return 0;
7310
7311 for (i = 0; i < count; i++)
7312 {
7313 rtx elt = XVECEXP (op, 0, i);
7314 rtx newaddr;
7315 rtx addr_reg;
7316 HOST_WIDE_INT newoffset;
7317
7318 if (GET_CODE (elt) != SET
7319 || GET_CODE (SET_DEST (elt)) != REG
7320 || GET_MODE (SET_DEST (elt)) != SImode
7321 || REGNO (SET_DEST (elt)) != dest_regno + i
7322 || GET_CODE (SET_SRC (elt)) != MEM
7323 || GET_MODE (SET_SRC (elt)) != SImode)
7324 return 0;
7325 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 7326 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7327 {
7328 newoffset = 0;
7329 addr_reg = newaddr;
7330 }
4d588c14 7331 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7332 {
7333 addr_reg = XEXP (newaddr, 0);
7334 newoffset = INTVAL (XEXP (newaddr, 1));
7335 }
7336 else
7337 return 0;
7338 if (REGNO (addr_reg) != base_regno
7339 || newoffset != offset + 4 * i)
7340 return 0;
7341 }
7342
7343 return 1;
7344}
7345
a4f6c312 7346/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
7347
7348int
a2369ed3 7349stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7350{
7351 int count = XVECLEN (op, 0);
e2c953b6 7352 unsigned int src_regno;
9ebbca7d 7353 rtx dest_addr;
e2c953b6 7354 unsigned int base_regno;
9ebbca7d
GK
7355 HOST_WIDE_INT offset;
7356 int i;
7357
7358 /* Perform a quick check so we don't blow up below. */
7359 if (count <= 1
7360 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7361 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7362 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7363 return 0;
7364
7365 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7366 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7367
7368 if (src_regno > 31
e2c953b6 7369 || count != 32 - (int) src_regno)
9ebbca7d
GK
7370 return 0;
7371
4d588c14 7372 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
7373 {
7374 offset = 0;
7375 base_regno = REGNO (dest_addr);
7376 if (base_regno == 0)
7377 return 0;
7378 }
4d588c14 7379 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
7380 {
7381 offset = INTVAL (XEXP (dest_addr, 1));
7382 base_regno = REGNO (XEXP (dest_addr, 0));
7383 }
7384 else
7385 return 0;
7386
7387 for (i = 0; i < count; i++)
7388 {
7389 rtx elt = XVECEXP (op, 0, i);
7390 rtx newaddr;
7391 rtx addr_reg;
7392 HOST_WIDE_INT newoffset;
7393
7394 if (GET_CODE (elt) != SET
7395 || GET_CODE (SET_SRC (elt)) != REG
7396 || GET_MODE (SET_SRC (elt)) != SImode
7397 || REGNO (SET_SRC (elt)) != src_regno + i
7398 || GET_CODE (SET_DEST (elt)) != MEM
7399 || GET_MODE (SET_DEST (elt)) != SImode)
7400 return 0;
7401 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 7402 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7403 {
7404 newoffset = 0;
7405 addr_reg = newaddr;
7406 }
4d588c14 7407 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7408 {
7409 addr_reg = XEXP (newaddr, 0);
7410 newoffset = INTVAL (XEXP (newaddr, 1));
7411 }
7412 else
7413 return 0;
7414 if (REGNO (addr_reg) != base_regno
7415 || newoffset != offset + 4 * i)
7416 return 0;
7417 }
7418
7419 return 1;
7420}
9878760c 7421\f
a4f6c312
SS
7422/* A validation routine: say whether CODE, a condition code, and MODE
7423 match. The other alternatives either don't make sense or should
7424 never be generated. */
39a10a29 7425
39a10a29 7426static void
a2369ed3 7427validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29
GK
7428{
7429 if (GET_RTX_CLASS (code) != '<'
7430 || GET_MODE_CLASS (mode) != MODE_CC)
7431 abort ();
7432
7433 /* These don't make sense. */
7434 if ((code == GT || code == LT || code == GE || code == LE)
7435 && mode == CCUNSmode)
7436 abort ();
7437
7438 if ((code == GTU || code == LTU || code == GEU || code == LEU)
7439 && mode != CCUNSmode)
7440 abort ();
7441
7442 if (mode != CCFPmode
7443 && (code == ORDERED || code == UNORDERED
7444 || code == UNEQ || code == LTGT
7445 || code == UNGT || code == UNLT
7446 || code == UNGE || code == UNLE))
a4f6c312 7447 abort ();
39a10a29 7448
de6c5979 7449 /* These should never be generated except for
bc9ec0e0 7450 flag_finite_math_only. */
39a10a29 7451 if (mode == CCFPmode
ad72b533 7452 && ! flag_finite_math_only
39a10a29
GK
7453 && (code == LE || code == GE
7454 || code == UNEQ || code == LTGT
7455 || code == UNGT || code == UNLT))
7456 abort ();
7457
7458 /* These are invalid; the information is not there. */
7459 if (mode == CCEQmode
7460 && code != EQ && code != NE)
7461 abort ();
7462}
7463
9878760c
RK
7464/* Return 1 if OP is a comparison operation that is valid for a branch insn.
7465 We only check the opcode against the mode of the CC value here. */
7466
7467int
a2369ed3 7468branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7469{
7470 enum rtx_code code = GET_CODE (op);
7471 enum machine_mode cc_mode;
7472
7473 if (GET_RTX_CLASS (code) != '<')
7474 return 0;
7475
7476 cc_mode = GET_MODE (XEXP (op, 0));
7477 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
7478 return 0;
7479
39a10a29 7480 validate_condition_mode (code, cc_mode);
9878760c 7481
39a10a29
GK
7482 return 1;
7483}
7484
7485/* Return 1 if OP is a comparison operation that is valid for a branch
7486 insn and which is true if the corresponding bit in the CC register
7487 is set. */
7488
7489int
a2369ed3 7490branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
7491{
7492 enum rtx_code code;
7493
8daf2e65 7494 if (! branch_comparison_operator (op, mode))
9878760c
RK
7495 return 0;
7496
39a10a29
GK
7497 code = GET_CODE (op);
7498 return (code == EQ || code == LT || code == GT
993f19a8 7499 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
7500 || code == LTU || code == GTU
7501 || code == UNORDERED);
9878760c
RK
7502}
7503
b7053a3f
GK
7504/* Return 1 if OP is a comparison operation that is valid for an scc
7505 insn: it must be a positive comparison. */
9878760c
RK
7506
7507int
a2369ed3 7508scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 7509{
b7053a3f 7510 return branch_positive_comparison_operator (op, mode);
9878760c 7511}
e0cd0770
JC
7512
7513int
a2369ed3 7514trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
7515{
7516 if (mode != VOIDmode && mode != GET_MODE (op))
7517 return 0;
39a10a29 7518 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 7519}
dfbdccdb
GK
7520
7521int
a2369ed3 7522boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
7523{
7524 enum rtx_code code = GET_CODE (op);
7525 return (code == AND || code == IOR || code == XOR);
7526}
1d328b19
GK
7527
7528int
a2369ed3 7529boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
7530{
7531 enum rtx_code code = GET_CODE (op);
7532 return (code == IOR || code == XOR);
7533}
50a0b056
GK
7534
7535int
a2369ed3 7536min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
7537{
7538 enum rtx_code code = GET_CODE (op);
7539 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
7540}
9878760c
RK
7541\f
7542/* Return 1 if ANDOP is a mask that has no bits on that are not in the
7543 mask required to convert the result of a rotate insn into a shift
b1765bde 7544 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
7545
7546int
a2369ed3 7547includes_lshift_p (rtx shiftop, rtx andop)
9878760c 7548{
e2c953b6
DE
7549 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
7550
7551 shift_mask <<= INTVAL (shiftop);
9878760c 7552
b1765bde 7553 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
7554}
7555
7556/* Similar, but for right shift. */
7557
7558int
a2369ed3 7559includes_rshift_p (rtx shiftop, rtx andop)
9878760c 7560{
a7653a2c 7561 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
7562
7563 shift_mask >>= INTVAL (shiftop);
7564
b1765bde 7565 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
7566}
7567
c5059423
AM
7568/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
7569 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 7570 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
7571
7572int
a2369ed3 7573includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 7574{
c5059423
AM
7575 if (GET_CODE (andop) == CONST_INT)
7576 {
02071907 7577 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 7578
c5059423 7579 c = INTVAL (andop);
02071907 7580 if (c == 0 || c == ~0)
c5059423 7581 return 0;
e2c953b6 7582
02071907 7583 shift_mask = ~0;
c5059423
AM
7584 shift_mask <<= INTVAL (shiftop);
7585
b6d08ca1 7586 /* Find the least significant one bit. */
c5059423
AM
7587 lsb = c & -c;
7588
7589 /* It must coincide with the LSB of the shift mask. */
7590 if (-lsb != shift_mask)
7591 return 0;
e2c953b6 7592
c5059423
AM
7593 /* Invert to look for the next transition (if any). */
7594 c = ~c;
7595
7596 /* Remove the low group of ones (originally low group of zeros). */
7597 c &= -lsb;
7598
7599 /* Again find the lsb, and check we have all 1's above. */
7600 lsb = c & -c;
7601 return c == -lsb;
7602 }
7603 else if (GET_CODE (andop) == CONST_DOUBLE
7604 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7605 {
02071907
AM
7606 HOST_WIDE_INT low, high, lsb;
7607 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
7608
7609 low = CONST_DOUBLE_LOW (andop);
7610 if (HOST_BITS_PER_WIDE_INT < 64)
7611 high = CONST_DOUBLE_HIGH (andop);
7612
7613 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 7614 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
7615 return 0;
7616
7617 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7618 {
02071907 7619 shift_mask_high = ~0;
c5059423
AM
7620 if (INTVAL (shiftop) > 32)
7621 shift_mask_high <<= INTVAL (shiftop) - 32;
7622
7623 lsb = high & -high;
7624
7625 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
7626 return 0;
7627
7628 high = ~high;
7629 high &= -lsb;
7630
7631 lsb = high & -high;
7632 return high == -lsb;
7633 }
7634
02071907 7635 shift_mask_low = ~0;
c5059423
AM
7636 shift_mask_low <<= INTVAL (shiftop);
7637
7638 lsb = low & -low;
7639
7640 if (-lsb != shift_mask_low)
7641 return 0;
7642
7643 if (HOST_BITS_PER_WIDE_INT < 64)
7644 high = ~high;
7645 low = ~low;
7646 low &= -lsb;
7647
7648 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7649 {
7650 lsb = high & -high;
7651 return high == -lsb;
7652 }
7653
7654 lsb = low & -low;
7655 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
7656 }
7657 else
7658 return 0;
7659}
e2c953b6 7660
c5059423
AM
7661/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
7662 to perform a left shift. It must have SHIFTOP or more least
c1207243 7663 significant 0's, with the remainder of the word 1's. */
e2c953b6 7664
c5059423 7665int
a2369ed3 7666includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 7667{
e2c953b6 7668 if (GET_CODE (andop) == CONST_INT)
c5059423 7669 {
02071907 7670 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 7671
02071907 7672 shift_mask = ~0;
c5059423
AM
7673 shift_mask <<= INTVAL (shiftop);
7674 c = INTVAL (andop);
7675
c1207243 7676 /* Find the least significant one bit. */
c5059423
AM
7677 lsb = c & -c;
7678
7679 /* It must be covered by the shift mask.
a4f6c312 7680 This test also rejects c == 0. */
c5059423
AM
7681 if ((lsb & shift_mask) == 0)
7682 return 0;
7683
7684 /* Check we have all 1's above the transition, and reject all 1's. */
7685 return c == -lsb && lsb != 1;
7686 }
7687 else if (GET_CODE (andop) == CONST_DOUBLE
7688 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7689 {
02071907 7690 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
7691
7692 low = CONST_DOUBLE_LOW (andop);
7693
7694 if (HOST_BITS_PER_WIDE_INT < 64)
7695 {
02071907 7696 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
7697
7698 high = CONST_DOUBLE_HIGH (andop);
7699
7700 if (low == 0)
7701 {
02071907 7702 shift_mask_high = ~0;
c5059423
AM
7703 if (INTVAL (shiftop) > 32)
7704 shift_mask_high <<= INTVAL (shiftop) - 32;
7705
7706 lsb = high & -high;
7707
7708 if ((lsb & shift_mask_high) == 0)
7709 return 0;
7710
7711 return high == -lsb;
7712 }
7713 if (high != ~0)
7714 return 0;
7715 }
7716
02071907 7717 shift_mask_low = ~0;
c5059423
AM
7718 shift_mask_low <<= INTVAL (shiftop);
7719
7720 lsb = low & -low;
7721
7722 if ((lsb & shift_mask_low) == 0)
7723 return 0;
7724
7725 return low == -lsb && lsb != 1;
7726 }
e2c953b6 7727 else
c5059423 7728 return 0;
9878760c 7729}
35068b43
RK
7730
7731/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
7732 for lfq and stfq insns.
7733
7734 Note reg1 and reg2 *must* be hard registers. To be sure we will
7735 abort if we are passed pseudo registers. */
7736
7737int
a2369ed3 7738registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
7739{
7740 /* We might have been passed a SUBREG. */
7741 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7742 return 0;
7743
7744 return (REGNO (reg1) == REGNO (reg2) - 1);
7745}
7746
a4f6c312
SS
7747/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
7748 addr1 and addr2 must be in consecutive memory locations
7749 (addr2 == addr1 + 8). */
35068b43
RK
7750
7751int
a2369ed3 7752addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 7753{
e2c953b6 7754 unsigned int reg1;
35068b43
RK
7755 int offset1;
7756
7757 /* Extract an offset (if used) from the first addr. */
7758 if (GET_CODE (addr1) == PLUS)
7759 {
7760 /* If not a REG, return zero. */
7761 if (GET_CODE (XEXP (addr1, 0)) != REG)
7762 return 0;
7763 else
7764 {
7765 reg1 = REGNO (XEXP (addr1, 0));
7766 /* The offset must be constant! */
7767 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7768 return 0;
7769 offset1 = INTVAL (XEXP (addr1, 1));
7770 }
7771 }
7772 else if (GET_CODE (addr1) != REG)
7773 return 0;
7774 else
7775 {
7776 reg1 = REGNO (addr1);
7777 /* This was a simple (mem (reg)) expression. Offset is 0. */
7778 offset1 = 0;
7779 }
7780
a2369ed3
DJ
7781 /* Make sure the second address is a (mem (plus (reg) (const_int)))
7782 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
7783 register as addr1. */
984e25ac
DE
7784 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
7785 return 1;
35068b43
RK
7786 if (GET_CODE (addr2) != PLUS)
7787 return 0;
7788
7789 if (GET_CODE (XEXP (addr2, 0)) != REG
7790 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7791 return 0;
7792
7793 if (reg1 != REGNO (XEXP (addr2, 0)))
7794 return 0;
7795
7796 /* The offset for the second addr must be 8 more than the first addr. */
7797 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
7798 return 0;
7799
7800 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
7801 instructions. */
7802 return 1;
7803}
9878760c
RK
7804\f
7805/* Return the register class of a scratch register needed to copy IN into
7806 or out of a register in CLASS in MODE. If it can be done directly,
7807 NO_REGS is returned. */
7808
7809enum reg_class
a2369ed3
DJ
7810secondary_reload_class (enum reg_class class,
7811 enum machine_mode mode ATTRIBUTE_UNUSED, rtx in)
9878760c 7812{
5accd822 7813 int regno;
9878760c 7814
ab82a49f
AP
7815 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
7816#if TARGET_MACHO
7817 && MACHOPIC_INDIRECT
7818#endif
7819 ))
46fad5b7
DJ
7820 {
7821 /* We cannot copy a symbolic operand directly into anything
7822 other than BASE_REGS for TARGET_ELF. So indicate that a
7823 register from BASE_REGS is needed as an intermediate
7824 register.
7825
7826 On Darwin, pic addresses require a load from memory, which
7827 needs a base register. */
7828 if (class != BASE_REGS
7829 && (GET_CODE (in) == SYMBOL_REF
7830 || GET_CODE (in) == HIGH
7831 || GET_CODE (in) == LABEL_REF
7832 || GET_CODE (in) == CONST))
7833 return BASE_REGS;
7834 }
e7b7998a 7835
5accd822
DE
7836 if (GET_CODE (in) == REG)
7837 {
7838 regno = REGNO (in);
7839 if (regno >= FIRST_PSEUDO_REGISTER)
7840 {
7841 regno = true_regnum (in);
7842 if (regno >= FIRST_PSEUDO_REGISTER)
7843 regno = -1;
7844 }
7845 }
7846 else if (GET_CODE (in) == SUBREG)
7847 {
7848 regno = true_regnum (in);
7849 if (regno >= FIRST_PSEUDO_REGISTER)
7850 regno = -1;
7851 }
7852 else
7853 regno = -1;
7854
9878760c
RK
7855 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
7856 into anything. */
7857 if (class == GENERAL_REGS || class == BASE_REGS
7858 || (regno >= 0 && INT_REGNO_P (regno)))
7859 return NO_REGS;
7860
7861 /* Constants, memory, and FP registers can go into FP registers. */
7862 if ((regno == -1 || FP_REGNO_P (regno))
7863 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
7864 return NO_REGS;
7865
0ac081f6
AH
7866 /* Memory, and AltiVec registers can go into AltiVec registers. */
7867 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
7868 && class == ALTIVEC_REGS)
7869 return NO_REGS;
7870
9878760c
RK
7871 /* We can copy among the CR registers. */
7872 if ((class == CR_REGS || class == CR0_REGS)
7873 && regno >= 0 && CR_REGNO_P (regno))
7874 return NO_REGS;
7875
7876 /* Otherwise, we need GENERAL_REGS. */
7877 return GENERAL_REGS;
7878}
7879\f
7880/* Given a comparison operation, return the bit number in CCR to test. We
7881 know this is a valid comparison.
7882
7883 SCC_P is 1 if this is for an scc. That means that %D will have been
7884 used instead of %C, so the bits will be in different places.
7885
b4ac57ab 7886 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
7887
7888int
a2369ed3 7889ccr_bit (rtx op, int scc_p)
9878760c
RK
7890{
7891 enum rtx_code code = GET_CODE (op);
7892 enum machine_mode cc_mode;
7893 int cc_regnum;
7894 int base_bit;
9ebbca7d 7895 rtx reg;
9878760c
RK
7896
7897 if (GET_RTX_CLASS (code) != '<')
7898 return -1;
7899
9ebbca7d
GK
7900 reg = XEXP (op, 0);
7901
7902 if (GET_CODE (reg) != REG
7903 || ! CR_REGNO_P (REGNO (reg)))
7904 abort ();
7905
7906 cc_mode = GET_MODE (reg);
7907 cc_regnum = REGNO (reg);
7908 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 7909
39a10a29 7910 validate_condition_mode (code, cc_mode);
c5defebb 7911
b7053a3f
GK
7912 /* When generating a sCOND operation, only positive conditions are
7913 allowed. */
7914 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
7915 && code != GTU && code != LTU)
7916 abort ();
7917
9878760c
RK
7918 switch (code)
7919 {
7920 case NE:
993f19a8
AH
7921 if (TARGET_E500 && !TARGET_FPRS
7922 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 7923 return base_bit + 1;
9878760c
RK
7924 return scc_p ? base_bit + 3 : base_bit + 2;
7925 case EQ:
993f19a8
AH
7926 if (TARGET_E500 && !TARGET_FPRS
7927 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 7928 return base_bit + 1;
9878760c 7929 return base_bit + 2;
1c882ea4 7930 case GT: case GTU: case UNLE:
9878760c 7931 return base_bit + 1;
1c882ea4 7932 case LT: case LTU: case UNGE:
9878760c 7933 return base_bit;
1c882ea4
GK
7934 case ORDERED: case UNORDERED:
7935 return base_bit + 3;
9878760c
RK
7936
7937 case GE: case GEU:
39a10a29 7938 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
7939 unordered position. So test that bit. For integer, this is ! LT
7940 unless this is an scc insn. */
39a10a29 7941 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
7942
7943 case LE: case LEU:
39a10a29 7944 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 7945
9878760c
RK
7946 default:
7947 abort ();
7948 }
7949}
1ff7789b 7950\f
8d30c4ee 7951/* Return the GOT register. */
1ff7789b
MM
7952
7953struct rtx_def *
a2369ed3 7954rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 7955{
a4f6c312
SS
7956 /* The second flow pass currently (June 1999) can't update
7957 regs_ever_live without disturbing other parts of the compiler, so
7958 update it here to make the prolog/epilogue code happy. */
1db02437
FS
7959 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
7960 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 7961
8d30c4ee 7962 current_function_uses_pic_offset_table = 1;
3cb999d8 7963
1ff7789b
MM
7964 return pic_offset_table_rtx;
7965}
a7df97e6 7966\f
e2500fed
GK
7967/* Function to init struct machine_function.
7968 This will be called, via a pointer variable,
7969 from push_function_context. */
a7df97e6 7970
e2500fed 7971static struct machine_function *
863d938c 7972rs6000_init_machine_status (void)
a7df97e6 7973{
e2500fed 7974 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 7975}
9878760c 7976\f
0ba1b2ff
AM
7977/* These macros test for integers and extract the low-order bits. */
7978#define INT_P(X) \
7979((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
7980 && GET_MODE (X) == VOIDmode)
7981
7982#define INT_LOWPART(X) \
7983 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
7984
7985int
a2369ed3 7986extract_MB (rtx op)
0ba1b2ff
AM
7987{
7988 int i;
7989 unsigned long val = INT_LOWPART (op);
7990
7991 /* If the high bit is zero, the value is the first 1 bit we find
7992 from the left. */
7993 if ((val & 0x80000000) == 0)
7994 {
7995 if ((val & 0xffffffff) == 0)
7996 abort ();
7997
7998 i = 1;
7999 while (((val <<= 1) & 0x80000000) == 0)
8000 ++i;
8001 return i;
8002 }
8003
8004 /* If the high bit is set and the low bit is not, or the mask is all
8005 1's, the value is zero. */
8006 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8007 return 0;
8008
8009 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8010 from the right. */
8011 i = 31;
8012 while (((val >>= 1) & 1) != 0)
8013 --i;
8014
8015 return i;
8016}
8017
8018int
a2369ed3 8019extract_ME (rtx op)
0ba1b2ff
AM
8020{
8021 int i;
8022 unsigned long val = INT_LOWPART (op);
8023
8024 /* If the low bit is zero, the value is the first 1 bit we find from
8025 the right. */
8026 if ((val & 1) == 0)
8027 {
8028 if ((val & 0xffffffff) == 0)
8029 abort ();
8030
8031 i = 30;
8032 while (((val >>= 1) & 1) == 0)
8033 --i;
8034
8035 return i;
8036 }
8037
8038 /* If the low bit is set and the high bit is not, or the mask is all
8039 1's, the value is 31. */
8040 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8041 return 31;
8042
8043 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8044 from the left. */
8045 i = 0;
8046 while (((val <<= 1) & 0x80000000) != 0)
8047 ++i;
8048
8049 return i;
8050}
8051
c4501e62
JJ
8052/* Locate some local-dynamic symbol still in use by this function
8053 so that we can print its name in some tls_ld pattern. */
8054
8055static const char *
863d938c 8056rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8057{
8058 rtx insn;
8059
8060 if (cfun->machine->some_ld_name)
8061 return cfun->machine->some_ld_name;
8062
8063 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8064 if (INSN_P (insn)
8065 && for_each_rtx (&PATTERN (insn),
8066 rs6000_get_some_local_dynamic_name_1, 0))
8067 return cfun->machine->some_ld_name;
8068
8069 abort ();
8070}
8071
8072/* Helper function for rs6000_get_some_local_dynamic_name. */
8073
8074static int
a2369ed3 8075rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8076{
8077 rtx x = *px;
8078
8079 if (GET_CODE (x) == SYMBOL_REF)
8080 {
8081 const char *str = XSTR (x, 0);
8082 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8083 {
8084 cfun->machine->some_ld_name = str;
8085 return 1;
8086 }
8087 }
8088
8089 return 0;
8090}
8091
9878760c
RK
8092/* Print an operand. Recognize special options, documented below. */
8093
38c1f2d7 8094#if TARGET_ELF
d9407988 8095#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8096#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8097#else
8098#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8099#define SMALL_DATA_REG 0
ba5e43aa
MM
8100#endif
8101
9878760c 8102void
a2369ed3 8103print_operand (FILE *file, rtx x, int code)
9878760c
RK
8104{
8105 int i;
a260abc9 8106 HOST_WIDE_INT val;
0ba1b2ff 8107 unsigned HOST_WIDE_INT uval;
9878760c
RK
8108
8109 switch (code)
8110 {
a8b3aeda 8111 case '.':
a85d226b
RK
8112 /* Write out an instruction after the call which may be replaced
8113 with glue code by the loader. This depends on the AIX version. */
8114 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8115 return;
8116
81eace42
GK
8117 /* %a is output_address. */
8118
9854d9ed
RK
8119 case 'A':
8120 /* If X is a constant integer whose low-order 5 bits are zero,
8121 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8122 in the AIX assembler where "sri" with a zero shift count
20e26713 8123 writes a trash instruction. */
9854d9ed 8124 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8125 putc ('l', file);
9854d9ed 8126 else
76229ac8 8127 putc ('r', file);
9854d9ed
RK
8128 return;
8129
8130 case 'b':
e2c953b6
DE
8131 /* If constant, low-order 16 bits of constant, unsigned.
8132 Otherwise, write normally. */
8133 if (INT_P (x))
8134 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8135 else
8136 print_operand (file, x, 0);
cad12a8d
RK
8137 return;
8138
a260abc9
DE
8139 case 'B':
8140 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8141 for 64-bit mask direction. */
296b8152 8142 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8143 return;
a260abc9 8144
81eace42
GK
8145 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8146 output_operand. */
8147
9854d9ed 8148 case 'E':
39a10a29 8149 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8150 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8151 output_operand_lossage ("invalid %%E value");
78fbdbf7 8152 else
39a10a29 8153 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8154 return;
9854d9ed
RK
8155
8156 case 'f':
8157 /* X is a CR register. Print the shift count needed to move it
8158 to the high-order four bits. */
8159 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8160 output_operand_lossage ("invalid %%f value");
8161 else
9ebbca7d 8162 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8163 return;
8164
8165 case 'F':
8166 /* Similar, but print the count for the rotate in the opposite
8167 direction. */
8168 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8169 output_operand_lossage ("invalid %%F value");
8170 else
9ebbca7d 8171 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8172 return;
8173
8174 case 'G':
8175 /* X is a constant integer. If it is negative, print "m",
43aa4e05 8176 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
8177 if (GET_CODE (x) != CONST_INT)
8178 output_operand_lossage ("invalid %%G value");
8179 else if (INTVAL (x) >= 0)
76229ac8 8180 putc ('z', file);
9854d9ed 8181 else
76229ac8 8182 putc ('m', file);
9854d9ed 8183 return;
e2c953b6 8184
9878760c 8185 case 'h':
a4f6c312
SS
8186 /* If constant, output low-order five bits. Otherwise, write
8187 normally. */
9878760c 8188 if (INT_P (x))
5f59ecb7 8189 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
8190 else
8191 print_operand (file, x, 0);
8192 return;
8193
64305719 8194 case 'H':
a4f6c312
SS
8195 /* If constant, output low-order six bits. Otherwise, write
8196 normally. */
64305719 8197 if (INT_P (x))
5f59ecb7 8198 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
8199 else
8200 print_operand (file, x, 0);
8201 return;
8202
9854d9ed
RK
8203 case 'I':
8204 /* Print `i' if this is a constant, else nothing. */
9878760c 8205 if (INT_P (x))
76229ac8 8206 putc ('i', file);
9878760c
RK
8207 return;
8208
9854d9ed
RK
8209 case 'j':
8210 /* Write the bit number in CCR for jump. */
8211 i = ccr_bit (x, 0);
8212 if (i == -1)
8213 output_operand_lossage ("invalid %%j code");
9878760c 8214 else
9854d9ed 8215 fprintf (file, "%d", i);
9878760c
RK
8216 return;
8217
9854d9ed
RK
8218 case 'J':
8219 /* Similar, but add one for shift count in rlinm for scc and pass
8220 scc flag to `ccr_bit'. */
8221 i = ccr_bit (x, 1);
8222 if (i == -1)
8223 output_operand_lossage ("invalid %%J code");
8224 else
a0466a68
RK
8225 /* If we want bit 31, write a shift count of zero, not 32. */
8226 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
8227 return;
8228
9854d9ed
RK
8229 case 'k':
8230 /* X must be a constant. Write the 1's complement of the
8231 constant. */
9878760c 8232 if (! INT_P (x))
9854d9ed 8233 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
8234 else
8235 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
8236 return;
8237
81eace42 8238 case 'K':
9ebbca7d
GK
8239 /* X must be a symbolic constant on ELF. Write an
8240 expression suitable for an 'addi' that adds in the low 16
8241 bits of the MEM. */
8242 if (GET_CODE (x) != CONST)
8243 {
8244 print_operand_address (file, x);
8245 fputs ("@l", file);
8246 }
8247 else
8248 {
8249 if (GET_CODE (XEXP (x, 0)) != PLUS
8250 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
8251 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
8252 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 8253 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
8254 print_operand_address (file, XEXP (XEXP (x, 0), 0));
8255 fputs ("@l", file);
ed8d2920
MM
8256 /* For GNU as, there must be a non-alphanumeric character
8257 between 'l' and the number. The '-' is added by
8258 print_operand() already. */
8259 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
8260 fputs ("+", file);
9ebbca7d
GK
8261 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
8262 }
81eace42
GK
8263 return;
8264
8265 /* %l is output_asm_label. */
9ebbca7d 8266
9854d9ed
RK
8267 case 'L':
8268 /* Write second word of DImode or DFmode reference. Works on register
8269 or non-indexed memory only. */
8270 if (GET_CODE (x) == REG)
5ebfb2ba 8271 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
8272 else if (GET_CODE (x) == MEM)
8273 {
8274 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 8275 we have already done it, we can just use an offset of word. */
9854d9ed
RK
8276 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8277 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
8278 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
8279 UNITS_PER_WORD));
9854d9ed 8280 else
d7624dc0
RK
8281 output_address (XEXP (adjust_address_nv (x, SImode,
8282 UNITS_PER_WORD),
8283 0));
ed8908e7 8284
ba5e43aa 8285 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8286 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8287 reg_names[SMALL_DATA_REG]);
9854d9ed 8288 }
9878760c 8289 return;
9854d9ed 8290
9878760c
RK
8291 case 'm':
8292 /* MB value for a mask operand. */
b1765bde 8293 if (! mask_operand (x, SImode))
9878760c
RK
8294 output_operand_lossage ("invalid %%m value");
8295
0ba1b2ff 8296 fprintf (file, "%d", extract_MB (x));
9878760c
RK
8297 return;
8298
8299 case 'M':
8300 /* ME value for a mask operand. */
b1765bde 8301 if (! mask_operand (x, SImode))
a260abc9 8302 output_operand_lossage ("invalid %%M value");
9878760c 8303
0ba1b2ff 8304 fprintf (file, "%d", extract_ME (x));
9878760c
RK
8305 return;
8306
81eace42
GK
8307 /* %n outputs the negative of its operand. */
8308
9878760c
RK
8309 case 'N':
8310 /* Write the number of elements in the vector times 4. */
8311 if (GET_CODE (x) != PARALLEL)
8312 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
8313 else
8314 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
8315 return;
8316
8317 case 'O':
8318 /* Similar, but subtract 1 first. */
8319 if (GET_CODE (x) != PARALLEL)
1427100a 8320 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
8321 else
8322 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
8323 return;
8324
9854d9ed
RK
8325 case 'p':
8326 /* X is a CONST_INT that is a power of two. Output the logarithm. */
8327 if (! INT_P (x)
2bfcf297 8328 || INT_LOWPART (x) < 0
9854d9ed
RK
8329 || (i = exact_log2 (INT_LOWPART (x))) < 0)
8330 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
8331 else
8332 fprintf (file, "%d", i);
9854d9ed
RK
8333 return;
8334
9878760c
RK
8335 case 'P':
8336 /* The operand must be an indirect memory reference. The result
a4f6c312 8337 is the register number. */
9878760c
RK
8338 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
8339 || REGNO (XEXP (x, 0)) >= 32)
8340 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
8341 else
8342 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
8343 return;
8344
dfbdccdb
GK
8345 case 'q':
8346 /* This outputs the logical code corresponding to a boolean
8347 expression. The expression may have one or both operands
39a10a29
GK
8348 negated (if one, only the first one). For condition register
8349 logical operations, it will also treat the negated
8350 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 8351 {
63bc1d05 8352 const char *const *t = 0;
dfbdccdb
GK
8353 const char *s;
8354 enum rtx_code code = GET_CODE (x);
8355 static const char * const tbl[3][3] = {
8356 { "and", "andc", "nor" },
8357 { "or", "orc", "nand" },
8358 { "xor", "eqv", "xor" } };
8359
8360 if (code == AND)
8361 t = tbl[0];
8362 else if (code == IOR)
8363 t = tbl[1];
8364 else if (code == XOR)
8365 t = tbl[2];
8366 else
8367 output_operand_lossage ("invalid %%q value");
8368
8369 if (GET_CODE (XEXP (x, 0)) != NOT)
8370 s = t[0];
8371 else
8372 {
8373 if (GET_CODE (XEXP (x, 1)) == NOT)
8374 s = t[2];
8375 else
8376 s = t[1];
8377 }
8378
8379 fputs (s, file);
8380 }
8381 return;
8382
2c4a9cff
DE
8383 case 'Q':
8384 if (TARGET_MFCRF)
8385 fputc (',',file);
8386 /* FALLTHRU */
8387 else
8388 return;
8389
9854d9ed
RK
8390 case 'R':
8391 /* X is a CR register. Print the mask for `mtcrf'. */
8392 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8393 output_operand_lossage ("invalid %%R value");
8394 else
9ebbca7d 8395 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 8396 return;
9854d9ed
RK
8397
8398 case 's':
8399 /* Low 5 bits of 32 - value */
8400 if (! INT_P (x))
8401 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
8402 else
8403 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 8404 return;
9854d9ed 8405
a260abc9 8406 case 'S':
0ba1b2ff 8407 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
8408 CONST_INT 32-bit mask is considered sign-extended so any
8409 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 8410 if (! mask64_operand (x, DImode))
a260abc9
DE
8411 output_operand_lossage ("invalid %%S value");
8412
0ba1b2ff 8413 uval = INT_LOWPART (x);
a260abc9 8414
0ba1b2ff 8415 if (uval & 1) /* Clear Left */
a260abc9 8416 {
f099d360
GK
8417#if HOST_BITS_PER_WIDE_INT > 64
8418 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
8419#endif
0ba1b2ff 8420 i = 64;
a260abc9 8421 }
0ba1b2ff 8422 else /* Clear Right */
a260abc9 8423 {
0ba1b2ff 8424 uval = ~uval;
f099d360
GK
8425#if HOST_BITS_PER_WIDE_INT > 64
8426 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
8427#endif
0ba1b2ff 8428 i = 63;
a260abc9 8429 }
0ba1b2ff
AM
8430 while (uval != 0)
8431 --i, uval >>= 1;
8432 if (i < 0)
8433 abort ();
8434 fprintf (file, "%d", i);
8435 return;
a260abc9 8436
a3170dc6
AH
8437 case 't':
8438 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
8439 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
8440 abort ();
8441
8442 /* Bit 3 is OV bit. */
8443 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
8444
8445 /* If we want bit 31, write a shift count of zero, not 32. */
8446 fprintf (file, "%d", i == 31 ? 0 : i + 1);
8447 return;
8448
cccf3bdc
DE
8449 case 'T':
8450 /* Print the symbolic name of a branch target register. */
8451 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
8452 && REGNO (x) != COUNT_REGISTER_REGNUM))
8453 output_operand_lossage ("invalid %%T value");
e2c953b6 8454 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
8455 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
8456 else
8457 fputs ("ctr", file);
8458 return;
8459
9854d9ed 8460 case 'u':
802a0058 8461 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
8462 if (! INT_P (x))
8463 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
8464 else
8465 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
8466 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
8467 return;
8468
802a0058
MM
8469 case 'v':
8470 /* High-order 16 bits of constant for use in signed operand. */
8471 if (! INT_P (x))
8472 output_operand_lossage ("invalid %%v value");
e2c953b6 8473 else
134c32f6
DE
8474 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
8475 (INT_LOWPART (x) >> 16) & 0xffff);
8476 return;
802a0058 8477
9854d9ed
RK
8478 case 'U':
8479 /* Print `u' if this has an auto-increment or auto-decrement. */
8480 if (GET_CODE (x) == MEM
8481 && (GET_CODE (XEXP (x, 0)) == PRE_INC
8482 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 8483 putc ('u', file);
9854d9ed 8484 return;
9878760c 8485
e0cd0770
JC
8486 case 'V':
8487 /* Print the trap code for this operand. */
8488 switch (GET_CODE (x))
8489 {
8490 case EQ:
8491 fputs ("eq", file); /* 4 */
8492 break;
8493 case NE:
8494 fputs ("ne", file); /* 24 */
8495 break;
8496 case LT:
8497 fputs ("lt", file); /* 16 */
8498 break;
8499 case LE:
8500 fputs ("le", file); /* 20 */
8501 break;
8502 case GT:
8503 fputs ("gt", file); /* 8 */
8504 break;
8505 case GE:
8506 fputs ("ge", file); /* 12 */
8507 break;
8508 case LTU:
8509 fputs ("llt", file); /* 2 */
8510 break;
8511 case LEU:
8512 fputs ("lle", file); /* 6 */
8513 break;
8514 case GTU:
8515 fputs ("lgt", file); /* 1 */
8516 break;
8517 case GEU:
8518 fputs ("lge", file); /* 5 */
8519 break;
8520 default:
8521 abort ();
8522 }
8523 break;
8524
9854d9ed
RK
8525 case 'w':
8526 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
8527 normally. */
8528 if (INT_P (x))
5f59ecb7
DE
8529 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
8530 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
8531 else
8532 print_operand (file, x, 0);
9878760c
RK
8533 return;
8534
9854d9ed 8535 case 'W':
e2c953b6 8536 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
8537 val = (GET_CODE (x) == CONST_INT
8538 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
8539
8540 if (val < 0)
8541 i = -1;
9854d9ed 8542 else
e2c953b6
DE
8543 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
8544 if ((val <<= 1) < 0)
8545 break;
8546
8547#if HOST_BITS_PER_WIDE_INT == 32
8548 if (GET_CODE (x) == CONST_INT && i >= 0)
8549 i += 32; /* zero-extend high-part was all 0's */
8550 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
8551 {
8552 val = CONST_DOUBLE_LOW (x);
8553
8554 if (val == 0)
a4f6c312 8555 abort ();
e2c953b6
DE
8556 else if (val < 0)
8557 --i;
8558 else
8559 for ( ; i < 64; i++)
8560 if ((val <<= 1) < 0)
8561 break;
8562 }
8563#endif
8564
8565 fprintf (file, "%d", i + 1);
9854d9ed 8566 return;
9878760c 8567
9854d9ed
RK
8568 case 'X':
8569 if (GET_CODE (x) == MEM
4d588c14 8570 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 8571 putc ('x', file);
9854d9ed 8572 return;
9878760c 8573
9854d9ed
RK
8574 case 'Y':
8575 /* Like 'L', for third word of TImode */
8576 if (GET_CODE (x) == REG)
5ebfb2ba 8577 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 8578 else if (GET_CODE (x) == MEM)
9878760c 8579 {
9854d9ed
RK
8580 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8581 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8582 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 8583 else
d7624dc0 8584 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 8585 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8586 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8587 reg_names[SMALL_DATA_REG]);
9878760c
RK
8588 }
8589 return;
9854d9ed 8590
9878760c 8591 case 'z':
b4ac57ab
RS
8592 /* X is a SYMBOL_REF. Write out the name preceded by a
8593 period and without any trailing data in brackets. Used for function
4d30c363
MM
8594 names. If we are configured for System V (or the embedded ABI) on
8595 the PowerPC, do not emit the period, since those systems do not use
8596 TOCs and the like. */
9878760c
RK
8597 if (GET_CODE (x) != SYMBOL_REF)
8598 abort ();
8599
b6c9286a
MM
8600 if (XSTR (x, 0)[0] != '.')
8601 {
8602 switch (DEFAULT_ABI)
8603 {
8604 default:
8605 abort ();
8606
8607 case ABI_AIX:
8608 putc ('.', file);
8609 break;
8610
8611 case ABI_V4:
ee890fe2 8612 case ABI_DARWIN:
b6c9286a 8613 break;
b6c9286a
MM
8614 }
8615 }
9739c90c
JJ
8616 if (TARGET_AIX)
8617 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
8618 else
8619 assemble_name (file, XSTR (x, 0));
9878760c
RK
8620 return;
8621
9854d9ed
RK
8622 case 'Z':
8623 /* Like 'L', for last word of TImode. */
8624 if (GET_CODE (x) == REG)
5ebfb2ba 8625 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
8626 else if (GET_CODE (x) == MEM)
8627 {
8628 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8629 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8630 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 8631 else
d7624dc0 8632 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 8633 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8634 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8635 reg_names[SMALL_DATA_REG]);
9854d9ed 8636 }
5c23c401 8637 return;
0ac081f6 8638
a3170dc6 8639 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
8640 case 'y':
8641 {
8642 rtx tmp;
8643
8644 if (GET_CODE (x) != MEM)
8645 abort ();
8646
8647 tmp = XEXP (x, 0);
8648
993f19a8 8649 if (TARGET_E500)
a3170dc6
AH
8650 {
8651 /* Handle [reg]. */
8652 if (GET_CODE (tmp) == REG)
8653 {
8654 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
8655 break;
8656 }
8657 /* Handle [reg+UIMM]. */
8658 else if (GET_CODE (tmp) == PLUS &&
8659 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
8660 {
8661 int x;
8662
8663 if (GET_CODE (XEXP (tmp, 0)) != REG)
8664 abort ();
8665
8666 x = INTVAL (XEXP (tmp, 1));
8667 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
8668 break;
8669 }
8670
8671 /* Fall through. Must be [reg+reg]. */
8672 }
0ac081f6 8673 if (GET_CODE (tmp) == REG)
c62f2db5 8674 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
8675 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
8676 {
8677 if (REGNO (XEXP (tmp, 0)) == 0)
8678 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
8679 reg_names[ REGNO (XEXP (tmp, 0)) ]);
8680 else
8681 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
8682 reg_names[ REGNO (XEXP (tmp, 1)) ]);
8683 }
8684 else
8685 abort ();
8686 break;
8687 }
9854d9ed 8688
9878760c
RK
8689 case 0:
8690 if (GET_CODE (x) == REG)
8691 fprintf (file, "%s", reg_names[REGNO (x)]);
8692 else if (GET_CODE (x) == MEM)
8693 {
8694 /* We need to handle PRE_INC and PRE_DEC here, since we need to
8695 know the width from the mode. */
8696 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
8697 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
8698 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8699 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
8700 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
8701 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8702 else
a54d04b7 8703 output_address (XEXP (x, 0));
9878760c
RK
8704 }
8705 else
a54d04b7 8706 output_addr_const (file, x);
a85d226b 8707 return;
9878760c 8708
c4501e62
JJ
8709 case '&':
8710 assemble_name (file, rs6000_get_some_local_dynamic_name ());
8711 return;
8712
9878760c
RK
8713 default:
8714 output_operand_lossage ("invalid %%xn code");
8715 }
8716}
8717\f
8718/* Print the address of an operand. */
8719
8720void
a2369ed3 8721print_operand_address (FILE *file, rtx x)
9878760c
RK
8722{
8723 if (GET_CODE (x) == REG)
4697a36c 8724 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
8725 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
8726 || GET_CODE (x) == LABEL_REF)
9878760c
RK
8727 {
8728 output_addr_const (file, x);
ba5e43aa 8729 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8730 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8731 reg_names[SMALL_DATA_REG]);
9ebbca7d 8732 else if (TARGET_TOC)
a4f6c312 8733 abort ();
9878760c
RK
8734 }
8735 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
8736 {
8737 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
8738 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
8739 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 8740 else
4697a36c
MM
8741 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
8742 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
8743 }
8744 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
8745 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
8746 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
8747#if TARGET_ELF
8748 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8749 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
8750 {
8751 output_addr_const (file, XEXP (x, 1));
8752 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8753 }
c859cda6
DJ
8754#endif
8755#if TARGET_MACHO
8756 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8757 && CONSTANT_P (XEXP (x, 1)))
8758 {
8759 fprintf (file, "lo16(");
8760 output_addr_const (file, XEXP (x, 1));
8761 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8762 }
3cb999d8 8763#endif
4d588c14 8764 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 8765 {
2bfcf297 8766 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 8767 {
2bfcf297
DB
8768 rtx contains_minus = XEXP (x, 1);
8769 rtx minus, symref;
8770 const char *name;
9ebbca7d
GK
8771
8772 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 8773 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
8774 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
8775 contains_minus = XEXP (contains_minus, 0);
8776
2bfcf297
DB
8777 minus = XEXP (contains_minus, 0);
8778 symref = XEXP (minus, 0);
8779 XEXP (contains_minus, 0) = symref;
8780 if (TARGET_ELF)
8781 {
8782 char *newname;
8783
8784 name = XSTR (symref, 0);
8785 newname = alloca (strlen (name) + sizeof ("@toc"));
8786 strcpy (newname, name);
8787 strcat (newname, "@toc");
8788 XSTR (symref, 0) = newname;
8789 }
8790 output_addr_const (file, XEXP (x, 1));
8791 if (TARGET_ELF)
8792 XSTR (symref, 0) = name;
9ebbca7d
GK
8793 XEXP (contains_minus, 0) = minus;
8794 }
8795 else
8796 output_addr_const (file, XEXP (x, 1));
8797
8798 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
8799 }
9878760c
RK
8800 else
8801 abort ();
8802}
8803\f
88cad84b 8804/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
8805 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
8806 is defined. It also needs to handle DI-mode objects on 64-bit
8807 targets. */
8808
8809static bool
a2369ed3 8810rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
8811{
8812#ifdef RELOCATABLE_NEEDS_FIXUP
8813 /* Special handling for SI values. */
8814 if (size == 4 && aligned_p)
8815 {
a2369ed3 8816 extern int in_toc_section (void);
301d03af
RS
8817 static int recurse = 0;
8818
8819 /* For -mrelocatable, we mark all addresses that need to be fixed up
8820 in the .fixup section. */
8821 if (TARGET_RELOCATABLE
8822 && !in_toc_section ()
8823 && !in_text_section ()
8824 && !recurse
8825 && GET_CODE (x) != CONST_INT
8826 && GET_CODE (x) != CONST_DOUBLE
8827 && CONSTANT_P (x))
8828 {
8829 char buf[256];
8830
8831 recurse = 1;
8832 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
8833 fixuplabelno++;
8834 ASM_OUTPUT_LABEL (asm_out_file, buf);
8835 fprintf (asm_out_file, "\t.long\t(");
8836 output_addr_const (asm_out_file, x);
8837 fprintf (asm_out_file, ")@fixup\n");
8838 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
8839 ASM_OUTPUT_ALIGN (asm_out_file, 2);
8840 fprintf (asm_out_file, "\t.long\t");
8841 assemble_name (asm_out_file, buf);
8842 fprintf (asm_out_file, "\n\t.previous\n");
8843 recurse = 0;
8844 return true;
8845 }
8846 /* Remove initial .'s to turn a -mcall-aixdesc function
8847 address into the address of the descriptor, not the function
8848 itself. */
8849 else if (GET_CODE (x) == SYMBOL_REF
8850 && XSTR (x, 0)[0] == '.'
8851 && DEFAULT_ABI == ABI_AIX)
8852 {
8853 const char *name = XSTR (x, 0);
8854 while (*name == '.')
8855 name++;
8856
8857 fprintf (asm_out_file, "\t.long\t%s\n", name);
8858 return true;
8859 }
8860 }
8861#endif /* RELOCATABLE_NEEDS_FIXUP */
8862 return default_assemble_integer (x, size, aligned_p);
8863}
93638d7a
AM
8864
8865#ifdef HAVE_GAS_HIDDEN
8866/* Emit an assembler directive to set symbol visibility for DECL to
8867 VISIBILITY_TYPE. */
8868
5add3202 8869static void
a2369ed3 8870rs6000_assemble_visibility (tree decl, int vis)
93638d7a 8871{
93638d7a
AM
8872 /* Functions need to have their entry point symbol visibility set as
8873 well as their descriptor symbol visibility. */
8874 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
8875 {
25fdb4dc
RH
8876 static const char * const visibility_types[] = {
8877 NULL, "internal", "hidden", "protected"
8878 };
8879
8880 const char *name, *type;
93638d7a
AM
8881
8882 name = ((* targetm.strip_name_encoding)
8883 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 8884 type = visibility_types[vis];
93638d7a 8885
25fdb4dc
RH
8886 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
8887 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 8888 }
25fdb4dc
RH
8889 else
8890 default_assemble_visibility (decl, vis);
93638d7a
AM
8891}
8892#endif
301d03af 8893\f
39a10a29 8894enum rtx_code
a2369ed3 8895rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
8896{
8897 /* Reversal of FP compares takes care -- an ordered compare
8898 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
8899 if (mode == CCFPmode
8900 && (!flag_finite_math_only
8901 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
8902 || code == UNEQ || code == LTGT))
bab6226b 8903 return reverse_condition_maybe_unordered (code);
39a10a29 8904 else
bab6226b 8905 return reverse_condition (code);
39a10a29
GK
8906}
8907
39a10a29
GK
8908/* Generate a compare for CODE. Return a brand-new rtx that
8909 represents the result of the compare. */
a4f6c312 8910
39a10a29 8911static rtx
a2369ed3 8912rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
8913{
8914 enum machine_mode comp_mode;
8915 rtx compare_result;
8916
8917 if (rs6000_compare_fp_p)
8918 comp_mode = CCFPmode;
8919 else if (code == GTU || code == LTU
8920 || code == GEU || code == LEU)
8921 comp_mode = CCUNSmode;
8922 else
8923 comp_mode = CCmode;
8924
8925 /* First, the compare. */
8926 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
8927
8928 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
8929 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
8930 && rs6000_compare_fp_p)
a3170dc6
AH
8931 {
8932 rtx cmp, or1, or2, or_result, compare_result2;
8933
8934 switch (code)
8935 {
8936 case EQ:
8937 case UNEQ:
8938 case NE:
8939 case LTGT:
bc9ec0e0 8940 cmp = flag_finite_math_only
a3170dc6
AH
8941 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
8942 rs6000_compare_op1)
8943 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
8944 rs6000_compare_op1);
8945 break;
8946 case GT:
8947 case GTU:
8948 case UNGT:
8949 case UNGE:
8950 case GE:
8951 case GEU:
bc9ec0e0 8952 cmp = flag_finite_math_only
a3170dc6
AH
8953 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
8954 rs6000_compare_op1)
8955 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
8956 rs6000_compare_op1);
8957 break;
8958 case LT:
8959 case LTU:
8960 case UNLT:
8961 case UNLE:
8962 case LE:
8963 case LEU:
bc9ec0e0 8964 cmp = flag_finite_math_only
a3170dc6
AH
8965 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
8966 rs6000_compare_op1)
8967 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
8968 rs6000_compare_op1);
8969 break;
8970 default:
8971 abort ();
8972 }
8973
8974 /* Synthesize LE and GE from LT/GT || EQ. */
8975 if (code == LE || code == GE || code == LEU || code == GEU)
8976 {
8977 /* Synthesize GE/LE frome GT/LT || EQ. */
8978
8979 emit_insn (cmp);
8980
8981 switch (code)
8982 {
8983 case LE: code = LT; break;
8984 case GE: code = GT; break;
8985 case LEU: code = LT; break;
8986 case GEU: code = GT; break;
8987 default: abort ();
8988 }
8989
8990 or1 = gen_reg_rtx (SImode);
8991 or2 = gen_reg_rtx (SImode);
8992 or_result = gen_reg_rtx (CCEQmode);
8993 compare_result2 = gen_reg_rtx (CCFPmode);
8994
8995 /* Do the EQ. */
bc9ec0e0 8996 cmp = flag_finite_math_only
a3170dc6
AH
8997 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
8998 rs6000_compare_op1)
8999 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9000 rs6000_compare_op1);
9001 emit_insn (cmp);
9002
9003 /* The MC8540 FP compare instructions set the CR bits
9004 differently than other PPC compare instructions. For
9005 that matter, there is no generic test instruction, but a
9006 testgt, testlt, and testeq. For a true condition, bit 2
9007 is set (x1xx) in the CR. Following the traditional CR
9008 values:
9009
9010 LT GT EQ OV
9011 bit3 bit2 bit1 bit0
9012
9013 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9014 look in the GT bits for the branch instructions.
a3170dc6
AH
9015 However, we must be careful to emit correct RTL in
9016 the meantime, so optimizations don't get confused. */
9017
9018 or1 = gen_rtx (NE, SImode, compare_result, const0_rtx);
9019 or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx);
9020
9021 /* OR them together. */
9022 cmp = gen_rtx_SET (VOIDmode, or_result,
9023 gen_rtx_COMPARE (CCEQmode,
9024 gen_rtx_IOR (SImode, or1, or2),
9025 const_true_rtx));
9026 compare_result = or_result;
9027 code = EQ;
9028 }
9029 else
9030 {
9031 /* We only care about 1 bit (x1xx), so map everything to NE to
9032 maintain rtl sanity. We'll get to the right bit (x1xx) at
9033 code output time. */
9034 if (code == NE || code == LTGT)
9035 /* Do the inverse here because we have no cmpne
9036 instruction. We use the cmpeq instruction and expect
9037 to get a 0 instead. */
9038 code = EQ;
9039 else
9040 code = NE;
9041 }
9042
9043 emit_insn (cmp);
9044 }
9045 else
9046 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9047 gen_rtx_COMPARE (comp_mode,
9048 rs6000_compare_op0,
9049 rs6000_compare_op1)));
39a10a29 9050
ca5adc63 9051 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9052 under flag_finite_math_only we don't bother. */
39a10a29 9053 if (rs6000_compare_fp_p
bc9ec0e0 9054 && ! flag_finite_math_only
993f19a8 9055 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9056 && (code == LE || code == GE
9057 || code == UNEQ || code == LTGT
9058 || code == UNGT || code == UNLT))
9059 {
9060 enum rtx_code or1, or2;
9061 rtx or1_rtx, or2_rtx, compare2_rtx;
9062 rtx or_result = gen_reg_rtx (CCEQmode);
9063
9064 switch (code)
9065 {
9066 case LE: or1 = LT; or2 = EQ; break;
9067 case GE: or1 = GT; or2 = EQ; break;
9068 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9069 case LTGT: or1 = LT; or2 = GT; break;
9070 case UNGT: or1 = UNORDERED; or2 = GT; break;
9071 case UNLT: or1 = UNORDERED; or2 = LT; break;
9072 default: abort ();
9073 }
9074 validate_condition_mode (or1, comp_mode);
9075 validate_condition_mode (or2, comp_mode);
9076 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
9077 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
9078 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9079 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9080 const_true_rtx);
9081 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9082
9083 compare_result = or_result;
9084 code = EQ;
9085 }
9086
9087 validate_condition_mode (code, GET_MODE (compare_result));
9088
9089 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
9090}
9091
9092
9093/* Emit the RTL for an sCOND pattern. */
9094
9095void
a2369ed3 9096rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9097{
9098 rtx condition_rtx;
9099 enum machine_mode op_mode;
b7053a3f 9100 enum rtx_code cond_code;
39a10a29
GK
9101
9102 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9103 cond_code = GET_CODE (condition_rtx);
9104
9105 if (cond_code == NE
9106 || cond_code == GE || cond_code == LE
9107 || cond_code == GEU || cond_code == LEU
9108 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9109 {
9110 rtx not_result = gen_reg_rtx (CCEQmode);
9111 rtx not_op, rev_cond_rtx;
9112 enum machine_mode cc_mode;
9113
9114 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9115
9116 rev_cond_rtx = gen_rtx (rs6000_reverse_condition (cc_mode, cond_code),
9117 SImode, XEXP (condition_rtx, 0), const0_rtx);
9118 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9119 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9120 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9121 }
39a10a29
GK
9122
9123 op_mode = GET_MODE (rs6000_compare_op0);
9124 if (op_mode == VOIDmode)
9125 op_mode = GET_MODE (rs6000_compare_op1);
9126
9127 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9128 {
9129 PUT_MODE (condition_rtx, DImode);
9130 convert_move (result, condition_rtx, 0);
9131 }
9132 else
9133 {
9134 PUT_MODE (condition_rtx, SImode);
9135 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9136 }
9137}
9138
39a10a29
GK
9139/* Emit a branch of kind CODE to location LOC. */
9140
9141void
a2369ed3 9142rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
9143{
9144 rtx condition_rtx, loc_ref;
9145
9146 condition_rtx = rs6000_generate_compare (code);
9147 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9148 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9149 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9150 loc_ref, pc_rtx)));
9151}
9152
12a4e8c5
GK
9153/* Return the string to output a conditional branch to LABEL, which is
9154 the operand number of the label, or -1 if the branch is really a
9155 conditional return.
9156
9157 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9158 condition code register and its mode specifies what kind of
9159 comparison we made.
9160
a0ab749a 9161 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9162
9163 INSN is the insn. */
9164
9165char *
a2369ed3 9166output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
9167{
9168 static char string[64];
9169 enum rtx_code code = GET_CODE (op);
9170 rtx cc_reg = XEXP (op, 0);
9171 enum machine_mode mode = GET_MODE (cc_reg);
9172 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 9173 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
9174 int really_reversed = reversed ^ need_longbranch;
9175 char *s = string;
9176 const char *ccode;
9177 const char *pred;
9178 rtx note;
9179
39a10a29
GK
9180 validate_condition_mode (code, mode);
9181
9182 /* Work out which way this really branches. We could use
9183 reverse_condition_maybe_unordered here always but this
9184 makes the resulting assembler clearer. */
12a4e8c5 9185 if (really_reversed)
de40e1df
DJ
9186 {
9187 /* Reversal of FP compares takes care -- an ordered compare
9188 becomes an unordered compare and vice versa. */
9189 if (mode == CCFPmode)
9190 code = reverse_condition_maybe_unordered (code);
9191 else
9192 code = reverse_condition (code);
9193 }
12a4e8c5 9194
993f19a8 9195 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
9196 {
9197 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
9198 to the GT bit. */
9199 if (code == EQ)
9200 /* Opposite of GT. */
9201 code = UNLE;
9202 else if (code == NE)
9203 code = GT;
9204 else
9205 abort ();
9206 }
9207
39a10a29 9208 switch (code)
12a4e8c5
GK
9209 {
9210 /* Not all of these are actually distinct opcodes, but
9211 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
9212 case NE: case LTGT:
9213 ccode = "ne"; break;
9214 case EQ: case UNEQ:
9215 ccode = "eq"; break;
9216 case GE: case GEU:
9217 ccode = "ge"; break;
9218 case GT: case GTU: case UNGT:
9219 ccode = "gt"; break;
9220 case LE: case LEU:
9221 ccode = "le"; break;
9222 case LT: case LTU: case UNLT:
9223 ccode = "lt"; break;
12a4e8c5
GK
9224 case UNORDERED: ccode = "un"; break;
9225 case ORDERED: ccode = "nu"; break;
9226 case UNGE: ccode = "nl"; break;
9227 case UNLE: ccode = "ng"; break;
9228 default:
a4f6c312 9229 abort ();
12a4e8c5
GK
9230 }
9231
94a54f47
GK
9232 /* Maybe we have a guess as to how likely the branch is.
9233 The old mnemonics don't have a way to specify this information. */
f4857b9b 9234 pred = "";
12a4e8c5
GK
9235 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
9236 if (note != NULL_RTX)
9237 {
9238 /* PROB is the difference from 50%. */
9239 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
9240 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
9241
9242 /* Only hint for highly probable/improbable branches on newer
9243 cpus as static prediction overrides processor dynamic
9244 prediction. For older cpus we may as well always hint, but
9245 assume not taken for branches that are very close to 50% as a
9246 mispredicted taken branch is more expensive than a
9247 mispredicted not-taken branch. */
9248 if (always_hint
9249 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
9250 {
9251 if (abs (prob) > REG_BR_PROB_BASE / 20
9252 && ((prob > 0) ^ need_longbranch))
7f3d8013 9253 pred = "+";
f4857b9b
AM
9254 else
9255 pred = "-";
9256 }
12a4e8c5 9257 }
12a4e8c5
GK
9258
9259 if (label == NULL)
94a54f47 9260 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 9261 else
94a54f47 9262 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 9263
37c67319
GK
9264 /* We need to escape any '%' characters in the reg_names string.
9265 Assume they'd only be the first character... */
9266 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
9267 *s++ = '%';
94a54f47 9268 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
9269
9270 if (label != NULL)
9271 {
9272 /* If the branch distance was too far, we may have to use an
9273 unconditional branch to go the distance. */
9274 if (need_longbranch)
44518ddd 9275 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
9276 else
9277 s += sprintf (s, ",%s", label);
9278 }
9279
9280 return string;
9281}
50a0b056
GK
9282
9283/* Emit a conditional move: move TRUE_COND to DEST if OP of the
9284 operands of the last comparison is nonzero/true, FALSE_COND if it
9285 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 9286
50a0b056 9287int
a2369ed3 9288rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
9289{
9290 enum rtx_code code = GET_CODE (op);
9291 rtx op0 = rs6000_compare_op0;
9292 rtx op1 = rs6000_compare_op1;
9293 REAL_VALUE_TYPE c1;
3148ad6d
DJ
9294 enum machine_mode compare_mode = GET_MODE (op0);
9295 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
9296 rtx temp;
9297
3148ad6d 9298 /* These modes should always match. */
a3170dc6
AH
9299 if (GET_MODE (op1) != compare_mode
9300 /* In the isel case however, we can use a compare immediate, so
9301 op1 may be a small constant. */
9302 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 9303 return 0;
178c3eff 9304 if (GET_MODE (true_cond) != result_mode)
3148ad6d 9305 return 0;
178c3eff 9306 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
9307 return 0;
9308
50a0b056
GK
9309 /* First, work out if the hardware can do this at all, or
9310 if it's too slow... */
50a0b056 9311 if (! rs6000_compare_fp_p)
a3170dc6
AH
9312 {
9313 if (TARGET_ISEL)
9314 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
9315 return 0;
9316 }
50a0b056
GK
9317
9318 /* Eliminate half of the comparisons by switching operands, this
9319 makes the remaining code simpler. */
9320 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 9321 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
9322 {
9323 code = reverse_condition_maybe_unordered (code);
9324 temp = true_cond;
9325 true_cond = false_cond;
9326 false_cond = temp;
9327 }
9328
9329 /* UNEQ and LTGT take four instructions for a comparison with zero,
9330 it'll probably be faster to use a branch here too. */
bc9ec0e0 9331 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
9332 return 0;
9333
9334 if (GET_CODE (op1) == CONST_DOUBLE)
9335 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
9336
b6d08ca1 9337 /* We're going to try to implement comparisons by performing
50a0b056
GK
9338 a subtract, then comparing against zero. Unfortunately,
9339 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 9340 know that the operand is finite and the comparison
50a0b056 9341 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 9342 if (HONOR_INFINITIES (compare_mode)
50a0b056 9343 && code != GT && code != UNGE
045572c7 9344 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
9345 /* Constructs of the form (a OP b ? a : b) are safe. */
9346 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
9347 || (! rtx_equal_p (op0, true_cond)
9348 && ! rtx_equal_p (op1, true_cond))))
9349 return 0;
9350 /* At this point we know we can use fsel. */
9351
9352 /* Reduce the comparison to a comparison against zero. */
3148ad6d 9353 temp = gen_reg_rtx (compare_mode);
50a0b056 9354 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9355 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 9356 op0 = temp;
3148ad6d 9357 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
9358
9359 /* If we don't care about NaNs we can reduce some of the comparisons
9360 down to faster ones. */
bc9ec0e0 9361 if (! HONOR_NANS (compare_mode))
50a0b056
GK
9362 switch (code)
9363 {
9364 case GT:
9365 code = LE;
9366 temp = true_cond;
9367 true_cond = false_cond;
9368 false_cond = temp;
9369 break;
9370 case UNGE:
9371 code = GE;
9372 break;
9373 case UNEQ:
9374 code = EQ;
9375 break;
9376 default:
9377 break;
9378 }
9379
9380 /* Now, reduce everything down to a GE. */
9381 switch (code)
9382 {
9383 case GE:
9384 break;
9385
9386 case LE:
3148ad6d
DJ
9387 temp = gen_reg_rtx (compare_mode);
9388 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9389 op0 = temp;
9390 break;
9391
9392 case ORDERED:
3148ad6d
DJ
9393 temp = gen_reg_rtx (compare_mode);
9394 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
9395 op0 = temp;
9396 break;
9397
9398 case EQ:
3148ad6d 9399 temp = gen_reg_rtx (compare_mode);
50a0b056 9400 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
9401 gen_rtx_NEG (compare_mode,
9402 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
9403 op0 = temp;
9404 break;
9405
9406 case UNGE:
bc9ec0e0 9407 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 9408 temp = gen_reg_rtx (result_mode);
50a0b056 9409 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9410 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9411 gen_rtx_GE (VOIDmode,
9412 op0, op1),
9413 true_cond, false_cond)));
bc9ec0e0
GK
9414 false_cond = true_cond;
9415 true_cond = temp;
50a0b056 9416
3148ad6d
DJ
9417 temp = gen_reg_rtx (compare_mode);
9418 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9419 op0 = temp;
9420 break;
9421
9422 case GT:
bc9ec0e0 9423 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 9424 temp = gen_reg_rtx (result_mode);
50a0b056 9425 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9426 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9427 gen_rtx_GE (VOIDmode,
9428 op0, op1),
9429 true_cond, false_cond)));
bc9ec0e0
GK
9430 true_cond = false_cond;
9431 false_cond = temp;
50a0b056 9432
3148ad6d
DJ
9433 temp = gen_reg_rtx (compare_mode);
9434 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9435 op0 = temp;
9436 break;
9437
9438 default:
9439 abort ();
9440 }
9441
9442 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 9443 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9444 gen_rtx_GE (VOIDmode,
9445 op0, op1),
9446 true_cond, false_cond)));
9447 return 1;
9448}
9449
a3170dc6
AH
9450/* Same as above, but for ints (isel). */
9451
9452static int
a2369ed3 9453rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
9454{
9455 rtx condition_rtx, cr;
9456
9457 /* All isel implementations thus far are 32-bits. */
9458 if (GET_MODE (rs6000_compare_op0) != SImode)
9459 return 0;
9460
9461 /* We still have to do the compare, because isel doesn't do a
9462 compare, it just looks at the CRx bits set by a previous compare
9463 instruction. */
9464 condition_rtx = rs6000_generate_compare (GET_CODE (op));
9465 cr = XEXP (condition_rtx, 0);
9466
9467 if (GET_MODE (cr) == CCmode)
9468 emit_insn (gen_isel_signed (dest, condition_rtx,
9469 true_cond, false_cond, cr));
9470 else
9471 emit_insn (gen_isel_unsigned (dest, condition_rtx,
9472 true_cond, false_cond, cr));
9473
9474 return 1;
9475}
9476
9477const char *
a2369ed3 9478output_isel (rtx *operands)
a3170dc6
AH
9479{
9480 enum rtx_code code;
9481
9482 code = GET_CODE (operands[1]);
9483 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
9484 {
9485 PUT_CODE (operands[1], reverse_condition (code));
9486 return "isel %0,%3,%2,%j1";
9487 }
9488 else
9489 return "isel %0,%2,%3,%j1";
9490}
9491
50a0b056 9492void
a2369ed3 9493rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
9494{
9495 enum machine_mode mode = GET_MODE (op0);
5dc8d536 9496 enum rtx_code c;
50a0b056 9497 rtx target;
5dc8d536
AH
9498
9499 if (code == SMAX || code == SMIN)
9500 c = GE;
9501 else
9502 c = GEU;
9503
50a0b056 9504 if (code == SMAX || code == UMAX)
5dc8d536 9505 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
9506 op0, op1, mode, 0);
9507 else
5dc8d536 9508 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
9509 op1, op0, mode, 0);
9510 if (target == NULL_RTX)
9511 abort ();
9512 if (target != dest)
9513 emit_move_insn (dest, target);
9514}
46c07df8 9515
3a1f863f 9516/* Called by splitter for multireg moves.
46c07df8
HP
9517 Input:
9518 operands[0] : Destination of move
9519 operands[1] : Source of move
3a1f863f 9520
46c07df8 9521 Output:
3a1f863f
DE
9522 operands[2-n] : Destination slots
9523 operands[n-m] : Source slots
9524 where n = 2 + HARD_REGNO_NREGS (reg, GET_MODE (operands[0]))
9525 m = 2 + 2 * HARD_REGNO_NREGS (reg, GET_MODE (operands[0])) - 1
46c07df8
HP
9526
9527 Splits the move of operands[1] to operands[0].
9528 This is done, if GPRs are one of the operands. In this case
9529 a sequence of simple move insns has to be issued. The sequence of these
9530 move insns has to be done in correct order to avoid early clobber of the
9531 base register or destructive overlap of registers.
9532*/
9533
9534void
3a1f863f 9535rs6000_split_multireg_move (rtx *operands)
46c07df8 9536{
3a1f863f 9537 int nregs, reg, i, j, used_update = 0;
46c07df8 9538 enum machine_mode mode;
3a1f863f
DE
9539 rtx dst = operands[0];
9540 rtx src = operands[1];
9541 rtx insn = 0;
46c07df8
HP
9542
9543 /* Calculate number to move (2/4 for 32/64 bit mode). */
9544
9545 reg = REG_P (operands[0]) ? REGNO (operands[0]) : REGNO (operands[1]);
9546 mode = GET_MODE (operands[0]);
9547 nregs = HARD_REGNO_NREGS (reg, mode);
9548
9549 if (REG_P (operands[1])
9550 && REG_P (operands[0])
9551 && (REGNO (operands[1]) < REGNO (operands[0])))
9552 {
9553 /* Move register range backwards, if we have destructive overlap. */
9554
9555 j = nregs;
9556 for (i = 0; i < nregs; i++)
9557 {
9558 j--;
3a1f863f
DE
9559 operands[i+2] = operand_subword (operands[0], j, 0, mode);
9560 operands[i+2+nregs] =
46c07df8
HP
9561 operand_subword (operands[1], j, 0, mode);
9562 }
9563 }
9564 else
9565 {
9566 j = -1;
9567
9568 if (GET_CODE (operands[1]) == MEM)
9569 {
9570 rtx breg;
3a1f863f
DE
9571
9572 if (GET_CODE (XEXP (operands[1], 0)) == PRE_INC
9573 || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
9574 {
9575 rtx delta_rtx;
9576 breg = XEXP (XEXP (operands[1], 0), 0);
9577 delta_rtx = GET_CODE (XEXP (operands[1], 0)) == PRE_INC
9578 ? GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1])))
9579 : GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[1])));
9580 insn = emit_insn (TARGET_32BIT
9581 ? gen_addsi3 (breg, breg, delta_rtx)
9582 : gen_adddi3 (breg, breg, delta_rtx));
9583 src = gen_rtx_MEM (mode, breg);
9584 }
9585
9586 /* We have now address involving an base register only.
9587 If we use one of the registers to address memory,
9588 we have change that register last. */
9589
9590 breg = (GET_CODE (XEXP (src, 0)) == PLUS
9591 ? XEXP (XEXP (src, 0), 0)
9592 : XEXP (src, 0));
9593
9594 if (!REG_P (breg))
9595 abort();
9596
9597 if (REGNO (breg) >= REGNO (dst)
9598 && REGNO (breg) < REGNO (dst) + nregs)
9599 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
9600 }
9601
3a1f863f
DE
9602 if (GET_CODE (operands[0]) == MEM)
9603 {
9604 rtx breg;
9605
9606 if (GET_CODE (XEXP (operands[0], 0)) == PRE_INC
9607 || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
9608 {
9609 rtx delta_rtx;
9610 breg = XEXP (XEXP (operands[0], 0), 0);
9611 delta_rtx = GET_CODE (XEXP (operands[0], 0)) == PRE_INC
9612 ? GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0])))
9613 : GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[0])));
9614
9615 /* We have to update the breg before doing the store.
9616 Use store with update, if available. */
9617
9618 if (TARGET_UPDATE)
9619 {
9620 insn = emit_insn (TARGET_32BIT
9621 ? gen_movsi_update (breg, breg, delta_rtx,
9622 operand_subword (src, 0, 0, mode))
9623 : gen_movdi_update (breg, breg, delta_rtx,
9624 operand_subword (src, 0, 0, mode)));
9625 used_update = 1;
9626 }
9627 else
9628 insn = emit_insn (TARGET_32BIT
9629 ? gen_addsi3 (breg, breg, delta_rtx)
9630 : gen_adddi3 (breg, breg, delta_rtx));
9631 dst = gen_rtx_MEM (mode, breg);
9632 }
9633 }
9634
46c07df8 9635 for (i = 0; i < nregs; i++)
3a1f863f
DE
9636 {
9637 /* Calculate index to next subword. */
9638 ++j;
9639 if (j == nregs)
9640 j = 0;
46c07df8 9641
3a1f863f
DE
9642 operands[i+2] = operand_subword (dst, j, 0, mode);
9643 operands[i+2+nregs] = operand_subword (src, j, 0, mode);
46c07df8 9644
3a1f863f
DE
9645 if (j == 0 && used_update)
9646 {
9647 /* Already emited move of first word by
9648 store with update -> emit dead insn instead (r := r). */
9649 operands[i+2] = operands[i+2+nregs];
9650 }
9651 }
46c07df8
HP
9652 }
9653}
9654
12a4e8c5 9655\f
a4f6c312
SS
9656/* This page contains routines that are used to determine what the
9657 function prologue and epilogue code will do and write them out. */
9878760c 9658
a4f6c312
SS
9659/* Return the first fixed-point register that is required to be
9660 saved. 32 if none. */
9878760c
RK
9661
9662int
863d938c 9663first_reg_to_save (void)
9878760c
RK
9664{
9665 int first_reg;
9666
9667 /* Find lowest numbered live register. */
9668 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
9669 if (regs_ever_live[first_reg]
9670 && (! call_used_regs[first_reg]
1db02437 9671 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 9672 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 9673 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
9674 break;
9675
ee890fe2 9676#if TARGET_MACHO
93638d7a
AM
9677 if (flag_pic
9678 && current_function_uses_pic_offset_table
9679 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 9680 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
9681#endif
9682
9878760c
RK
9683 return first_reg;
9684}
9685
9686/* Similar, for FP regs. */
9687
9688int
863d938c 9689first_fp_reg_to_save (void)
9878760c
RK
9690{
9691 int first_reg;
9692
9693 /* Find lowest numbered live register. */
9694 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
9695 if (regs_ever_live[first_reg])
9696 break;
9697
9698 return first_reg;
9699}
00b960c7
AH
9700
9701/* Similar, for AltiVec regs. */
9702
9703static int
863d938c 9704first_altivec_reg_to_save (void)
00b960c7
AH
9705{
9706 int i;
9707
9708 /* Stack frame remains as is unless we are in AltiVec ABI. */
9709 if (! TARGET_ALTIVEC_ABI)
9710 return LAST_ALTIVEC_REGNO + 1;
9711
9712 /* Find lowest numbered live register. */
9713 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
9714 if (regs_ever_live[i])
9715 break;
9716
9717 return i;
9718}
9719
9720/* Return a 32-bit mask of the AltiVec registers we need to set in
9721 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
9722 the 32-bit word is 0. */
9723
9724static unsigned int
863d938c 9725compute_vrsave_mask (void)
00b960c7
AH
9726{
9727 unsigned int i, mask = 0;
9728
9729 /* First, find out if we use _any_ altivec registers. */
9730 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9731 if (regs_ever_live[i])
9732 mask |= ALTIVEC_REG_BIT (i);
9733
9734 if (mask == 0)
9735 return mask;
9736
00b960c7
AH
9737 /* Next, remove the argument registers from the set. These must
9738 be in the VRSAVE mask set by the caller, so we don't need to add
9739 them in again. More importantly, the mask we compute here is
9740 used to generate CLOBBERs in the set_vrsave insn, and we do not
9741 wish the argument registers to die. */
9742 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
9743 mask &= ~ALTIVEC_REG_BIT (i);
9744
9745 /* Similarly, remove the return value from the set. */
9746 {
9747 bool yes = false;
9748 diddle_return_value (is_altivec_return_reg, &yes);
9749 if (yes)
9750 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
9751 }
9752
9753 return mask;
9754}
9755
9756static void
a2369ed3 9757is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
9758{
9759 bool *yes = (bool *) xyes;
9760 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
9761 *yes = true;
9762}
9763
4697a36c
MM
9764\f
9765/* Calculate the stack information for the current function. This is
9766 complicated by having two separate calling sequences, the AIX calling
9767 sequence and the V.4 calling sequence.
9768
592696dd 9769 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 9770 32-bit 64-bit
4697a36c 9771 SP----> +---------------------------------------+
a260abc9 9772 | back chain to caller | 0 0
4697a36c 9773 +---------------------------------------+
a260abc9 9774 | saved CR | 4 8 (8-11)
4697a36c 9775 +---------------------------------------+
a260abc9 9776 | saved LR | 8 16
4697a36c 9777 +---------------------------------------+
a260abc9 9778 | reserved for compilers | 12 24
4697a36c 9779 +---------------------------------------+
a260abc9 9780 | reserved for binders | 16 32
4697a36c 9781 +---------------------------------------+
a260abc9 9782 | saved TOC pointer | 20 40
4697a36c 9783 +---------------------------------------+
a260abc9 9784 | Parameter save area (P) | 24 48
4697a36c 9785 +---------------------------------------+
a260abc9 9786 | Alloca space (A) | 24+P etc.
802a0058 9787 +---------------------------------------+
a7df97e6 9788 | Local variable space (L) | 24+P+A
4697a36c 9789 +---------------------------------------+
a7df97e6 9790 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 9791 +---------------------------------------+
00b960c7
AH
9792 | Save area for AltiVec registers (W) | 24+P+A+L+X
9793 +---------------------------------------+
9794 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
9795 +---------------------------------------+
9796 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 9797 +---------------------------------------+
00b960c7
AH
9798 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
9799 +---------------------------------------+
9800 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
9801 +---------------------------------------+
9802 old SP->| back chain to caller's caller |
9803 +---------------------------------------+
9804
5376a30c
KR
9805 The required alignment for AIX configurations is two words (i.e., 8
9806 or 16 bytes).
9807
9808
4697a36c
MM
9809 V.4 stack frames look like:
9810
9811 SP----> +---------------------------------------+
9812 | back chain to caller | 0
9813 +---------------------------------------+
5eb387b8 9814 | caller's saved LR | 4
4697a36c
MM
9815 +---------------------------------------+
9816 | Parameter save area (P) | 8
9817 +---------------------------------------+
a7df97e6
MM
9818 | Alloca space (A) | 8+P
9819 +---------------------------------------+
9820 | Varargs save area (V) | 8+P+A
9821 +---------------------------------------+
9822 | Local variable space (L) | 8+P+A+V
9823 +---------------------------------------+
9824 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 9825 +---------------------------------------+
00b960c7
AH
9826 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
9827 +---------------------------------------+
9828 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
9829 +---------------------------------------+
9830 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
9831 +---------------------------------------+
a3170dc6
AH
9832 | SPE: area for 64-bit GP registers |
9833 +---------------------------------------+
9834 | SPE alignment padding |
9835 +---------------------------------------+
00b960c7 9836 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 9837 +---------------------------------------+
00b960c7 9838 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 9839 +---------------------------------------+
00b960c7 9840 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
9841 +---------------------------------------+
9842 old SP->| back chain to caller's caller |
9843 +---------------------------------------+
b6c9286a 9844
5376a30c
KR
9845 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
9846 given. (But note below and in sysv4.h that we require only 8 and
9847 may round up the size of our stack frame anyways. The historical
9848 reason is early versions of powerpc-linux which didn't properly
9849 align the stack at program startup. A happy side-effect is that
9850 -mno-eabi libraries can be used with -meabi programs.)
9851
50d440bc 9852 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
9853 the stack alignment requirements may differ. If -mno-eabi is not
9854 given, the required stack alignment is 8 bytes; if -mno-eabi is
9855 given, the required alignment is 16 bytes. (But see V.4 comment
9856 above.) */
4697a36c 9857
61b2fbe7
MM
9858#ifndef ABI_STACK_BOUNDARY
9859#define ABI_STACK_BOUNDARY STACK_BOUNDARY
9860#endif
9861
4697a36c 9862rs6000_stack_t *
863d938c 9863rs6000_stack_info (void)
4697a36c
MM
9864{
9865 static rs6000_stack_t info, zero_info;
9866 rs6000_stack_t *info_ptr = &info;
9ebbca7d 9867 int reg_size = TARGET_POWERPC64 ? 8 : 4;
83720594 9868 int ehrd_size;
b6c9286a 9869 int total_raw_size;
4697a36c 9870
a4f6c312 9871 /* Zero all fields portably. */
4697a36c
MM
9872 info = zero_info;
9873
c19de7aa
AH
9874 if (TARGET_SPE)
9875 {
9876 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
9877 if (cfun->machine->insn_chain_scanned_p == 0)
9878 {
9879 cfun->machine->insn_chain_scanned_p = 1;
9880 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
9881 }
c19de7aa
AH
9882 }
9883
a4f6c312 9884 /* Select which calling sequence. */
178274da 9885 info_ptr->abi = DEFAULT_ABI;
9878760c 9886
a4f6c312 9887 /* Calculate which registers need to be saved & save area size. */
4697a36c 9888 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 9889 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 9890 even if it currently looks like we won't. */
2bfcf297 9891 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
9892 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
9893 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
9894 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
9895 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
9896 else
9897 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 9898
a3170dc6
AH
9899 /* For the SPE, we have an additional upper 32-bits on each GPR.
9900 Ideally we should save the entire 64-bits only when the upper
9901 half is used in SIMD instructions. Since we only record
9902 registers live (not the size they are used in), this proves
9903 difficult because we'd have to traverse the instruction chain at
9904 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
9905 so we opt to save the GPRs in 64-bits always if but one register
9906 gets used in 64-bits. Otherwise, all the registers in the frame
9907 get saved in 32-bits.
a3170dc6 9908
c19de7aa 9909 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 9910 traditional GP save area will be empty. */
c19de7aa 9911 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9912 info_ptr->gp_size = 0;
9913
4697a36c
MM
9914 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
9915 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
9916
00b960c7
AH
9917 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
9918 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
9919 - info_ptr->first_altivec_reg_save);
9920
592696dd 9921 /* Does this function call anything? */
71f123ca
FS
9922 info_ptr->calls_p = (! current_function_is_leaf
9923 || cfun->machine->ra_needs_full_frame);
b6c9286a 9924
a4f6c312 9925 /* Determine if we need to save the link register. */
71f123ca 9926 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
9927 || (DEFAULT_ABI == ABI_AIX
9928 && current_function_profile
9929 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
9930#ifdef TARGET_RELOCATABLE
9931 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
9932#endif
9933 || (info_ptr->first_fp_reg_save != 64
9934 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 9935 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 9936 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
9937 || (DEFAULT_ABI == ABI_DARWIN
9938 && flag_pic
9939 && current_function_uses_pic_offset_table)
4697a36c
MM
9940 || info_ptr->calls_p)
9941 {
9942 info_ptr->lr_save_p = 1;
9ebbca7d 9943 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
9944 }
9945
9ebbca7d
GK
9946 /* Determine if we need to save the condition code registers. */
9947 if (regs_ever_live[CR2_REGNO]
9948 || regs_ever_live[CR3_REGNO]
9949 || regs_ever_live[CR4_REGNO])
4697a36c
MM
9950 {
9951 info_ptr->cr_save_p = 1;
178274da 9952 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
9953 info_ptr->cr_size = reg_size;
9954 }
9955
83720594
RH
9956 /* If the current function calls __builtin_eh_return, then we need
9957 to allocate stack space for registers that will hold data for
9958 the exception handler. */
9959 if (current_function_calls_eh_return)
9960 {
9961 unsigned int i;
9962 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
9963 continue;
a3170dc6
AH
9964
9965 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
9966 ehrd_size = i * (TARGET_SPE_ABI
9967 && info_ptr->spe_64bit_regs_used != 0
9968 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
9969 }
9970 else
9971 ehrd_size = 0;
9972
592696dd 9973 /* Determine various sizes. */
4697a36c
MM
9974 info_ptr->reg_size = reg_size;
9975 info_ptr->fixed_size = RS6000_SAVE_AREA;
9976 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 9977 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
9978 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
9979 8);
00b960c7 9980
c19de7aa 9981 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9982 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
9983 else
9984 info_ptr->spe_gp_size = 0;
9985
08b57fb3 9986 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE)
00b960c7
AH
9987 {
9988 info_ptr->vrsave_mask = compute_vrsave_mask ();
9989 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
9990 }
9991 else
9992 {
9993 info_ptr->vrsave_mask = 0;
9994 info_ptr->vrsave_size = 0;
9995 }
b6c9286a 9996
592696dd 9997 /* Calculate the offsets. */
178274da 9998 switch (DEFAULT_ABI)
4697a36c 9999 {
b6c9286a 10000 case ABI_NONE:
24d304eb 10001 default:
b6c9286a
MM
10002 abort ();
10003
10004 case ABI_AIX:
ee890fe2 10005 case ABI_DARWIN:
b6c9286a
MM
10006 info_ptr->fp_save_offset = - info_ptr->fp_size;
10007 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10008
10009 if (TARGET_ALTIVEC_ABI)
10010 {
10011 info_ptr->vrsave_save_offset
10012 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10013
10014 /* Align stack so vector save area is on a quadword boundary. */
10015 if (info_ptr->altivec_size != 0)
10016 info_ptr->altivec_padding_size
10017 = 16 - (-info_ptr->vrsave_save_offset % 16);
10018 else
10019 info_ptr->altivec_padding_size = 0;
10020
10021 info_ptr->altivec_save_offset
10022 = info_ptr->vrsave_save_offset
10023 - info_ptr->altivec_padding_size
10024 - info_ptr->altivec_size;
10025
10026 /* Adjust for AltiVec case. */
10027 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10028 }
10029 else
10030 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10031 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10032 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10033 break;
10034
10035 case ABI_V4:
b6c9286a
MM
10036 info_ptr->fp_save_offset = - info_ptr->fp_size;
10037 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10038 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10039
c19de7aa 10040 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10041 {
10042 /* Align stack so SPE GPR save area is aligned on a
10043 double-word boundary. */
10044 if (info_ptr->spe_gp_size != 0)
10045 info_ptr->spe_padding_size
10046 = 8 - (-info_ptr->cr_save_offset % 8);
10047 else
10048 info_ptr->spe_padding_size = 0;
10049
10050 info_ptr->spe_gp_save_offset
10051 = info_ptr->cr_save_offset
10052 - info_ptr->spe_padding_size
10053 - info_ptr->spe_gp_size;
10054
10055 /* Adjust for SPE case. */
10056 info_ptr->toc_save_offset
10057 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10058 }
10059 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10060 {
10061 info_ptr->vrsave_save_offset
10062 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10063
10064 /* Align stack so vector save area is on a quadword boundary. */
10065 if (info_ptr->altivec_size != 0)
10066 info_ptr->altivec_padding_size
10067 = 16 - (-info_ptr->vrsave_save_offset % 16);
10068 else
10069 info_ptr->altivec_padding_size = 0;
10070
10071 info_ptr->altivec_save_offset
10072 = info_ptr->vrsave_save_offset
10073 - info_ptr->altivec_padding_size
10074 - info_ptr->altivec_size;
10075
10076 /* Adjust for AltiVec case. */
10077 info_ptr->toc_save_offset
10078 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10079 }
10080 else
10081 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10082 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10083 info_ptr->lr_save_offset = reg_size;
10084 break;
4697a36c
MM
10085 }
10086
00b960c7
AH
10087 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10088 + info_ptr->gp_size
10089 + info_ptr->altivec_size
10090 + info_ptr->altivec_padding_size
a3170dc6
AH
10091 + info_ptr->spe_gp_size
10092 + info_ptr->spe_padding_size
00b960c7
AH
10093 + ehrd_size
10094 + info_ptr->cr_size
10095 + info_ptr->lr_size
10096 + info_ptr->vrsave_size
10097 + info_ptr->toc_size,
10098 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10099 ? 16 : 8);
10100
ff381587
MM
10101 total_raw_size = (info_ptr->vars_size
10102 + info_ptr->parm_size
ff381587
MM
10103 + info_ptr->save_size
10104 + info_ptr->varargs_size
10105 + info_ptr->fixed_size);
10106
a4f6c312
SS
10107 info_ptr->total_size =
10108 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10109
10110 /* Determine if we need to allocate any stack frame:
10111
a4f6c312
SS
10112 For AIX we need to push the stack if a frame pointer is needed
10113 (because the stack might be dynamically adjusted), if we are
10114 debugging, if we make calls, or if the sum of fp_save, gp_save,
10115 and local variables are more than the space needed to save all
10116 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10117 + 18*8 = 288 (GPR13 reserved).
ff381587 10118
a4f6c312
SS
10119 For V.4 we don't have the stack cushion that AIX uses, but assume
10120 that the debugger can handle stackless frames. */
ff381587
MM
10121
10122 if (info_ptr->calls_p)
10123 info_ptr->push_p = 1;
10124
178274da 10125 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10126 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10127
178274da
AM
10128 else if (frame_pointer_needed)
10129 info_ptr->push_p = 1;
10130
10131 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10132 info_ptr->push_p = 1;
10133
ff381587 10134 else
178274da
AM
10135 info_ptr->push_p
10136 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10137
a4f6c312 10138 /* Zero offsets if we're not saving those registers. */
8dda1a21 10139 if (info_ptr->fp_size == 0)
4697a36c
MM
10140 info_ptr->fp_save_offset = 0;
10141
8dda1a21 10142 if (info_ptr->gp_size == 0)
4697a36c
MM
10143 info_ptr->gp_save_offset = 0;
10144
00b960c7
AH
10145 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10146 info_ptr->altivec_save_offset = 0;
10147
10148 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10149 info_ptr->vrsave_save_offset = 0;
10150
c19de7aa
AH
10151 if (! TARGET_SPE_ABI
10152 || info_ptr->spe_64bit_regs_used == 0
10153 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10154 info_ptr->spe_gp_save_offset = 0;
10155
c81fc13e 10156 if (! info_ptr->lr_save_p)
4697a36c
MM
10157 info_ptr->lr_save_offset = 0;
10158
c81fc13e 10159 if (! info_ptr->cr_save_p)
4697a36c
MM
10160 info_ptr->cr_save_offset = 0;
10161
c81fc13e 10162 if (! info_ptr->toc_save_p)
b6c9286a
MM
10163 info_ptr->toc_save_offset = 0;
10164
4697a36c
MM
10165 return info_ptr;
10166}
10167
c19de7aa
AH
10168/* Return true if the current function uses any GPRs in 64-bit SIMD
10169 mode. */
10170
10171static bool
863d938c 10172spe_func_has_64bit_regs_p (void)
c19de7aa
AH
10173{
10174 rtx insns, insn;
10175
10176 /* Functions that save and restore all the call-saved registers will
10177 need to save/restore the registers in 64-bits. */
10178 if (current_function_calls_eh_return
10179 || current_function_calls_setjmp
10180 || current_function_has_nonlocal_goto)
10181 return true;
10182
10183 insns = get_insns ();
10184
10185 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
10186 {
10187 if (INSN_P (insn))
10188 {
10189 rtx i;
10190
10191 i = PATTERN (insn);
10192 if (GET_CODE (i) == SET
10193 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
10194 return true;
10195 }
10196 }
10197
10198 return false;
10199}
10200
4697a36c 10201void
a2369ed3 10202debug_stack_info (rs6000_stack_t *info)
9878760c 10203{
d330fd93 10204 const char *abi_string;
24d304eb 10205
c81fc13e 10206 if (! info)
4697a36c
MM
10207 info = rs6000_stack_info ();
10208
10209 fprintf (stderr, "\nStack information for function %s:\n",
10210 ((current_function_decl && DECL_NAME (current_function_decl))
10211 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
10212 : "<unknown>"));
10213
24d304eb
RK
10214 switch (info->abi)
10215 {
b6c9286a
MM
10216 default: abi_string = "Unknown"; break;
10217 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 10218 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 10219 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 10220 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
10221 }
10222
10223 fprintf (stderr, "\tABI = %5s\n", abi_string);
10224
00b960c7
AH
10225 if (TARGET_ALTIVEC_ABI)
10226 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
10227
a3170dc6
AH
10228 if (TARGET_SPE_ABI)
10229 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
10230
4697a36c
MM
10231 if (info->first_gp_reg_save != 32)
10232 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
10233
10234 if (info->first_fp_reg_save != 64)
10235 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 10236
00b960c7
AH
10237 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
10238 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
10239 info->first_altivec_reg_save);
10240
4697a36c
MM
10241 if (info->lr_save_p)
10242 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 10243
4697a36c
MM
10244 if (info->cr_save_p)
10245 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
10246
b6c9286a
MM
10247 if (info->toc_save_p)
10248 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
10249
00b960c7
AH
10250 if (info->vrsave_mask)
10251 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
10252
4697a36c
MM
10253 if (info->push_p)
10254 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
10255
10256 if (info->calls_p)
10257 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
10258
4697a36c
MM
10259 if (info->gp_save_offset)
10260 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
10261
10262 if (info->fp_save_offset)
10263 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
10264
00b960c7
AH
10265 if (info->altivec_save_offset)
10266 fprintf (stderr, "\taltivec_save_offset = %5d\n",
10267 info->altivec_save_offset);
10268
a3170dc6
AH
10269 if (info->spe_gp_save_offset)
10270 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
10271 info->spe_gp_save_offset);
10272
00b960c7
AH
10273 if (info->vrsave_save_offset)
10274 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
10275 info->vrsave_save_offset);
10276
4697a36c
MM
10277 if (info->lr_save_offset)
10278 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
10279
10280 if (info->cr_save_offset)
10281 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
10282
b6c9286a
MM
10283 if (info->toc_save_offset)
10284 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
10285
4697a36c
MM
10286 if (info->varargs_save_offset)
10287 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
10288
10289 if (info->total_size)
10290 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
10291
10292 if (info->varargs_size)
10293 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
10294
10295 if (info->vars_size)
10296 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
10297
10298 if (info->parm_size)
10299 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
10300
10301 if (info->fixed_size)
10302 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
10303
10304 if (info->gp_size)
10305 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
10306
a3170dc6
AH
10307 if (info->spe_gp_size)
10308 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
10309
4697a36c
MM
10310 if (info->fp_size)
10311 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
10312
00b960c7
AH
10313 if (info->altivec_size)
10314 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
10315
10316 if (info->vrsave_size)
10317 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
10318
10319 if (info->altivec_padding_size)
10320 fprintf (stderr, "\taltivec_padding_size= %5d\n",
10321 info->altivec_padding_size);
10322
a3170dc6
AH
10323 if (info->spe_padding_size)
10324 fprintf (stderr, "\tspe_padding_size = %5d\n",
10325 info->spe_padding_size);
10326
a4f6c312 10327 if (info->lr_size)
ed947a96 10328 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 10329
4697a36c
MM
10330 if (info->cr_size)
10331 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
10332
a4f6c312 10333 if (info->toc_size)
b6c9286a
MM
10334 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
10335
4697a36c
MM
10336 if (info->save_size)
10337 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
10338
10339 if (info->reg_size != 4)
10340 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
10341
10342 fprintf (stderr, "\n");
9878760c 10343}
71f123ca
FS
10344
10345rtx
a2369ed3 10346rs6000_return_addr (int count, rtx frame)
71f123ca 10347{
a4f6c312
SS
10348 /* Currently we don't optimize very well between prolog and body
10349 code and for PIC code the code can be actually quite bad, so
10350 don't try to be too clever here. */
f1384257 10351 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
10352 {
10353 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
10354
10355 return
10356 gen_rtx_MEM
10357 (Pmode,
10358 memory_address
10359 (Pmode,
10360 plus_constant (copy_to_reg
10361 (gen_rtx_MEM (Pmode,
10362 memory_address (Pmode, frame))),
10363 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
10364 }
10365
8c29550d 10366 cfun->machine->ra_need_lr = 1;
9e2f7ec7 10367 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
10368}
10369
5e1bf043
DJ
10370/* Say whether a function is a candidate for sibcall handling or not.
10371 We do not allow indirect calls to be optimized into sibling calls.
10372 Also, we can't do it if there are any vector parameters; there's
10373 nowhere to put the VRsave code so it works; note that functions with
10374 vector parameters are required to have a prototype, so the argument
10375 type info must be available here. (The tail recursion case can work
10376 with vector parameters, but there's no way to distinguish here.) */
4977bab6 10377static bool
a2369ed3 10378rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
10379{
10380 tree type;
4977bab6 10381 if (decl)
5e1bf043
DJ
10382 {
10383 if (TARGET_ALTIVEC_VRSAVE)
10384 {
4977bab6 10385 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
10386 type; type = TREE_CHAIN (type))
10387 {
c15b529f 10388 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 10389 return false;
5e1bf043
DJ
10390 }
10391 }
10392 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 10393 || (*targetm.binds_local_p) (decl))
2bcc50d0 10394 {
4977bab6 10395 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
10396
10397 if (!lookup_attribute ("longcall", attr_list)
10398 || lookup_attribute ("shortcall", attr_list))
4977bab6 10399 return true;
2bcc50d0 10400 }
5e1bf043 10401 }
4977bab6 10402 return false;
5e1bf043
DJ
10403}
10404
71f123ca 10405static int
863d938c 10406rs6000_ra_ever_killed (void)
71f123ca
FS
10407{
10408 rtx top;
5e1bf043
DJ
10409 rtx reg;
10410 rtx insn;
71f123ca 10411
3961e8fe
RH
10412 /* Irritatingly, there are two kinds of thunks -- those created with
10413 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
10414 through the regular part of the compiler. This is a very hacky
10415 way to tell them apart. */
10416 if (current_function_is_thunk && !no_new_pseudos)
71f123ca 10417 return 0;
eb0424da 10418
36f7e964
AH
10419 /* regs_ever_live has LR marked as used if any sibcalls are present,
10420 but this should not force saving and restoring in the
10421 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
10422 clobbers LR, so that is inappropriate. */
10423
5e1bf043
DJ
10424 /* Also, the prologue can generate a store into LR that
10425 doesn't really count, like this:
36f7e964 10426
5e1bf043
DJ
10427 move LR->R0
10428 bcl to set PIC register
10429 move LR->R31
10430 move R0->LR
36f7e964
AH
10431
10432 When we're called from the epilogue, we need to avoid counting
10433 this as a store. */
5e1bf043 10434
71f123ca
FS
10435 push_topmost_sequence ();
10436 top = get_insns ();
10437 pop_topmost_sequence ();
5e1bf043 10438 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 10439
5e1bf043
DJ
10440 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
10441 {
10442 if (INSN_P (insn))
10443 {
10444 if (FIND_REG_INC_NOTE (insn, reg))
10445 return 1;
10446 else if (GET_CODE (insn) == CALL_INSN
c15b529f 10447 && !SIBLING_CALL_P (insn))
5e1bf043 10448 return 1;
36f7e964
AH
10449 else if (set_of (reg, insn) != NULL_RTX
10450 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
10451 return 1;
10452 }
10453 }
10454 return 0;
71f123ca 10455}
4697a36c 10456\f
8cd8f856
GK
10457/* Add a REG_MAYBE_DEAD note to the insn. */
10458static void
a2369ed3 10459rs6000_maybe_dead (rtx insn)
8cd8f856
GK
10460{
10461 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
10462 const0_rtx,
10463 REG_NOTES (insn));
10464}
10465
9ebbca7d 10466/* Emit instructions needed to load the TOC register.
c7ca610e 10467 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 10468 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
10469
10470void
a2369ed3 10471rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 10472{
027fbf43 10473 rtx dest, insn;
1db02437 10474 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 10475
20b71b17
AM
10476 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10477 {
10478 rtx temp = (fromprolog
10479 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
10480 : gen_reg_rtx (Pmode));
027fbf43
JJ
10481 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
10482 if (fromprolog)
10483 rs6000_maybe_dead (insn);
10484 insn = emit_move_insn (dest, temp);
10485 if (fromprolog)
10486 rs6000_maybe_dead (insn);
20b71b17
AM
10487 }
10488 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
10489 {
10490 char buf[30];
10491 rtx tempLR = (fromprolog
10492 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
10493 : gen_reg_rtx (Pmode));
10494 rtx temp0 = (fromprolog
10495 ? gen_rtx_REG (Pmode, 0)
10496 : gen_reg_rtx (Pmode));
10497 rtx symF;
10498
10499 /* possibly create the toc section */
10500 if (! toc_initialized)
38c1f2d7 10501 {
20b71b17
AM
10502 toc_section ();
10503 function_section (current_function_decl);
38c1f2d7 10504 }
9ebbca7d 10505
20b71b17
AM
10506 if (fromprolog)
10507 {
10508 rtx symL;
38c1f2d7 10509
20b71b17
AM
10510 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
10511 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 10512
20b71b17
AM
10513 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
10514 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10515
10516 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
10517 symF)));
10518 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
10519 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
10520 symL,
10521 symF)));
9ebbca7d
GK
10522 }
10523 else
20b71b17
AM
10524 {
10525 rtx tocsym;
10526 static int reload_toc_labelno = 0;
10527
10528 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
10529
10530 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
10531 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10532
027fbf43
JJ
10533 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
10534 emit_move_insn (dest, tempLR);
10535 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 10536 }
027fbf43
JJ
10537 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
10538 if (fromprolog)
10539 rs6000_maybe_dead (insn);
9ebbca7d 10540 }
20b71b17
AM
10541 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
10542 {
10543 /* This is for AIX code running in non-PIC ELF32. */
10544 char buf[30];
10545 rtx realsym;
10546 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
10547 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10548
027fbf43
JJ
10549 insn = emit_insn (gen_elf_high (dest, realsym));
10550 if (fromprolog)
10551 rs6000_maybe_dead (insn);
10552 insn = emit_insn (gen_elf_low (dest, dest, realsym));
10553 if (fromprolog)
10554 rs6000_maybe_dead (insn);
20b71b17
AM
10555 }
10556 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
10557 {
10558 if (TARGET_32BIT)
027fbf43 10559 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 10560 else
027fbf43
JJ
10561 insn = emit_insn (gen_load_toc_aix_di (dest));
10562 if (fromprolog)
10563 rs6000_maybe_dead (insn);
9ebbca7d 10564 }
20b71b17
AM
10565 else
10566 abort ();
9ebbca7d
GK
10567}
10568
10569int
863d938c 10570get_TOC_alias_set (void)
9ebbca7d
GK
10571{
10572 static int set = -1;
10573 if (set == -1)
10574 set = new_alias_set ();
10575 return set;
10576}
10577
c1207243 10578/* This returns nonzero if the current function uses the TOC. This is
c4501e62
JJ
10579 determined by the presence of (unspec ... UNSPEC_TOC) or
10580 use (unspec ... UNSPEC_TOC), which are generated by the various
10581 load_toc_* patterns. */
a4f6c312 10582
9ebbca7d
GK
10583int
10584uses_TOC ()
10585{
c4501e62 10586 rtx insn;
38c1f2d7 10587
c4501e62
JJ
10588 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
10589 if (INSN_P (insn))
10590 {
10591 rtx pat = PATTERN (insn);
10592 int i;
9ebbca7d 10593
c4501e62
JJ
10594 if (GET_CODE (pat) == PARALLEL)
10595 for (i = 0; i < XVECLEN (pat, 0); i++)
10596 {
10597 rtx sub = XVECEXP (pat, 0, i);
10598 if (GET_CODE (sub) == USE)
10599 {
10600 sub = XEXP (sub, 0);
10601 if (GET_CODE (sub) == UNSPEC
10602 && XINT (sub, 1) == UNSPEC_TOC)
10603 return 1;
10604 }
10605 }
10606 }
10607 return 0;
9ebbca7d 10608}
38c1f2d7 10609
9ebbca7d 10610rtx
a2369ed3 10611create_TOC_reference (rtx symbol)
9ebbca7d 10612{
a8a05998
ZW
10613 return gen_rtx_PLUS (Pmode,
10614 gen_rtx_REG (Pmode, TOC_REGISTER),
10615 gen_rtx_CONST (Pmode,
10616 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 10617 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 10618}
38c1f2d7 10619
fc4767bb
JJ
10620/* If _Unwind_* has been called from within the same module,
10621 toc register is not guaranteed to be saved to 40(1) on function
10622 entry. Save it there in that case. */
c7ca610e 10623
9ebbca7d 10624void
863d938c 10625rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
10626{
10627 rtx mem;
10628 rtx stack_top = gen_reg_rtx (Pmode);
10629 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
10630 rtx opcode = gen_reg_rtx (SImode);
10631 rtx tocompare = gen_reg_rtx (SImode);
10632 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
10633
10634 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
10635 emit_move_insn (stack_top, mem);
10636
fc4767bb
JJ
10637 mem = gen_rtx_MEM (Pmode,
10638 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
10639 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
10640 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
10641 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
10642 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 10643 : 0xE8410028, SImode));
9ebbca7d 10644
fc4767bb 10645 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 10646 SImode, NULL_RTX, NULL_RTX,
fc4767bb 10647 no_toc_save_needed);
9ebbca7d 10648
fc4767bb
JJ
10649 mem = gen_rtx_MEM (Pmode,
10650 gen_rtx_PLUS (Pmode, stack_top,
10651 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
10652 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
10653 emit_label (no_toc_save_needed);
9ebbca7d 10654}
38c1f2d7 10655\f
ba4828e0
RK
10656/* This ties together stack memory (MEM with an alias set of
10657 rs6000_sr_alias_set) and the change to the stack pointer. */
10658
9ebbca7d 10659static void
863d938c 10660rs6000_emit_stack_tie (void)
9ebbca7d 10661{
ba4828e0
RK
10662 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
10663
10664 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10665 emit_insn (gen_stack_tie (mem));
10666}
38c1f2d7 10667
9ebbca7d
GK
10668/* Emit the correct code for allocating stack space, as insns.
10669 If COPY_R12, make sure a copy of the old frame is left in r12.
10670 The generated code may use hard register 0 as a temporary. */
10671
10672static void
a2369ed3 10673rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 10674{
9ebbca7d
GK
10675 rtx insn;
10676 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10677 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
10678 rtx todec = GEN_INT (-size);
a157febd
GK
10679
10680 if (current_function_limit_stack)
10681 {
10682 if (REG_P (stack_limit_rtx)
10683 && REGNO (stack_limit_rtx) > 1
10684 && REGNO (stack_limit_rtx) <= 31)
10685 {
5b71a4e7 10686 emit_insn (TARGET_32BIT
9ebbca7d
GK
10687 ? gen_addsi3 (tmp_reg,
10688 stack_limit_rtx,
10689 GEN_INT (size))
10690 : gen_adddi3 (tmp_reg,
10691 stack_limit_rtx,
10692 GEN_INT (size)));
5b71a4e7 10693
9ebbca7d
GK
10694 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10695 const0_rtx));
a157febd
GK
10696 }
10697 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 10698 && TARGET_32BIT
f607bc57 10699 && DEFAULT_ABI == ABI_V4)
a157febd 10700 {
9ebbca7d
GK
10701 rtx toload = gen_rtx_CONST (VOIDmode,
10702 gen_rtx_PLUS (Pmode,
10703 stack_limit_rtx,
10704 GEN_INT (size)));
5b71a4e7 10705
9ebbca7d
GK
10706 emit_insn (gen_elf_high (tmp_reg, toload));
10707 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
10708 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10709 const0_rtx));
a157febd
GK
10710 }
10711 else
10712 warning ("stack limit expression is not supported");
10713 }
10714
9ebbca7d
GK
10715 if (copy_r12 || ! TARGET_UPDATE)
10716 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
10717
38c1f2d7
MM
10718 if (TARGET_UPDATE)
10719 {
9ebbca7d 10720 if (size > 32767)
38c1f2d7 10721 {
9ebbca7d
GK
10722 /* Need a note here so that try_split doesn't get confused. */
10723 if (get_last_insn() == NULL_RTX)
2e040219 10724 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
10725 insn = emit_move_insn (tmp_reg, todec);
10726 try_split (PATTERN (insn), insn, 0);
10727 todec = tmp_reg;
38c1f2d7 10728 }
5b71a4e7
DE
10729
10730 insn = emit_insn (TARGET_32BIT
10731 ? gen_movsi_update (stack_reg, stack_reg,
10732 todec, stack_reg)
10733 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 10734 todec, stack_reg));
38c1f2d7
MM
10735 }
10736 else
10737 {
5b71a4e7
DE
10738 insn = emit_insn (TARGET_32BIT
10739 ? gen_addsi3 (stack_reg, stack_reg, todec)
10740 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
10741 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
10742 gen_rtx_REG (Pmode, 12));
10743 }
5b71a4e7 10744
9ebbca7d
GK
10745 RTX_FRAME_RELATED_P (insn) = 1;
10746 REG_NOTES (insn) =
10747 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10748 gen_rtx_SET (VOIDmode, stack_reg,
10749 gen_rtx_PLUS (Pmode, stack_reg,
10750 GEN_INT (-size))),
10751 REG_NOTES (insn));
10752}
10753
a4f6c312
SS
10754/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
10755 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
10756 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
10757 deduce these equivalences by itself so it wasn't necessary to hold
10758 its hand so much. */
9ebbca7d
GK
10759
10760static void
a2369ed3
DJ
10761rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
10762 rtx reg2, rtx rreg)
9ebbca7d
GK
10763{
10764 rtx real, temp;
10765
e56c4463
JL
10766 /* copy_rtx will not make unique copies of registers, so we need to
10767 ensure we don't have unwanted sharing here. */
10768 if (reg == reg2)
10769 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10770
10771 if (reg == rreg)
10772 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10773
9ebbca7d
GK
10774 real = copy_rtx (PATTERN (insn));
10775
89e7058f
AH
10776 if (reg2 != NULL_RTX)
10777 real = replace_rtx (real, reg2, rreg);
10778
9ebbca7d
GK
10779 real = replace_rtx (real, reg,
10780 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
10781 STACK_POINTER_REGNUM),
10782 GEN_INT (val)));
10783
10784 /* We expect that 'real' is either a SET or a PARALLEL containing
10785 SETs (and possibly other stuff). In a PARALLEL, all the SETs
10786 are important so they all have to be marked RTX_FRAME_RELATED_P. */
10787
10788 if (GET_CODE (real) == SET)
10789 {
10790 rtx set = real;
10791
10792 temp = simplify_rtx (SET_SRC (set));
10793 if (temp)
10794 SET_SRC (set) = temp;
10795 temp = simplify_rtx (SET_DEST (set));
10796 if (temp)
10797 SET_DEST (set) = temp;
10798 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 10799 {
9ebbca7d
GK
10800 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10801 if (temp)
10802 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 10803 }
38c1f2d7 10804 }
9ebbca7d
GK
10805 else if (GET_CODE (real) == PARALLEL)
10806 {
10807 int i;
10808 for (i = 0; i < XVECLEN (real, 0); i++)
10809 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
10810 {
10811 rtx set = XVECEXP (real, 0, i);
10812
10813 temp = simplify_rtx (SET_SRC (set));
10814 if (temp)
10815 SET_SRC (set) = temp;
10816 temp = simplify_rtx (SET_DEST (set));
10817 if (temp)
10818 SET_DEST (set) = temp;
10819 if (GET_CODE (SET_DEST (set)) == MEM)
10820 {
10821 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10822 if (temp)
10823 XEXP (SET_DEST (set), 0) = temp;
10824 }
10825 RTX_FRAME_RELATED_P (set) = 1;
10826 }
10827 }
10828 else
a4f6c312 10829 abort ();
c19de7aa
AH
10830
10831 if (TARGET_SPE)
10832 real = spe_synthesize_frame_save (real);
10833
9ebbca7d
GK
10834 RTX_FRAME_RELATED_P (insn) = 1;
10835 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10836 real,
10837 REG_NOTES (insn));
38c1f2d7
MM
10838}
10839
c19de7aa
AH
10840/* Given an SPE frame note, return a PARALLEL of SETs with the
10841 original note, plus a synthetic register save. */
10842
10843static rtx
a2369ed3 10844spe_synthesize_frame_save (rtx real)
c19de7aa
AH
10845{
10846 rtx synth, offset, reg, real2;
10847
10848 if (GET_CODE (real) != SET
10849 || GET_MODE (SET_SRC (real)) != V2SImode)
10850 return real;
10851
10852 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
10853 frame related note. The parallel contains a set of the register
41f3a930 10854 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
10855 This is so we can differentiate between 64-bit and 32-bit saves.
10856 Words cannot describe this nastiness. */
10857
10858 if (GET_CODE (SET_DEST (real)) != MEM
10859 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
10860 || GET_CODE (SET_SRC (real)) != REG)
10861 abort ();
10862
10863 /* Transform:
10864 (set (mem (plus (reg x) (const y)))
10865 (reg z))
10866 into:
10867 (set (mem (plus (reg x) (const y+4)))
41f3a930 10868 (reg z+1200))
c19de7aa
AH
10869 */
10870
10871 real2 = copy_rtx (real);
10872 PUT_MODE (SET_DEST (real2), SImode);
10873 reg = SET_SRC (real2);
10874 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
10875 synth = copy_rtx (real2);
10876
10877 if (BYTES_BIG_ENDIAN)
10878 {
10879 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
10880 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
10881 }
10882
10883 reg = SET_SRC (synth);
41f3a930 10884
c19de7aa 10885 synth = replace_rtx (synth, reg,
41f3a930 10886 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
10887
10888 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
10889 synth = replace_rtx (synth, offset,
10890 GEN_INT (INTVAL (offset)
10891 + (BYTES_BIG_ENDIAN ? 0 : 4)));
10892
10893 RTX_FRAME_RELATED_P (synth) = 1;
10894 RTX_FRAME_RELATED_P (real2) = 1;
10895 if (BYTES_BIG_ENDIAN)
10896 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
10897 else
10898 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
10899
10900 return real;
10901}
10902
00b960c7
AH
10903/* Returns an insn that has a vrsave set operation with the
10904 appropriate CLOBBERs. */
10905
10906static rtx
a2369ed3 10907generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
10908{
10909 int nclobs, i;
10910 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 10911 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 10912
a004eb82
AH
10913 clobs[0]
10914 = gen_rtx_SET (VOIDmode,
10915 vrsave,
10916 gen_rtx_UNSPEC_VOLATILE (SImode,
10917 gen_rtvec (2, reg, vrsave),
10918 30));
00b960c7
AH
10919
10920 nclobs = 1;
10921
9aa86737
AH
10922 /* We need to clobber the registers in the mask so the scheduler
10923 does not move sets to VRSAVE before sets of AltiVec registers.
10924
10925 However, if the function receives nonlocal gotos, reload will set
10926 all call saved registers live. We will end up with:
10927
10928 (set (reg 999) (mem))
10929 (parallel [ (set (reg vrsave) (unspec blah))
10930 (clobber (reg 999))])
10931
10932 The clobber will cause the store into reg 999 to be dead, and
10933 flow will attempt to delete an epilogue insn. In this case, we
10934 need an unspec use/set of the register. */
00b960c7
AH
10935
10936 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10937 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
10938 {
10939 if (!epiloguep || call_used_regs [i])
10940 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
10941 gen_rtx_REG (V4SImode, i));
10942 else
10943 {
10944 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
10945
10946 clobs[nclobs++]
a004eb82
AH
10947 = gen_rtx_SET (VOIDmode,
10948 reg,
10949 gen_rtx_UNSPEC (V4SImode,
10950 gen_rtvec (1, reg), 27));
9aa86737
AH
10951 }
10952 }
00b960c7
AH
10953
10954 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
10955
10956 for (i = 0; i < nclobs; ++i)
10957 XVECEXP (insn, 0, i) = clobs[i];
10958
10959 return insn;
10960}
10961
89e7058f
AH
10962/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
10963 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
10964
10965static void
a2369ed3
DJ
10966emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
10967 unsigned int regno, int offset, int total_size)
89e7058f
AH
10968{
10969 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
10970 rtx replacea, replaceb;
10971
10972 int_rtx = GEN_INT (offset);
10973
10974 /* Some cases that need register indexed addressing. */
10975 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
10976 || (TARGET_SPE_ABI
10977 && SPE_VECTOR_MODE (mode)
10978 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
10979 {
10980 /* Whomever calls us must make sure r11 is available in the
10981 flow path of instructions in the prologue. */
10982 offset_rtx = gen_rtx_REG (Pmode, 11);
10983 emit_move_insn (offset_rtx, int_rtx);
10984
10985 replacea = offset_rtx;
10986 replaceb = int_rtx;
10987 }
10988 else
10989 {
10990 offset_rtx = int_rtx;
10991 replacea = NULL_RTX;
10992 replaceb = NULL_RTX;
10993 }
10994
10995 reg = gen_rtx_REG (mode, regno);
10996 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
10997 mem = gen_rtx_MEM (mode, addr);
10998 set_mem_alias_set (mem, rs6000_sr_alias_set);
10999
11000 insn = emit_move_insn (mem, reg);
11001
11002 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11003}
11004
a3170dc6
AH
11005/* Emit an offset memory reference suitable for a frame store, while
11006 converting to a valid addressing mode. */
11007
11008static rtx
a2369ed3 11009gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11010{
11011 rtx int_rtx, offset_rtx;
11012
11013 int_rtx = GEN_INT (offset);
11014
11015 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11016 {
11017 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11018 emit_move_insn (offset_rtx, int_rtx);
11019 }
11020 else
11021 offset_rtx = int_rtx;
11022
11023 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11024}
11025
9ebbca7d
GK
11026/* Emit function prologue as insns. */
11027
9878760c 11028void
863d938c 11029rs6000_emit_prologue (void)
9878760c 11030{
4697a36c 11031 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
11032 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
11033 int reg_size = TARGET_POWERPC64 ? 8 : 4;
11034 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11035 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11036 rtx frame_reg_rtx = sp_reg_rtx;
11037 rtx cr_save_rtx = NULL;
11038 rtx insn;
11039 int saving_FPRs_inline;
11040 int using_store_multiple;
11041 HOST_WIDE_INT sp_offset = 0;
11042
c19de7aa 11043 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11044 {
11045 reg_mode = V2SImode;
11046 reg_size = 8;
11047 }
11048
9ebbca7d 11049 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11050 && (!TARGET_SPE_ABI
11051 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11052 && info->first_gp_reg_save < 31);
11053 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11054 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11055 || current_function_calls_eh_return
8c29550d 11056 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11057
11058 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11059 if (info->push_p
acd0b319
AM
11060 && (DEFAULT_ABI == ABI_V4
11061 || current_function_calls_eh_return))
9ebbca7d
GK
11062 {
11063 if (info->total_size < 32767)
11064 sp_offset = info->total_size;
11065 else
11066 frame_reg_rtx = frame_ptr_rtx;
11067 rs6000_emit_allocate_stack (info->total_size,
11068 (frame_reg_rtx != sp_reg_rtx
11069 && (info->cr_save_p
11070 || info->lr_save_p
11071 || info->first_fp_reg_save < 64
11072 || info->first_gp_reg_save < 32
11073 )));
11074 if (frame_reg_rtx != sp_reg_rtx)
11075 rs6000_emit_stack_tie ();
11076 }
11077
9aa86737
AH
11078 /* Save AltiVec registers if needed. */
11079 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11080 {
11081 int i;
11082
11083 /* There should be a non inline version of this, for when we
11084 are saving lots of vector registers. */
11085 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11086 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11087 {
11088 rtx areg, savereg, mem;
11089 int offset;
11090
11091 offset = info->altivec_save_offset + sp_offset
11092 + 16 * (i - info->first_altivec_reg_save);
11093
11094 savereg = gen_rtx_REG (V4SImode, i);
11095
11096 areg = gen_rtx_REG (Pmode, 0);
11097 emit_move_insn (areg, GEN_INT (offset));
11098
11099 /* AltiVec addressing mode is [reg+reg]. */
11100 mem = gen_rtx_MEM (V4SImode,
11101 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11102
11103 set_mem_alias_set (mem, rs6000_sr_alias_set);
11104
11105 insn = emit_move_insn (mem, savereg);
11106
5c242421
SB
11107 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11108 areg, GEN_INT (offset));
9aa86737
AH
11109 }
11110 }
11111
11112 /* VRSAVE is a bit vector representing which AltiVec registers
11113 are used. The OS uses this to determine which vector
11114 registers to save on a context switch. We need to save
11115 VRSAVE on the stack frame, add whatever AltiVec registers we
11116 used in this function, and do the corresponding magic in the
11117 epilogue. */
11118
11119 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
11120 {
a004eb82 11121 rtx reg, mem, vrsave;
9aa86737
AH
11122 int offset;
11123
11124 /* Get VRSAVE onto a GPR. */
11125 reg = gen_rtx_REG (SImode, 12);
a004eb82 11126 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11127 if (TARGET_MACHO)
11128 emit_insn (gen_get_vrsave_internal (reg));
11129 else
11130 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11131
11132 /* Save VRSAVE. */
11133 offset = info->vrsave_save_offset + sp_offset;
11134 mem
11135 = gen_rtx_MEM (SImode,
11136 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
11137 set_mem_alias_set (mem, rs6000_sr_alias_set);
11138 insn = emit_move_insn (mem, reg);
11139
11140 /* Include the registers in the mask. */
11141 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
11142
11143 insn = emit_insn (generate_set_vrsave (reg, info, 0));
11144 }
11145
9ebbca7d
GK
11146 /* If we use the link register, get it into r0. */
11147 if (info->lr_save_p)
71f123ca 11148 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
11149 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11150
11151 /* If we need to save CR, put it into r12. */
11152 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
11153 {
11154 cr_save_rtx = gen_rtx_REG (SImode, 12);
11155 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11156 }
11157
a4f6c312
SS
11158 /* Do any required saving of fpr's. If only one or two to save, do
11159 it ourselves. Otherwise, call function. */
9ebbca7d
GK
11160 if (saving_FPRs_inline)
11161 {
11162 int i;
11163 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11164 if ((regs_ever_live[info->first_fp_reg_save+i]
11165 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
11166 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
11167 info->first_fp_reg_save + i,
11168 info->fp_save_offset + sp_offset + 8 * i,
11169 info->total_size);
9ebbca7d
GK
11170 }
11171 else if (info->first_fp_reg_save != 64)
11172 {
11173 int i;
11174 char rname[30];
520a57c8 11175 const char *alloc_rname;
9ebbca7d
GK
11176 rtvec p;
11177 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
11178
11179 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
11180 gen_rtx_REG (Pmode,
11181 LINK_REGISTER_REGNUM));
11182 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
11183 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 11184 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11185 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
11186 gen_rtx_SYMBOL_REF (Pmode,
11187 alloc_rname));
11188 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11189 {
11190 rtx addr, reg, mem;
11191 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
11192 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11193 GEN_INT (info->fp_save_offset
11194 + sp_offset + 8*i));
11195 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11196 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11197
11198 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
11199 }
11200 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11201 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11202 NULL_RTX, NULL_RTX);
11203 }
b6c9286a 11204
9ebbca7d
GK
11205 /* Save GPRs. This is done as a PARALLEL if we are using
11206 the store-multiple instructions. */
11207 if (using_store_multiple)
b6c9286a 11208 {
308c142a 11209 rtvec p;
9ebbca7d
GK
11210 int i;
11211 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
11212 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11213 {
11214 rtx addr, reg, mem;
11215 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11216 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11217 GEN_INT (info->gp_save_offset
11218 + sp_offset
11219 + reg_size * i));
11220 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11221 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11222
11223 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
11224 }
11225 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11226 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11227 NULL_RTX, NULL_RTX);
b6c9286a
MM
11228 }
11229 else
11230 {
9ebbca7d
GK
11231 int i;
11232 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11233 if ((regs_ever_live[info->first_gp_reg_save+i]
11234 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11235 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11236 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11237 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
11238 {
11239 rtx addr, reg, mem;
11240 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11241
c19de7aa 11242 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11243 {
11244 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11245 rtx b;
11246
11247 if (!SPE_CONST_OFFSET_OK (offset))
11248 {
11249 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11250 emit_move_insn (b, GEN_INT (offset));
11251 }
11252 else
11253 b = GEN_INT (offset);
11254
11255 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11256 mem = gen_rtx_MEM (V2SImode, addr);
11257 set_mem_alias_set (mem, rs6000_sr_alias_set);
11258 insn = emit_move_insn (mem, reg);
11259
11260 if (GET_CODE (b) == CONST_INT)
11261 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11262 NULL_RTX, NULL_RTX);
11263 else
11264 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11265 b, GEN_INT (offset));
11266 }
11267 else
11268 {
11269 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11270 GEN_INT (info->gp_save_offset
11271 + sp_offset
11272 + reg_size * i));
11273 mem = gen_rtx_MEM (reg_mode, addr);
11274 set_mem_alias_set (mem, rs6000_sr_alias_set);
11275
11276 insn = emit_move_insn (mem, reg);
11277 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11278 NULL_RTX, NULL_RTX);
11279 }
11280 }
9ebbca7d
GK
11281 }
11282
83720594
RH
11283 /* ??? There's no need to emit actual instructions here, but it's the
11284 easiest way to get the frame unwind information emitted. */
11285 if (current_function_calls_eh_return)
11286 {
78e1b90d
DE
11287 unsigned int i, regno;
11288
fc4767bb
JJ
11289 /* In AIX ABI we need to pretend we save r2 here. */
11290 if (TARGET_AIX)
11291 {
11292 rtx addr, reg, mem;
11293
11294 reg = gen_rtx_REG (reg_mode, 2);
11295 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11296 GEN_INT (sp_offset + 5 * reg_size));
11297 mem = gen_rtx_MEM (reg_mode, addr);
11298 set_mem_alias_set (mem, rs6000_sr_alias_set);
11299
11300 insn = emit_move_insn (mem, reg);
11301 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11302 NULL_RTX, NULL_RTX);
11303 PATTERN (insn) = gen_blockage ();
11304 }
11305
83720594
RH
11306 for (i = 0; ; ++i)
11307 {
83720594
RH
11308 regno = EH_RETURN_DATA_REGNO (i);
11309 if (regno == INVALID_REGNUM)
11310 break;
11311
89e7058f
AH
11312 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
11313 info->ehrd_offset + sp_offset
11314 + reg_size * (int) i,
11315 info->total_size);
83720594
RH
11316 }
11317 }
11318
9ebbca7d
GK
11319 /* Save lr if we used it. */
11320 if (info->lr_save_p)
11321 {
11322 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11323 GEN_INT (info->lr_save_offset + sp_offset));
11324 rtx reg = gen_rtx_REG (Pmode, 0);
11325 rtx mem = gen_rtx_MEM (Pmode, addr);
11326 /* This should not be of rs6000_sr_alias_set, because of
11327 __builtin_return_address. */
11328
11329 insn = emit_move_insn (mem, reg);
11330 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11331 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11332 }
11333
11334 /* Save CR if we use any that must be preserved. */
11335 if (info->cr_save_p)
11336 {
11337 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11338 GEN_INT (info->cr_save_offset + sp_offset));
11339 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11340
11341 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11342
11343 /* If r12 was used to hold the original sp, copy cr into r0 now
11344 that it's free. */
11345 if (REGNO (frame_reg_rtx) == 12)
11346 {
11347 cr_save_rtx = gen_rtx_REG (SImode, 0);
11348 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11349 }
11350 insn = emit_move_insn (mem, cr_save_rtx);
11351
11352 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
11353 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
11354 But that's OK. All we have to do is specify that _one_ condition
11355 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
11356 will then restore all the call-saved registers.
11357 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 11358 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 11359 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
11360 }
11361
11362 /* Update stack and set back pointer unless this is V.4,
11363 for which it was done previously. */
fc4767bb
JJ
11364 if (info->push_p
11365 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
11366 rs6000_emit_allocate_stack (info->total_size, FALSE);
11367
11368 /* Set frame pointer, if needed. */
11369 if (frame_pointer_needed)
11370 {
a3170dc6 11371 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
11372 sp_reg_rtx);
11373 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 11374 }
9878760c 11375
1db02437 11376 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 11377 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 11378 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 11379 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
11380 {
11381 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 11382 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
11383 can use register 0. This allows us to use a plain 'blr' to return
11384 from the procedure more often. */
f1384257
AM
11385 int save_LR_around_toc_setup = (TARGET_ELF
11386 && DEFAULT_ABI != ABI_AIX
11387 && flag_pic
d5fa86ba
GK
11388 && ! info->lr_save_p
11389 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 11390 if (save_LR_around_toc_setup)
c4501e62
JJ
11391 {
11392 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11393 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
11394 rs6000_emit_load_toc_table (TRUE);
11395 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
11396 }
11397 else
11398 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 11399 }
ee890fe2 11400
fcce224d 11401#if TARGET_MACHO
ee890fe2
SS
11402 if (DEFAULT_ABI == ABI_DARWIN
11403 && flag_pic && current_function_uses_pic_offset_table)
11404 {
11405 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 11406 const char *picbase = machopic_function_base_name ();
6788f5ca 11407 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 11408
f51eee6a 11409 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
11410
11411 rs6000_maybe_dead (
1db02437 11412 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
11413 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
11414 }
fcce224d 11415#endif
9ebbca7d
GK
11416}
11417
9ebbca7d 11418/* Write function prologue. */
a4f6c312 11419
08c148a8 11420static void
a2369ed3
DJ
11421rs6000_output_function_prologue (FILE *file,
11422 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
11423{
11424 rs6000_stack_t *info = rs6000_stack_info ();
11425
4697a36c
MM
11426 if (TARGET_DEBUG_STACK)
11427 debug_stack_info (info);
9878760c 11428
a4f6c312
SS
11429 /* Write .extern for any function we will call to save and restore
11430 fp values. */
11431 if (info->first_fp_reg_save < 64
11432 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 11433 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 11434 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
11435 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
11436 RESTORE_FP_SUFFIX);
9878760c 11437
c764f757
RK
11438 /* Write .extern for AIX common mode routines, if needed. */
11439 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
11440 {
f6709c70
JW
11441 fputs ("\t.extern __mulh\n", file);
11442 fputs ("\t.extern __mull\n", file);
11443 fputs ("\t.extern __divss\n", file);
11444 fputs ("\t.extern __divus\n", file);
11445 fputs ("\t.extern __quoss\n", file);
11446 fputs ("\t.extern __quous\n", file);
c764f757
RK
11447 common_mode_defined = 1;
11448 }
9878760c 11449
9ebbca7d 11450 if (! HAVE_prologue)
979721f8 11451 {
9ebbca7d 11452 start_sequence ();
9dda4cc8 11453
a4f6c312
SS
11454 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
11455 the "toplevel" insn chain. */
2e040219 11456 emit_note (NOTE_INSN_DELETED);
9ebbca7d 11457 rs6000_emit_prologue ();
2e040219 11458 emit_note (NOTE_INSN_DELETED);
178c3eff
DJ
11459
11460 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11461 {
11462 rtx insn;
11463 unsigned addr = 0;
11464 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11465 {
11466 INSN_ADDRESSES_NEW (insn, addr);
11467 addr += 4;
11468 }
11469 }
9dda4cc8 11470
9ebbca7d 11471 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11472 debug_rtx_list (get_insns (), 100);
11473 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11474 end_sequence ();
979721f8
MM
11475 }
11476
9ebbca7d
GK
11477 rs6000_pic_labelno++;
11478}
11479
11480/* Emit function epilogue as insns.
9878760c 11481
9ebbca7d
GK
11482 At present, dwarf2out_frame_debug_expr doesn't understand
11483 register restores, so we don't bother setting RTX_FRAME_RELATED_P
11484 anywhere in the epilogue. Most of the insns below would in any case
11485 need special notes to explain where r11 is in relation to the stack. */
9878760c 11486
9ebbca7d 11487void
a2369ed3 11488rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
11489{
11490 rs6000_stack_t *info;
11491 int restoring_FPRs_inline;
11492 int using_load_multiple;
11493 int using_mfcr_multiple;
11494 int use_backchain_to_restore_sp;
11495 int sp_offset = 0;
11496 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
11497 rtx frame_reg_rtx = sp_reg_rtx;
11498 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
11499 int reg_size = TARGET_POWERPC64 ? 8 : 4;
11500 int i;
11501
c19de7aa
AH
11502 info = rs6000_stack_info ();
11503
11504 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11505 {
11506 reg_mode = V2SImode;
11507 reg_size = 8;
11508 }
11509
9ebbca7d 11510 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11511 && (!TARGET_SPE_ABI
11512 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11513 && info->first_gp_reg_save < 31);
11514 restoring_FPRs_inline = (sibcall
83720594 11515 || current_function_calls_eh_return
9ebbca7d
GK
11516 || info->first_fp_reg_save == 64
11517 || FP_SAVE_INLINE (info->first_fp_reg_save));
11518 use_backchain_to_restore_sp = (frame_pointer_needed
11519 || current_function_calls_alloca
11520 || info->total_size > 32767);
11521 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
11522 || rs6000_cpu == PROCESSOR_PPC603
11523 || rs6000_cpu == PROCESSOR_PPC750
11524 || optimize_size);
11525
11526 /* If we have a frame pointer, a call to alloca, or a large stack
11527 frame, restore the old stack pointer using the backchain. Otherwise,
11528 we know what size to update it with. */
11529 if (use_backchain_to_restore_sp)
bacbde18 11530 {
9ebbca7d
GK
11531 /* Under V.4, don't reset the stack pointer until after we're done
11532 loading the saved registers. */
f607bc57 11533 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 11534 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 11535
9ebbca7d
GK
11536 emit_move_insn (frame_reg_rtx,
11537 gen_rtx_MEM (Pmode, sp_reg_rtx));
11538
bacbde18 11539 }
9ebbca7d 11540 else if (info->push_p)
85638c0d 11541 {
fc4767bb
JJ
11542 if (DEFAULT_ABI == ABI_V4
11543 || current_function_calls_eh_return)
9ebbca7d
GK
11544 sp_offset = info->total_size;
11545 else
11546 {
11547 emit_insn (TARGET_32BIT
11548 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11549 GEN_INT (info->total_size))
11550 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11551 GEN_INT (info->total_size)));
11552 }
85638c0d 11553 }
9ebbca7d 11554
9aa86737
AH
11555 /* Restore AltiVec registers if needed. */
11556 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11557 {
11558 int i;
11559
11560 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11561 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11562 {
11563 rtx addr, areg, mem;
11564
11565 areg = gen_rtx_REG (Pmode, 0);
11566 emit_move_insn
11567 (areg, GEN_INT (info->altivec_save_offset
11568 + sp_offset
11569 + 16 * (i - info->first_altivec_reg_save)));
11570
11571 /* AltiVec addressing mode is [reg+reg]. */
11572 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
11573 mem = gen_rtx_MEM (V4SImode, addr);
11574 set_mem_alias_set (mem, rs6000_sr_alias_set);
11575
11576 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
11577 }
11578 }
11579
11580 /* Restore VRSAVE if needed. */
11581 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
11582 {
11583 rtx addr, mem, reg;
11584
11585 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11586 GEN_INT (info->vrsave_save_offset + sp_offset));
11587 mem = gen_rtx_MEM (SImode, addr);
11588 set_mem_alias_set (mem, rs6000_sr_alias_set);
11589 reg = gen_rtx_REG (SImode, 12);
11590 emit_move_insn (reg, mem);
11591
11592 emit_insn (generate_set_vrsave (reg, info, 1));
11593 }
11594
9ebbca7d
GK
11595 /* Get the old lr if we saved it. */
11596 if (info->lr_save_p)
b6c9286a 11597 {
a3170dc6
AH
11598 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
11599 info->lr_save_offset + sp_offset);
ba4828e0
RK
11600
11601 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 11602
9ebbca7d 11603 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 11604 }
9ebbca7d
GK
11605
11606 /* Get the old cr if we saved it. */
11607 if (info->cr_save_p)
11608 {
11609 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11610 GEN_INT (info->cr_save_offset + sp_offset));
11611 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11612
11613 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 11614
9ebbca7d
GK
11615 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
11616 }
11617
11618 /* Set LR here to try to overlap restores below. */
4697a36c 11619 if (info->lr_save_p)
9ebbca7d
GK
11620 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
11621 gen_rtx_REG (Pmode, 0));
11622
83720594
RH
11623 /* Load exception handler data registers, if needed. */
11624 if (current_function_calls_eh_return)
11625 {
78e1b90d
DE
11626 unsigned int i, regno;
11627
fc4767bb
JJ
11628 if (TARGET_AIX)
11629 {
11630 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11631 GEN_INT (sp_offset + 5 * reg_size));
11632 rtx mem = gen_rtx_MEM (reg_mode, addr);
11633
11634 set_mem_alias_set (mem, rs6000_sr_alias_set);
11635
11636 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
11637 }
11638
83720594
RH
11639 for (i = 0; ; ++i)
11640 {
a3170dc6 11641 rtx mem;
83720594
RH
11642
11643 regno = EH_RETURN_DATA_REGNO (i);
11644 if (regno == INVALID_REGNUM)
11645 break;
11646
a3170dc6
AH
11647 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
11648 info->ehrd_offset + sp_offset
11649 + reg_size * (int) i);
ba4828e0 11650 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
11651
11652 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
11653 }
11654 }
9ebbca7d
GK
11655
11656 /* Restore GPRs. This is done as a PARALLEL if we are using
11657 the load-multiple instructions. */
11658 if (using_load_multiple)
979721f8 11659 {
9ebbca7d
GK
11660 rtvec p;
11661 p = rtvec_alloc (32 - info->first_gp_reg_save);
11662 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 11663 {
9ebbca7d
GK
11664 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11665 GEN_INT (info->gp_save_offset
11666 + sp_offset
11667 + reg_size * i));
11668 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
11669
11670 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11671
11672 RTVEC_ELT (p, i) =
11673 gen_rtx_SET (VOIDmode,
11674 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
11675 mem);
979721f8 11676 }
9ebbca7d 11677 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 11678 }
9ebbca7d
GK
11679 else
11680 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11681 if ((regs_ever_live[info->first_gp_reg_save+i]
11682 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11683 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11684 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11685 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
11686 {
11687 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11688 GEN_INT (info->gp_save_offset
11689 + sp_offset
11690 + reg_size * i));
11691 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11692
a3170dc6 11693 /* Restore 64-bit quantities for SPE. */
c19de7aa 11694 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11695 {
11696 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11697 rtx b;
11698
11699 if (!SPE_CONST_OFFSET_OK (offset))
11700 {
11701 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11702 emit_move_insn (b, GEN_INT (offset));
11703 }
11704 else
11705 b = GEN_INT (offset);
11706
11707 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11708 mem = gen_rtx_MEM (V2SImode, addr);
11709 }
11710
ba4828e0 11711 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11712
11713 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 11714 info->first_gp_reg_save + i), mem);
9ebbca7d 11715 }
9878760c 11716
9ebbca7d
GK
11717 /* Restore fpr's if we need to do it without calling a function. */
11718 if (restoring_FPRs_inline)
11719 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11720 if ((regs_ever_live[info->first_fp_reg_save+i]
11721 && ! call_used_regs[info->first_fp_reg_save+i]))
11722 {
11723 rtx addr, mem;
11724 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11725 GEN_INT (info->fp_save_offset
11726 + sp_offset
a4f6c312 11727 + 8 * i));
9ebbca7d 11728 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11729 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11730
11731 emit_move_insn (gen_rtx_REG (DFmode,
11732 info->first_fp_reg_save + i),
11733 mem);
11734 }
8d30c4ee 11735
9ebbca7d
GK
11736 /* If we saved cr, restore it here. Just those that were used. */
11737 if (info->cr_save_p)
979721f8 11738 {
9ebbca7d 11739 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 11740 int count = 0;
9ebbca7d
GK
11741
11742 if (using_mfcr_multiple)
979721f8 11743 {
9ebbca7d
GK
11744 for (i = 0; i < 8; i++)
11745 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 11746 count++;
9ebbca7d 11747 if (count == 0)
e35b9579
GK
11748 abort ();
11749 }
11750
11751 if (using_mfcr_multiple && count > 1)
11752 {
11753 rtvec p;
11754 int ndx;
9ebbca7d 11755
e35b9579 11756 p = rtvec_alloc (count);
9ebbca7d 11757
e35b9579 11758 ndx = 0;
9ebbca7d
GK
11759 for (i = 0; i < 8; i++)
11760 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
11761 {
11762 rtvec r = rtvec_alloc (2);
11763 RTVEC_ELT (r, 0) = r12_rtx;
11764 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 11765 RTVEC_ELT (p, ndx) =
9ebbca7d 11766 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 11767 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 11768 ndx++;
9ebbca7d
GK
11769 }
11770 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
11771 if (ndx != count)
11772 abort ();
979721f8
MM
11773 }
11774 else
9ebbca7d
GK
11775 for (i = 0; i < 8; i++)
11776 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 11777 {
9ebbca7d
GK
11778 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
11779 CR0_REGNO+i),
11780 r12_rtx));
979721f8 11781 }
979721f8
MM
11782 }
11783
9ebbca7d
GK
11784 /* If this is V.4, unwind the stack pointer after all of the loads
11785 have been done. We need to emit a block here so that sched
11786 doesn't decide to move the sp change before the register restores
11787 (which may not have any obvious dependency on the stack). This
11788 doesn't hurt performance, because there is no scheduling that can
11789 be done after this point. */
fc4767bb
JJ
11790 if (DEFAULT_ABI == ABI_V4
11791 || current_function_calls_eh_return)
b6c9286a 11792 {
9ebbca7d
GK
11793 if (frame_reg_rtx != sp_reg_rtx)
11794 rs6000_emit_stack_tie ();
b6c9286a 11795
9ebbca7d 11796 if (use_backchain_to_restore_sp)
b6c9286a 11797 {
9ebbca7d 11798 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 11799 }
9ebbca7d 11800 else if (sp_offset != 0)
13f1623b 11801 {
5b71a4e7 11802 emit_insn (TARGET_32BIT
9ebbca7d
GK
11803 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11804 GEN_INT (sp_offset))
11805 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11806 GEN_INT (sp_offset)));
13f1623b 11807 }
9ebbca7d 11808 }
b6c9286a 11809
83720594
RH
11810 if (current_function_calls_eh_return)
11811 {
11812 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 11813 emit_insn (TARGET_32BIT
83720594
RH
11814 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
11815 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
11816 }
11817
9ebbca7d
GK
11818 if (!sibcall)
11819 {
11820 rtvec p;
11821 if (! restoring_FPRs_inline)
11822 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
11823 else
11824 p = rtvec_alloc (2);
b6c9286a 11825
e35b9579
GK
11826 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
11827 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
11828 gen_rtx_REG (Pmode,
11829 LINK_REGISTER_REGNUM));
9ebbca7d
GK
11830
11831 /* If we have to restore more than two FP registers, branch to the
11832 restore function. It will return to our caller. */
11833 if (! restoring_FPRs_inline)
11834 {
11835 int i;
11836 char rname[30];
520a57c8 11837 const char *alloc_rname;
979721f8 11838
9ebbca7d
GK
11839 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
11840 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 11841 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11842 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
11843 gen_rtx_SYMBOL_REF (Pmode,
11844 alloc_rname));
b6c9286a 11845
9ebbca7d
GK
11846 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11847 {
11848 rtx addr, mem;
11849 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
11850 GEN_INT (info->fp_save_offset + 8*i));
11851 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11852 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11853
11854 RTVEC_ELT (p, i+3) =
11855 gen_rtx_SET (VOIDmode,
11856 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
11857 mem);
b6c9286a
MM
11858 }
11859 }
9ebbca7d
GK
11860
11861 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 11862 }
9878760c
RK
11863}
11864
11865/* Write function epilogue. */
11866
08c148a8 11867static void
a2369ed3
DJ
11868rs6000_output_function_epilogue (FILE *file,
11869 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 11870{
4697a36c 11871 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 11872
9ebbca7d 11873 if (! HAVE_epilogue)
9878760c 11874 {
9ebbca7d
GK
11875 rtx insn = get_last_insn ();
11876 /* If the last insn was a BARRIER, we don't have to write anything except
11877 the trace table. */
11878 if (GET_CODE (insn) == NOTE)
11879 insn = prev_nonnote_insn (insn);
11880 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 11881 {
9ebbca7d
GK
11882 /* This is slightly ugly, but at least we don't have two
11883 copies of the epilogue-emitting code. */
11884 start_sequence ();
11885
11886 /* A NOTE_INSN_DELETED is supposed to be at the start
11887 and end of the "toplevel" insn chain. */
2e040219 11888 emit_note (NOTE_INSN_DELETED);
9ebbca7d 11889 rs6000_emit_epilogue (FALSE);
2e040219 11890 emit_note (NOTE_INSN_DELETED);
9ebbca7d 11891
178c3eff
DJ
11892 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11893 {
11894 rtx insn;
11895 unsigned addr = 0;
11896 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11897 {
11898 INSN_ADDRESSES_NEW (insn, addr);
11899 addr += 4;
11900 }
11901 }
11902
9ebbca7d 11903 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11904 debug_rtx_list (get_insns (), 100);
11905 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11906 end_sequence ();
4697a36c 11907 }
9878760c 11908 }
b4ac57ab 11909
0e5da0be
GK
11910#if TARGET_OBJECT_FORMAT == OBJECT_MACHO
11911 /* Mach-O doesn't support labels at the end of objects, so if
11912 it looks like we might want one, insert a NOP. */
11913 {
11914 rtx insn = get_last_insn ();
11915 while (insn
11916 && NOTE_P (insn)
11917 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
11918 insn = PREV_INSN (insn);
11919 if (insn
11920 && (LABEL_P (insn)
11921 || (NOTE_P (insn)
11922 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
11923 fputs ("\tnop\n", file);
11924 }
11925#endif
11926
9b30bae2 11927 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
11928 on its format.
11929
11930 We don't output a traceback table if -finhibit-size-directive was
11931 used. The documentation for -finhibit-size-directive reads
11932 ``don't output a @code{.size} assembler directive, or anything
11933 else that would cause trouble if the function is split in the
11934 middle, and the two halves are placed at locations far apart in
11935 memory.'' The traceback table has this property, since it
11936 includes the offset from the start of the function to the
4d30c363
MM
11937 traceback table itself.
11938
11939 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 11940 different traceback table. */
57ac7be9
AM
11941 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
11942 && rs6000_traceback != traceback_none)
9b30bae2 11943 {
69c75916 11944 const char *fname = NULL;
3ac88239 11945 const char *language_string = lang_hooks.name;
6041bf2f 11946 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 11947 int i;
57ac7be9
AM
11948 int optional_tbtab;
11949
11950 if (rs6000_traceback == traceback_full)
11951 optional_tbtab = 1;
11952 else if (rs6000_traceback == traceback_part)
11953 optional_tbtab = 0;
11954 else
11955 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 11956
69c75916
AM
11957 if (optional_tbtab)
11958 {
11959 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11960 while (*fname == '.') /* V.4 encodes . in the name */
11961 fname++;
11962
11963 /* Need label immediately before tbtab, so we can compute
11964 its offset from the function start. */
11965 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
11966 ASM_OUTPUT_LABEL (file, fname);
11967 }
314fc5a9
ILT
11968
11969 /* The .tbtab pseudo-op can only be used for the first eight
11970 expressions, since it can't handle the possibly variable
11971 length fields that follow. However, if you omit the optional
11972 fields, the assembler outputs zeros for all optional fields
11973 anyways, giving each variable length field is minimum length
11974 (as defined in sys/debug.h). Thus we can not use the .tbtab
11975 pseudo-op at all. */
11976
11977 /* An all-zero word flags the start of the tbtab, for debuggers
11978 that have to find it by searching forward from the entry
11979 point or from the current pc. */
19d2d16f 11980 fputs ("\t.long 0\n", file);
314fc5a9
ILT
11981
11982 /* Tbtab format type. Use format type 0. */
19d2d16f 11983 fputs ("\t.byte 0,", file);
314fc5a9
ILT
11984
11985 /* Language type. Unfortunately, there doesn't seem to be any
11986 official way to get this info, so we use language_string. C
11987 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 11988 value for C for now. There is no official value for Java,
6f573ff9 11989 although IBM appears to be using 13. There is no official value
f710504c 11990 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 11991 if (! strcmp (language_string, "GNU C")
e2c953b6 11992 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
11993 i = 0;
11994 else if (! strcmp (language_string, "GNU F77"))
11995 i = 1;
11996 else if (! strcmp (language_string, "GNU Ada"))
11997 i = 3;
8b83775b 11998 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
11999 i = 2;
12000 else if (! strcmp (language_string, "GNU C++"))
12001 i = 9;
9517ead8
AG
12002 else if (! strcmp (language_string, "GNU Java"))
12003 i = 13;
6f573ff9
JL
12004 else if (! strcmp (language_string, "GNU CHILL"))
12005 i = 44;
314fc5a9
ILT
12006 else
12007 abort ();
12008 fprintf (file, "%d,", i);
12009
12010 /* 8 single bit fields: global linkage (not set for C extern linkage,
12011 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12012 from start of procedure stored in tbtab, internal function, function
12013 has controlled storage, function has no toc, function uses fp,
12014 function logs/aborts fp operations. */
12015 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12016 fprintf (file, "%d,",
12017 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12018
12019 /* 6 bitfields: function is interrupt handler, name present in
12020 proc table, function calls alloca, on condition directives
12021 (controls stack walks, 3 bits), saves condition reg, saves
12022 link reg. */
12023 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12024 set up as a frame pointer, even when there is no alloca call. */
12025 fprintf (file, "%d,",
6041bf2f
DE
12026 ((optional_tbtab << 6)
12027 | ((optional_tbtab & frame_pointer_needed) << 5)
12028 | (info->cr_save_p << 1)
12029 | (info->lr_save_p)));
314fc5a9 12030
6041bf2f 12031 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12032 (6 bits). */
12033 fprintf (file, "%d,",
4697a36c 12034 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12035
12036 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12037 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12038
6041bf2f
DE
12039 if (optional_tbtab)
12040 {
12041 /* Compute the parameter info from the function decl argument
12042 list. */
12043 tree decl;
12044 int next_parm_info_bit = 31;
314fc5a9 12045
6041bf2f
DE
12046 for (decl = DECL_ARGUMENTS (current_function_decl);
12047 decl; decl = TREE_CHAIN (decl))
12048 {
12049 rtx parameter = DECL_INCOMING_RTL (decl);
12050 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12051
6041bf2f
DE
12052 if (GET_CODE (parameter) == REG)
12053 {
12054 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12055 {
12056 int bits;
12057
12058 float_parms++;
12059
12060 if (mode == SFmode)
12061 bits = 0x2;
fcce224d 12062 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12063 bits = 0x3;
12064 else
12065 abort ();
12066
12067 /* If only one bit will fit, don't or in this entry. */
12068 if (next_parm_info_bit > 0)
12069 parm_info |= (bits << (next_parm_info_bit - 1));
12070 next_parm_info_bit -= 2;
12071 }
12072 else
12073 {
12074 fixed_parms += ((GET_MODE_SIZE (mode)
12075 + (UNITS_PER_WORD - 1))
12076 / UNITS_PER_WORD);
12077 next_parm_info_bit -= 1;
12078 }
12079 }
12080 }
12081 }
314fc5a9
ILT
12082
12083 /* Number of fixed point parameters. */
12084 /* This is actually the number of words of fixed point parameters; thus
12085 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12086 fprintf (file, "%d,", fixed_parms);
12087
12088 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12089 all on stack. */
12090 /* This is actually the number of fp registers that hold parameters;
12091 and thus the maximum value is 13. */
12092 /* Set parameters on stack bit if parameters are not in their original
12093 registers, regardless of whether they are on the stack? Xlc
12094 seems to set the bit when not optimizing. */
12095 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12096
6041bf2f
DE
12097 if (! optional_tbtab)
12098 return;
12099
314fc5a9
ILT
12100 /* Optional fields follow. Some are variable length. */
12101
12102 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12103 11 double float. */
12104 /* There is an entry for each parameter in a register, in the order that
12105 they occur in the parameter list. Any intervening arguments on the
12106 stack are ignored. If the list overflows a long (max possible length
12107 34 bits) then completely leave off all elements that don't fit. */
12108 /* Only emit this long if there was at least one parameter. */
12109 if (fixed_parms || float_parms)
12110 fprintf (file, "\t.long %d\n", parm_info);
12111
12112 /* Offset from start of code to tb table. */
19d2d16f 12113 fputs ("\t.long ", file);
314fc5a9 12114 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12115#if TARGET_AIX
12116 RS6000_OUTPUT_BASENAME (file, fname);
12117#else
9ebbca7d 12118 assemble_name (file, fname);
54ee9799 12119#endif
19d2d16f 12120 fputs ("-.", file);
54ee9799
DE
12121#if TARGET_AIX
12122 RS6000_OUTPUT_BASENAME (file, fname);
12123#else
9ebbca7d 12124 assemble_name (file, fname);
54ee9799 12125#endif
19d2d16f 12126 putc ('\n', file);
314fc5a9
ILT
12127
12128 /* Interrupt handler mask. */
12129 /* Omit this long, since we never set the interrupt handler bit
12130 above. */
12131
12132 /* Number of CTL (controlled storage) anchors. */
12133 /* Omit this long, since the has_ctl bit is never set above. */
12134
12135 /* Displacement into stack of each CTL anchor. */
12136 /* Omit this list of longs, because there are no CTL anchors. */
12137
12138 /* Length of function name. */
69c75916
AM
12139 if (*fname == '*')
12140 ++fname;
296b8152 12141 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
12142
12143 /* Function name. */
12144 assemble_string (fname, strlen (fname));
12145
12146 /* Register for alloca automatic storage; this is always reg 31.
12147 Only emit this if the alloca bit was set above. */
12148 if (frame_pointer_needed)
19d2d16f 12149 fputs ("\t.byte 31\n", file);
b1765bde
DE
12150
12151 fputs ("\t.align 2\n", file);
9b30bae2 12152 }
9878760c 12153}
17167fd8 12154\f
a4f6c312
SS
12155/* A C compound statement that outputs the assembler code for a thunk
12156 function, used to implement C++ virtual function calls with
12157 multiple inheritance. The thunk acts as a wrapper around a virtual
12158 function, adjusting the implicit object parameter before handing
12159 control off to the real function.
12160
12161 First, emit code to add the integer DELTA to the location that
12162 contains the incoming first argument. Assume that this argument
12163 contains a pointer, and is the one used to pass the `this' pointer
12164 in C++. This is the incoming argument *before* the function
12165 prologue, e.g. `%o0' on a sparc. The addition must preserve the
12166 values of all other incoming arguments.
17167fd8
MM
12167
12168 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
12169 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
12170 not touch the return address. Hence returning from FUNCTION will
12171 return to whoever called the current `thunk'.
17167fd8 12172
a4f6c312
SS
12173 The effect must be as if FUNCTION had been called directly with the
12174 adjusted first argument. This macro is responsible for emitting
12175 all of the code for a thunk function; output_function_prologue()
12176 and output_function_epilogue() are not invoked.
17167fd8 12177
a4f6c312
SS
12178 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
12179 been extracted from it.) It might possibly be useful on some
12180 targets, but probably not.
17167fd8 12181
a4f6c312
SS
12182 If you do not define this macro, the target-independent code in the
12183 C++ frontend will generate a less efficient heavyweight thunk that
12184 calls FUNCTION instead of jumping to it. The generic approach does
12185 not support varargs. */
17167fd8 12186
3961e8fe 12187static void
a2369ed3
DJ
12188rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
12189 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
12190 tree function)
17167fd8 12191{
5b71a4e7 12192 rtx this, insn, funexp;
17167fd8 12193
5b71a4e7 12194 reload_completed = 1;
fe3ad572 12195 epilogue_completed = 1;
5b71a4e7 12196 no_new_pseudos = 1;
56a7189a 12197
5b71a4e7 12198 /* Mark the end of the (empty) prologue. */
2e040219 12199 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 12200
5b71a4e7
DE
12201 /* Find the "this" pointer. If the function returns a structure,
12202 the structure return pointer is in r3. */
61f71b34 12203 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 12204 this = gen_rtx_REG (Pmode, 4);
56a7189a 12205 else
5b71a4e7 12206 this = gen_rtx_REG (Pmode, 3);
17167fd8 12207
5b71a4e7
DE
12208 /* Apply the constant offset, if required. */
12209 if (delta)
12210 {
12211 rtx delta_rtx = GEN_INT (delta);
12212 emit_insn (TARGET_32BIT
12213 ? gen_addsi3 (this, this, delta_rtx)
12214 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
12215 }
12216
5b71a4e7
DE
12217 /* Apply the offset from the vtable, if required. */
12218 if (vcall_offset)
17167fd8 12219 {
5b71a4e7
DE
12220 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
12221 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 12222
5b71a4e7 12223 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
12224 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
12225 {
12226 emit_insn (TARGET_32BIT
12227 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
12228 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
12229 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
12230 }
12231 else
12232 {
12233 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
12234
12235 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
12236 }
5b71a4e7
DE
12237 emit_insn (TARGET_32BIT
12238 ? gen_addsi3 (this, this, tmp)
12239 : gen_adddi3 (this, this, tmp));
17167fd8
MM
12240 }
12241
5b71a4e7
DE
12242 /* Generate a tail call to the target function. */
12243 if (!TREE_USED (function))
12244 {
12245 assemble_external (function);
12246 TREE_USED (function) = 1;
12247 }
12248 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 12249 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
12250
12251#if TARGET_MACHO
ab82a49f 12252 if (MACHOPIC_INDIRECT)
5b71a4e7 12253 funexp = machopic_indirect_call_target (funexp);
ee890fe2 12254#endif
5b71a4e7
DE
12255
12256 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
12257 generate sibcall RTL explicitly to avoid constraint abort. */
12258 insn = emit_call_insn (
12259 gen_rtx_PARALLEL (VOIDmode,
12260 gen_rtvec (4,
12261 gen_rtx_CALL (VOIDmode,
12262 funexp, const0_rtx),
12263 gen_rtx_USE (VOIDmode, const0_rtx),
12264 gen_rtx_USE (VOIDmode,
12265 gen_rtx_REG (SImode,
12266 LINK_REGISTER_REGNUM)),
12267 gen_rtx_RETURN (VOIDmode))));
12268 SIBLING_CALL_P (insn) = 1;
12269 emit_barrier ();
12270
12271 /* Run just enough of rest_of_compilation to get the insns emitted.
12272 There's not really enough bulk here to make other passes such as
12273 instruction scheduling worth while. Note that use_thunk calls
12274 assemble_start_function and assemble_end_function. */
12275 insn = get_insns ();
a2855205 12276 insn_locators_initialize ();
5b71a4e7
DE
12277 shorten_branches (insn);
12278 final_start_function (insn, file, 1);
12279 final (insn, file, 1, 0);
12280 final_end_function ();
12281
12282 reload_completed = 0;
fe3ad572 12283 epilogue_completed = 0;
5b71a4e7 12284 no_new_pseudos = 0;
9ebbca7d 12285}
9ebbca7d
GK
12286\f
12287/* A quick summary of the various types of 'constant-pool tables'
12288 under PowerPC:
12289
12290 Target Flags Name One table per
12291 AIX (none) AIX TOC object file
12292 AIX -mfull-toc AIX TOC object file
12293 AIX -mminimal-toc AIX minimal TOC translation unit
12294 SVR4/EABI (none) SVR4 SDATA object file
12295 SVR4/EABI -fpic SVR4 pic object file
12296 SVR4/EABI -fPIC SVR4 PIC translation unit
12297 SVR4/EABI -mrelocatable EABI TOC function
12298 SVR4/EABI -maix AIX TOC object file
12299 SVR4/EABI -maix -mminimal-toc
12300 AIX minimal TOC translation unit
12301
12302 Name Reg. Set by entries contains:
12303 made by addrs? fp? sum?
12304
12305 AIX TOC 2 crt0 as Y option option
12306 AIX minimal TOC 30 prolog gcc Y Y option
12307 SVR4 SDATA 13 crt0 gcc N Y N
12308 SVR4 pic 30 prolog ld Y not yet N
12309 SVR4 PIC 30 prolog gcc Y option option
12310 EABI TOC 30 prolog gcc Y option option
12311
12312*/
12313
9ebbca7d
GK
12314/* Hash functions for the hash table. */
12315
12316static unsigned
a2369ed3 12317rs6000_hash_constant (rtx k)
9ebbca7d 12318{
46b33600
RH
12319 enum rtx_code code = GET_CODE (k);
12320 enum machine_mode mode = GET_MODE (k);
12321 unsigned result = (code << 3) ^ mode;
12322 const char *format;
12323 int flen, fidx;
9ebbca7d 12324
46b33600
RH
12325 format = GET_RTX_FORMAT (code);
12326 flen = strlen (format);
12327 fidx = 0;
9ebbca7d 12328
46b33600
RH
12329 switch (code)
12330 {
12331 case LABEL_REF:
12332 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
12333
12334 case CONST_DOUBLE:
12335 if (mode != VOIDmode)
12336 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
12337 flen = 2;
12338 break;
12339
12340 case CODE_LABEL:
12341 fidx = 3;
12342 break;
12343
12344 default:
12345 break;
12346 }
9ebbca7d
GK
12347
12348 for (; fidx < flen; fidx++)
12349 switch (format[fidx])
12350 {
12351 case 's':
12352 {
12353 unsigned i, len;
12354 const char *str = XSTR (k, fidx);
12355 len = strlen (str);
12356 result = result * 613 + len;
12357 for (i = 0; i < len; i++)
12358 result = result * 613 + (unsigned) str[i];
17167fd8
MM
12359 break;
12360 }
9ebbca7d
GK
12361 case 'u':
12362 case 'e':
12363 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
12364 break;
12365 case 'i':
12366 case 'n':
12367 result = result * 613 + (unsigned) XINT (k, fidx);
12368 break;
12369 case 'w':
12370 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
12371 result = result * 613 + (unsigned) XWINT (k, fidx);
12372 else
12373 {
12374 size_t i;
12375 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
12376 result = result * 613 + (unsigned) (XWINT (k, fidx)
12377 >> CHAR_BIT * i);
12378 }
12379 break;
09501938
DE
12380 case '0':
12381 break;
9ebbca7d 12382 default:
a4f6c312 12383 abort ();
9ebbca7d 12384 }
46b33600 12385
9ebbca7d
GK
12386 return result;
12387}
12388
12389static unsigned
a2369ed3 12390toc_hash_function (const void *hash_entry)
9ebbca7d 12391{
a9098fd0
GK
12392 const struct toc_hash_struct *thc =
12393 (const struct toc_hash_struct *) hash_entry;
12394 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
12395}
12396
12397/* Compare H1 and H2 for equivalence. */
12398
12399static int
a2369ed3 12400toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
12401{
12402 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
12403 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
12404
a9098fd0
GK
12405 if (((const struct toc_hash_struct *) h1)->key_mode
12406 != ((const struct toc_hash_struct *) h2)->key_mode)
12407 return 0;
12408
5692c7bc 12409 return rtx_equal_p (r1, r2);
9ebbca7d
GK
12410}
12411
28e510bd
MM
12412/* These are the names given by the C++ front-end to vtables, and
12413 vtable-like objects. Ideally, this logic should not be here;
12414 instead, there should be some programmatic way of inquiring as
12415 to whether or not an object is a vtable. */
12416
12417#define VTABLE_NAME_P(NAME) \
12418 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
12419 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
12420 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
12421 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
12422
12423void
a2369ed3 12424rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
12425{
12426 /* Currently C++ toc references to vtables can be emitted before it
12427 is decided whether the vtable is public or private. If this is
12428 the case, then the linker will eventually complain that there is
12429 a reference to an unknown section. Thus, for vtables only,
12430 we emit the TOC reference to reference the symbol and not the
12431 section. */
12432 const char *name = XSTR (x, 0);
54ee9799
DE
12433
12434 if (VTABLE_NAME_P (name))
12435 {
12436 RS6000_OUTPUT_BASENAME (file, name);
12437 }
12438 else
12439 assemble_name (file, name);
28e510bd
MM
12440}
12441
a4f6c312
SS
12442/* Output a TOC entry. We derive the entry name from what is being
12443 written. */
9878760c
RK
12444
12445void
a2369ed3 12446output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
12447{
12448 char buf[256];
3cce094d 12449 const char *name = buf;
ec940faa 12450 const char *real_name;
9878760c
RK
12451 rtx base = x;
12452 int offset = 0;
12453
4697a36c
MM
12454 if (TARGET_NO_TOC)
12455 abort ();
12456
9ebbca7d
GK
12457 /* When the linker won't eliminate them, don't output duplicate
12458 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
12459 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
12460 CODE_LABELs. */
12461 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
12462 {
12463 struct toc_hash_struct *h;
12464 void * * found;
12465
17211ab5 12466 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 12467 time because GGC is not initialized at that point. */
17211ab5
GK
12468 if (toc_hash_table == NULL)
12469 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
12470 toc_hash_eq, NULL);
12471
9ebbca7d
GK
12472 h = ggc_alloc (sizeof (*h));
12473 h->key = x;
a9098fd0 12474 h->key_mode = mode;
9ebbca7d
GK
12475 h->labelno = labelno;
12476
12477 found = htab_find_slot (toc_hash_table, h, 1);
12478 if (*found == NULL)
12479 *found = h;
12480 else /* This is indeed a duplicate.
12481 Set this label equal to that label. */
12482 {
12483 fputs ("\t.set ", file);
12484 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
12485 fprintf (file, "%d,", labelno);
12486 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
12487 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
12488 found)->labelno));
12489 return;
12490 }
12491 }
12492
12493 /* If we're going to put a double constant in the TOC, make sure it's
12494 aligned properly when strict alignment is on. */
ff1720ed
RK
12495 if (GET_CODE (x) == CONST_DOUBLE
12496 && STRICT_ALIGNMENT
a9098fd0 12497 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
12498 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
12499 ASM_OUTPUT_ALIGN (file, 3);
12500 }
12501
4977bab6 12502 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 12503
37c37a57
RK
12504 /* Handle FP constants specially. Note that if we have a minimal
12505 TOC, things we put here aren't actually in the TOC, so we can allow
12506 FP constants. */
fcce224d
DE
12507 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
12508 {
12509 REAL_VALUE_TYPE rv;
12510 long k[4];
12511
12512 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12513 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
12514
12515 if (TARGET_64BIT)
12516 {
12517 if (TARGET_MINIMAL_TOC)
12518 fputs (DOUBLE_INT_ASM_OP, file);
12519 else
12520 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
12521 k[0] & 0xffffffff, k[1] & 0xffffffff,
12522 k[2] & 0xffffffff, k[3] & 0xffffffff);
12523 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
12524 k[0] & 0xffffffff, k[1] & 0xffffffff,
12525 k[2] & 0xffffffff, k[3] & 0xffffffff);
12526 return;
12527 }
12528 else
12529 {
12530 if (TARGET_MINIMAL_TOC)
12531 fputs ("\t.long ", file);
12532 else
12533 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
12534 k[0] & 0xffffffff, k[1] & 0xffffffff,
12535 k[2] & 0xffffffff, k[3] & 0xffffffff);
12536 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
12537 k[0] & 0xffffffff, k[1] & 0xffffffff,
12538 k[2] & 0xffffffff, k[3] & 0xffffffff);
12539 return;
12540 }
12541 }
12542 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 12543 {
042259f2
DE
12544 REAL_VALUE_TYPE rv;
12545 long k[2];
0adc764e 12546
042259f2
DE
12547 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12548 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 12549
13ded975
DE
12550 if (TARGET_64BIT)
12551 {
12552 if (TARGET_MINIMAL_TOC)
2bfcf297 12553 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12554 else
2f0552b6
AM
12555 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
12556 k[0] & 0xffffffff, k[1] & 0xffffffff);
12557 fprintf (file, "0x%lx%08lx\n",
12558 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
12559 return;
12560 }
1875cc88 12561 else
13ded975
DE
12562 {
12563 if (TARGET_MINIMAL_TOC)
2bfcf297 12564 fputs ("\t.long ", file);
13ded975 12565 else
2f0552b6
AM
12566 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
12567 k[0] & 0xffffffff, k[1] & 0xffffffff);
12568 fprintf (file, "0x%lx,0x%lx\n",
12569 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
12570 return;
12571 }
9878760c 12572 }
a9098fd0 12573 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 12574 {
042259f2
DE
12575 REAL_VALUE_TYPE rv;
12576 long l;
9878760c 12577
042259f2
DE
12578 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
12579 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
12580
31bfaa0b
DE
12581 if (TARGET_64BIT)
12582 {
12583 if (TARGET_MINIMAL_TOC)
2bfcf297 12584 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 12585 else
2f0552b6
AM
12586 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
12587 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
12588 return;
12589 }
042259f2 12590 else
31bfaa0b
DE
12591 {
12592 if (TARGET_MINIMAL_TOC)
2bfcf297 12593 fputs ("\t.long ", file);
31bfaa0b 12594 else
2f0552b6
AM
12595 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
12596 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
12597 return;
12598 }
042259f2 12599 }
f176e826 12600 else if (GET_MODE (x) == VOIDmode
a9098fd0 12601 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 12602 {
e2c953b6 12603 unsigned HOST_WIDE_INT low;
042259f2
DE
12604 HOST_WIDE_INT high;
12605
12606 if (GET_CODE (x) == CONST_DOUBLE)
12607 {
12608 low = CONST_DOUBLE_LOW (x);
12609 high = CONST_DOUBLE_HIGH (x);
12610 }
12611 else
12612#if HOST_BITS_PER_WIDE_INT == 32
12613 {
12614 low = INTVAL (x);
0858c623 12615 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
12616 }
12617#else
12618 {
0858c623 12619 low = INTVAL (x) & 0xffffffff;
042259f2
DE
12620 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
12621 }
12622#endif
9878760c 12623
a9098fd0
GK
12624 /* TOC entries are always Pmode-sized, but since this
12625 is a bigendian machine then if we're putting smaller
12626 integer constants in the TOC we have to pad them.
12627 (This is still a win over putting the constants in
12628 a separate constant pool, because then we'd have
02a4ec28
FS
12629 to have both a TOC entry _and_ the actual constant.)
12630
12631 For a 32-bit target, CONST_INT values are loaded and shifted
12632 entirely within `low' and can be stored in one TOC entry. */
12633
12634 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 12635 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
12636
12637 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
12638 {
12639#if HOST_BITS_PER_WIDE_INT == 32
12640 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
12641 POINTER_SIZE, &low, &high, 0);
12642#else
12643 low |= high << 32;
12644 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
12645 high = (HOST_WIDE_INT) low >> 32;
12646 low &= 0xffffffff;
12647#endif
12648 }
a9098fd0 12649
13ded975
DE
12650 if (TARGET_64BIT)
12651 {
12652 if (TARGET_MINIMAL_TOC)
2bfcf297 12653 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12654 else
2f0552b6
AM
12655 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
12656 (long) high & 0xffffffff, (long) low & 0xffffffff);
12657 fprintf (file, "0x%lx%08lx\n",
12658 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
12659 return;
12660 }
1875cc88 12661 else
13ded975 12662 {
02a4ec28
FS
12663 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
12664 {
12665 if (TARGET_MINIMAL_TOC)
2bfcf297 12666 fputs ("\t.long ", file);
02a4ec28 12667 else
2bfcf297 12668 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
12669 (long) high & 0xffffffff, (long) low & 0xffffffff);
12670 fprintf (file, "0x%lx,0x%lx\n",
12671 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 12672 }
13ded975 12673 else
02a4ec28
FS
12674 {
12675 if (TARGET_MINIMAL_TOC)
2bfcf297 12676 fputs ("\t.long ", file);
02a4ec28 12677 else
2f0552b6
AM
12678 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
12679 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 12680 }
13ded975
DE
12681 return;
12682 }
9878760c
RK
12683 }
12684
12685 if (GET_CODE (x) == CONST)
12686 {
2bfcf297
DB
12687 if (GET_CODE (XEXP (x, 0)) != PLUS)
12688 abort ();
12689
9878760c
RK
12690 base = XEXP (XEXP (x, 0), 0);
12691 offset = INTVAL (XEXP (XEXP (x, 0), 1));
12692 }
12693
12694 if (GET_CODE (base) == SYMBOL_REF)
12695 name = XSTR (base, 0);
12696 else if (GET_CODE (base) == LABEL_REF)
12697 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
12698 else if (GET_CODE (base) == CODE_LABEL)
12699 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
12700 else
12701 abort ();
12702
772c5265 12703 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 12704 if (TARGET_MINIMAL_TOC)
2bfcf297 12705 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
12706 else
12707 {
b6c9286a 12708 fprintf (file, "\t.tc %s", real_name);
9878760c 12709
1875cc88
JW
12710 if (offset < 0)
12711 fprintf (file, ".N%d", - offset);
12712 else if (offset)
12713 fprintf (file, ".P%d", offset);
9878760c 12714
19d2d16f 12715 fputs ("[TC],", file);
1875cc88 12716 }
581bc4de
MM
12717
12718 /* Currently C++ toc references to vtables can be emitted before it
12719 is decided whether the vtable is public or private. If this is
12720 the case, then the linker will eventually complain that there is
12721 a TOC reference to an unknown section. Thus, for vtables only,
12722 we emit the TOC reference to reference the symbol and not the
12723 section. */
28e510bd 12724 if (VTABLE_NAME_P (name))
581bc4de 12725 {
54ee9799 12726 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
12727 if (offset < 0)
12728 fprintf (file, "%d", offset);
12729 else if (offset > 0)
12730 fprintf (file, "+%d", offset);
12731 }
12732 else
12733 output_addr_const (file, x);
19d2d16f 12734 putc ('\n', file);
9878760c
RK
12735}
12736\f
12737/* Output an assembler pseudo-op to write an ASCII string of N characters
12738 starting at P to FILE.
12739
12740 On the RS/6000, we have to do this using the .byte operation and
12741 write out special characters outside the quoted string.
12742 Also, the assembler is broken; very long strings are truncated,
a4f6c312 12743 so we must artificially break them up early. */
9878760c
RK
12744
12745void
a2369ed3 12746output_ascii (FILE *file, const char *p, int n)
9878760c
RK
12747{
12748 char c;
12749 int i, count_string;
d330fd93
KG
12750 const char *for_string = "\t.byte \"";
12751 const char *for_decimal = "\t.byte ";
12752 const char *to_close = NULL;
9878760c
RK
12753
12754 count_string = 0;
12755 for (i = 0; i < n; i++)
12756 {
12757 c = *p++;
12758 if (c >= ' ' && c < 0177)
12759 {
12760 if (for_string)
12761 fputs (for_string, file);
12762 putc (c, file);
12763
12764 /* Write two quotes to get one. */
12765 if (c == '"')
12766 {
12767 putc (c, file);
12768 ++count_string;
12769 }
12770
12771 for_string = NULL;
12772 for_decimal = "\"\n\t.byte ";
12773 to_close = "\"\n";
12774 ++count_string;
12775
12776 if (count_string >= 512)
12777 {
12778 fputs (to_close, file);
12779
12780 for_string = "\t.byte \"";
12781 for_decimal = "\t.byte ";
12782 to_close = NULL;
12783 count_string = 0;
12784 }
12785 }
12786 else
12787 {
12788 if (for_decimal)
12789 fputs (for_decimal, file);
12790 fprintf (file, "%d", c);
12791
12792 for_string = "\n\t.byte \"";
12793 for_decimal = ", ";
12794 to_close = "\n";
12795 count_string = 0;
12796 }
12797 }
12798
12799 /* Now close the string if we have written one. Then end the line. */
12800 if (to_close)
9ebbca7d 12801 fputs (to_close, file);
9878760c
RK
12802}
12803\f
12804/* Generate a unique section name for FILENAME for a section type
12805 represented by SECTION_DESC. Output goes into BUF.
12806
12807 SECTION_DESC can be any string, as long as it is different for each
12808 possible section type.
12809
12810 We name the section in the same manner as xlc. The name begins with an
12811 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
12812 names) with the last period replaced by the string SECTION_DESC. If
12813 FILENAME does not contain a period, SECTION_DESC is appended to the end of
12814 the name. */
9878760c
RK
12815
12816void
a2369ed3
DJ
12817rs6000_gen_section_name (char **buf, const char *filename,
12818 const char *section_desc)
9878760c 12819{
9ebbca7d 12820 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
12821 char *p;
12822 int len;
9878760c
RK
12823
12824 after_last_slash = filename;
12825 for (q = filename; *q; q++)
11e5fe42
RK
12826 {
12827 if (*q == '/')
12828 after_last_slash = q + 1;
12829 else if (*q == '.')
12830 last_period = q;
12831 }
9878760c 12832
11e5fe42 12833 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 12834 *buf = (char *) xmalloc (len);
9878760c
RK
12835
12836 p = *buf;
12837 *p++ = '_';
12838
12839 for (q = after_last_slash; *q; q++)
12840 {
11e5fe42 12841 if (q == last_period)
9878760c
RK
12842 {
12843 strcpy (p, section_desc);
12844 p += strlen (section_desc);
e3981aab 12845 break;
9878760c
RK
12846 }
12847
e9a780ec 12848 else if (ISALNUM (*q))
9878760c
RK
12849 *p++ = *q;
12850 }
12851
11e5fe42 12852 if (last_period == 0)
9878760c
RK
12853 strcpy (p, section_desc);
12854 else
12855 *p = '\0';
12856}
e165f3f0 12857\f
a4f6c312 12858/* Emit profile function. */
411707f4 12859
411707f4 12860void
a2369ed3 12861output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 12862{
ffcfcb5f
AM
12863 if (TARGET_PROFILE_KERNEL)
12864 return;
12865
8480e480
CC
12866 if (DEFAULT_ABI == ABI_AIX)
12867 {
9739c90c
JJ
12868#ifndef NO_PROFILE_COUNTERS
12869# define NO_PROFILE_COUNTERS 0
12870#endif
12871 if (NO_PROFILE_COUNTERS)
12872 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
12873 else
12874 {
12875 char buf[30];
12876 const char *label_name;
12877 rtx fun;
411707f4 12878
9739c90c
JJ
12879 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
12880 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
12881 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 12882
9739c90c
JJ
12883 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
12884 fun, Pmode);
12885 }
8480e480 12886 }
ee890fe2
SS
12887 else if (DEFAULT_ABI == ABI_DARWIN)
12888 {
d5fa86ba 12889 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
12890 int caller_addr_regno = LINK_REGISTER_REGNUM;
12891
12892 /* Be conservative and always set this, at least for now. */
12893 current_function_uses_pic_offset_table = 1;
12894
12895#if TARGET_MACHO
12896 /* For PIC code, set up a stub and collect the caller's address
12897 from r0, which is where the prologue puts it. */
ab82a49f 12898 if (MACHOPIC_INDIRECT)
ee890fe2
SS
12899 {
12900 mcount_name = machopic_stub_name (mcount_name);
12901 if (current_function_uses_pic_offset_table)
12902 caller_addr_regno = 0;
12903 }
12904#endif
12905 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
12906 0, VOIDmode, 1,
12907 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
12908 }
411707f4
CC
12909}
12910
a4f6c312 12911/* Write function profiler code. */
e165f3f0
RK
12912
12913void
a2369ed3 12914output_function_profiler (FILE *file, int labelno)
e165f3f0 12915{
3daf36a4 12916 char buf[100];
09eeeacb 12917 int save_lr = 8;
e165f3f0 12918
38c1f2d7 12919 switch (DEFAULT_ABI)
3daf36a4 12920 {
38c1f2d7
MM
12921 default:
12922 abort ();
12923
12924 case ABI_V4:
09eeeacb 12925 save_lr = 4;
09eeeacb
AM
12926 if (!TARGET_32BIT)
12927 {
12928 warning ("no profiling of 64-bit code for this ABI");
12929 return;
12930 }
ffcfcb5f 12931 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
12932 fprintf (file, "\tmflr %s\n", reg_names[0]);
12933 if (flag_pic == 1)
12934 {
dfdfa60f 12935 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
12936 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12937 reg_names[0], save_lr, reg_names[1]);
17167fd8 12938 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 12939 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 12940 assemble_name (file, buf);
17167fd8 12941 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 12942 }
9ebbca7d 12943 else if (flag_pic > 1)
38c1f2d7 12944 {
09eeeacb
AM
12945 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12946 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
12947 /* Now, we need to get the address of the label. */
12948 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 12949 assemble_name (file, buf);
9ebbca7d
GK
12950 fputs ("-.\n1:", file);
12951 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
12952 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
12953 reg_names[0], reg_names[11]);
12954 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
12955 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 12956 }
38c1f2d7
MM
12957 else
12958 {
17167fd8 12959 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 12960 assemble_name (file, buf);
dfdfa60f 12961 fputs ("@ha\n", file);
09eeeacb
AM
12962 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12963 reg_names[0], save_lr, reg_names[1]);
a260abc9 12964 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 12965 assemble_name (file, buf);
17167fd8 12966 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
12967 }
12968
50d440bc
NC
12969 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
12970 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
12971 break;
12972
12973 case ABI_AIX:
ee890fe2 12974 case ABI_DARWIN:
ffcfcb5f
AM
12975 if (!TARGET_PROFILE_KERNEL)
12976 {
12977 /* Don't do anything, done in output_profile_hook (). */
12978 }
12979 else
12980 {
12981 if (TARGET_32BIT)
12982 abort ();
12983
12984 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
12985 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
12986
12987 if (current_function_needs_context)
12988 {
12989 asm_fprintf (file, "\tstd %s,24(%s)\n",
12990 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
12991 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
12992 asm_fprintf (file, "\tld %s,24(%s)\n",
12993 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
12994 }
12995 else
12996 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
12997 }
38c1f2d7
MM
12998 break;
12999 }
e165f3f0 13000}
a251ffd0 13001
b54cf83a
DE
13002\f
13003static int
863d938c 13004rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13005{
13006 return 1;
13007}
13008
b54cf83a
DE
13009/* Power4 load update and store update instructions are cracked into a
13010 load or store and an integer insn which are executed in the same cycle.
13011 Branches have their own dispatch slot which does not count against the
13012 GCC issue rate, but it changes the program flow so there are no other
13013 instructions to issue in this cycle. */
13014
13015static int
a2369ed3
DJ
13016rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13017 int verbose ATTRIBUTE_UNUSED,
13018 rtx insn, int more)
b54cf83a
DE
13019{
13020 if (GET_CODE (PATTERN (insn)) == USE
13021 || GET_CODE (PATTERN (insn)) == CLOBBER)
13022 return more;
13023
13024 if (rs6000_cpu == PROCESSOR_POWER4)
13025 {
13026 enum attr_type type = get_attr_type (insn);
13027 if (type == TYPE_LOAD_EXT_U || type == TYPE_LOAD_EXT_UX
2c4a9cff
DE
13028 || type == TYPE_LOAD_UX || type == TYPE_STORE_UX
13029 || type == TYPE_MFCR)
b54cf83a
DE
13030 return 0;
13031 else if (type == TYPE_LOAD_U || type == TYPE_STORE_U
13032 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
9259f3b0
DE
13033 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
13034 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
13035 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
13036 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
8e8238f1
DE
13037 || type == TYPE_IDIV || type == TYPE_LDIV
13038 || type == TYPE_INSERT_WORD)
3317bab1 13039 return more > 2 ? more - 2 : 0;
b54cf83a 13040 }
165b263e
DE
13041
13042 return more - 1;
b54cf83a
DE
13043}
13044
a251ffd0
TG
13045/* Adjust the cost of a scheduling dependency. Return the new cost of
13046 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13047
c237e94a 13048static int
a2369ed3
DJ
13049rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13050 int cost)
a251ffd0
TG
13051{
13052 if (! recog_memoized (insn))
13053 return 0;
13054
13055 if (REG_NOTE_KIND (link) != 0)
13056 return 0;
13057
13058 if (REG_NOTE_KIND (link) == 0)
13059 {
ed947a96
DJ
13060 /* Data dependency; DEP_INSN writes a register that INSN reads
13061 some cycles later. */
13062 switch (get_attr_type (insn))
13063 {
13064 case TYPE_JMPREG:
309323c2 13065 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13066 a mtctr and bctr (and mtlr and br/blr). The first
13067 scheduling pass will not know about this latency since
13068 the mtctr instruction, which has the latency associated
13069 to it, will be generated by reload. */
309323c2 13070 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13071 case TYPE_BRANCH:
13072 /* Leave some extra cycles between a compare and its
13073 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13074 if ((rs6000_cpu_attr == CPU_PPC603
13075 || rs6000_cpu_attr == CPU_PPC604
13076 || rs6000_cpu_attr == CPU_PPC604E
13077 || rs6000_cpu_attr == CPU_PPC620
13078 || rs6000_cpu_attr == CPU_PPC630
13079 || rs6000_cpu_attr == CPU_PPC750
13080 || rs6000_cpu_attr == CPU_PPC7400
13081 || rs6000_cpu_attr == CPU_PPC7450
13082 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13083 && recog_memoized (dep_insn)
13084 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13085 && (get_attr_type (dep_insn) == TYPE_CMP
13086 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13087 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13088 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13089 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13090 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13091 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13092 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13093 return cost + 2;
13094 default:
13095 break;
13096 }
a251ffd0
TG
13097 /* Fall out to return default cost. */
13098 }
13099
13100 return cost;
13101}
b6c9286a 13102
a4f6c312
SS
13103/* A C statement (sans semicolon) to update the integer scheduling
13104 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
13105 INSN earlier, increase the priority to execute INSN later. Do not
13106 define this macro if you do not need to adjust the scheduling
13107 priorities of insns. */
bef84347 13108
c237e94a 13109static int
a2369ed3 13110rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 13111{
a4f6c312
SS
13112 /* On machines (like the 750) which have asymmetric integer units,
13113 where one integer unit can do multiply and divides and the other
13114 can't, reduce the priority of multiply/divide so it is scheduled
13115 before other integer operations. */
bef84347
VM
13116
13117#if 0
2c3c49de 13118 if (! INSN_P (insn))
bef84347
VM
13119 return priority;
13120
13121 if (GET_CODE (PATTERN (insn)) == USE)
13122 return priority;
13123
13124 switch (rs6000_cpu_attr) {
13125 case CPU_PPC750:
13126 switch (get_attr_type (insn))
13127 {
13128 default:
13129 break;
13130
13131 case TYPE_IMUL:
13132 case TYPE_IDIV:
3cb999d8
DE
13133 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
13134 priority, priority);
bef84347
VM
13135 if (priority >= 0 && priority < 0x01000000)
13136 priority >>= 3;
13137 break;
13138 }
13139 }
13140#endif
13141
13142 return priority;
13143}
13144
a4f6c312
SS
13145/* Return how many instructions the machine can issue per cycle. */
13146
c237e94a 13147static int
863d938c 13148rs6000_issue_rate (void)
b6c9286a 13149{
3317bab1
DE
13150 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
13151 if (!reload_completed)
13152 return 1;
13153
b6c9286a 13154 switch (rs6000_cpu_attr) {
3cb999d8
DE
13155 case CPU_RIOS1: /* ? */
13156 case CPU_RS64A:
13157 case CPU_PPC601: /* ? */
ed947a96 13158 case CPU_PPC7450:
3cb999d8 13159 return 3;
b54cf83a 13160 case CPU_PPC440:
b6c9286a 13161 case CPU_PPC603:
bef84347 13162 case CPU_PPC750:
ed947a96 13163 case CPU_PPC7400:
be12c2b0 13164 case CPU_PPC8540:
bef84347 13165 return 2;
3cb999d8 13166 case CPU_RIOS2:
b6c9286a 13167 case CPU_PPC604:
19684119 13168 case CPU_PPC604E:
b6c9286a 13169 case CPU_PPC620:
3cb999d8 13170 case CPU_PPC630:
309323c2 13171 case CPU_POWER4:
b6c9286a
MM
13172 return 4;
13173 default:
13174 return 1;
13175 }
13176}
13177
be12c2b0
VM
13178/* Return how many instructions to look ahead for better insn
13179 scheduling. */
13180
13181static int
863d938c 13182rs6000_use_sched_lookahead (void)
be12c2b0
VM
13183{
13184 if (rs6000_cpu_attr == CPU_PPC8540)
13185 return 4;
13186 return 0;
13187}
13188
b6c9286a 13189\f
b6c9286a
MM
13190/* Length in units of the trampoline for entering a nested function. */
13191
13192int
863d938c 13193rs6000_trampoline_size (void)
b6c9286a
MM
13194{
13195 int ret = 0;
13196
13197 switch (DEFAULT_ABI)
13198 {
13199 default:
13200 abort ();
13201
13202 case ABI_AIX:
8f802bfb 13203 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
13204 break;
13205
4dabc42d 13206 case ABI_DARWIN:
b6c9286a 13207 case ABI_V4:
03a7e1a5 13208 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 13209 break;
b6c9286a
MM
13210 }
13211
13212 return ret;
13213}
13214
13215/* Emit RTL insns to initialize the variable parts of a trampoline.
13216 FNADDR is an RTX for the address of the function's pure code.
13217 CXT is an RTX for the static chain value for the function. */
13218
13219void
a2369ed3 13220rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 13221{
ac2a93a1 13222 enum machine_mode pmode = Pmode;
8bd04c56
MM
13223 int regsize = (TARGET_32BIT) ? 4 : 8;
13224 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
13225
13226 switch (DEFAULT_ABI)
13227 {
13228 default:
13229 abort ();
13230
8bd04c56 13231/* Macros to shorten the code expansions below. */
39403d82 13232#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
13233#define MEM_PLUS(addr,offset) \
13234 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 13235
b6c9286a
MM
13236 /* Under AIX, just build the 3 word function descriptor */
13237 case ABI_AIX:
8bd04c56
MM
13238 {
13239 rtx fn_reg = gen_reg_rtx (pmode);
13240 rtx toc_reg = gen_reg_rtx (pmode);
13241 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 13242 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
13243 emit_move_insn (MEM_DEREF (addr), fn_reg);
13244 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
13245 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
13246 }
b6c9286a
MM
13247 break;
13248
4dabc42d
TC
13249 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
13250 case ABI_DARWIN:
b6c9286a 13251 case ABI_V4:
39403d82 13252 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
13253 FALSE, VOIDmode, 4,
13254 addr, pmode,
13255 GEN_INT (rs6000_trampoline_size ()), SImode,
13256 fnaddr, pmode,
13257 ctx_reg, pmode);
b6c9286a 13258 break;
b6c9286a
MM
13259 }
13260
13261 return;
13262}
7509c759
MM
13263
13264\f
91d231cb 13265/* Table of valid machine attributes. */
a4f6c312 13266
91d231cb 13267const struct attribute_spec rs6000_attribute_table[] =
7509c759 13268{
91d231cb 13269 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
13270 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
13271 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
13272 { NULL, 0, 0, false, false, false, NULL }
91d231cb 13273};
7509c759 13274
a5c76ee6
ZW
13275/* Handle a "longcall" or "shortcall" attribute; arguments as in
13276 struct attribute_spec.handler. */
a4f6c312 13277
91d231cb 13278static tree
a2369ed3
DJ
13279rs6000_handle_longcall_attribute (tree *node, tree name,
13280 tree args ATTRIBUTE_UNUSED,
13281 int flags ATTRIBUTE_UNUSED,
13282 bool *no_add_attrs)
91d231cb
JM
13283{
13284 if (TREE_CODE (*node) != FUNCTION_TYPE
13285 && TREE_CODE (*node) != FIELD_DECL
13286 && TREE_CODE (*node) != TYPE_DECL)
13287 {
13288 warning ("`%s' attribute only applies to functions",
13289 IDENTIFIER_POINTER (name));
13290 *no_add_attrs = true;
13291 }
6a4cee5f 13292
91d231cb 13293 return NULL_TREE;
7509c759
MM
13294}
13295
a5c76ee6
ZW
13296/* Set longcall attributes on all functions declared when
13297 rs6000_default_long_calls is true. */
13298static void
a2369ed3 13299rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
13300{
13301 if (rs6000_default_long_calls
13302 && (TREE_CODE (type) == FUNCTION_TYPE
13303 || TREE_CODE (type) == METHOD_TYPE))
13304 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
13305 NULL_TREE,
13306 TYPE_ATTRIBUTES (type));
13307}
13308
3cb999d8
DE
13309/* Return a reference suitable for calling a function with the
13310 longcall attribute. */
a4f6c312 13311
6a4cee5f 13312struct rtx_def *
a2369ed3 13313rs6000_longcall_ref (rtx call_ref)
6a4cee5f 13314{
d330fd93 13315 const char *call_name;
6a4cee5f
MM
13316 tree node;
13317
13318 if (GET_CODE (call_ref) != SYMBOL_REF)
13319 return call_ref;
13320
13321 /* System V adds '.' to the internal name, so skip them. */
13322 call_name = XSTR (call_ref, 0);
13323 if (*call_name == '.')
13324 {
13325 while (*call_name == '.')
13326 call_name++;
13327
13328 node = get_identifier (call_name);
39403d82 13329 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
13330 }
13331
13332 return force_reg (Pmode, call_ref);
13333}
7509c759 13334\f
b64a1b53
RH
13335#ifdef USING_ELFOS_H
13336
7509c759
MM
13337/* A C statement or statements to switch to the appropriate section
13338 for output of RTX in mode MODE. You can assume that RTX is some
13339 kind of constant in RTL. The argument MODE is redundant except in
13340 the case of a `const_int' rtx. Select the section by calling
13341 `text_section' or one of the alternatives for other sections.
13342
13343 Do not define this macro if you put all constants in the read-only
13344 data section. */
13345
b64a1b53 13346static void
a2369ed3
DJ
13347rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
13348 unsigned HOST_WIDE_INT align)
7509c759 13349{
a9098fd0 13350 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 13351 toc_section ();
7509c759 13352 else
b64a1b53 13353 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
13354}
13355
13356/* A C statement or statements to switch to the appropriate
13357 section for output of DECL. DECL is either a `VAR_DECL' node
13358 or a constant of some sort. RELOC indicates whether forming
13359 the initial value of DECL requires link-time relocations. */
13360
ae46c4e0 13361static void
a2369ed3
DJ
13362rs6000_elf_select_section (tree decl, int reloc,
13363 unsigned HOST_WIDE_INT align)
7509c759 13364{
f1384257
AM
13365 /* Pretend that we're always building for a shared library when
13366 ABI_AIX, because otherwise we end up with dynamic relocations
13367 in read-only sections. This happens for function pointers,
13368 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
13369 default_elf_select_section_1 (decl, reloc, align,
13370 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
13371}
13372
13373/* A C statement to build up a unique section name, expressed as a
13374 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
13375 RELOC indicates whether the initial value of EXP requires
13376 link-time relocations. If you do not define this macro, GCC will use
13377 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 13378 macro can now be called for uninitialized data items as well as
4912a07c 13379 initialized data and functions. */
63019373 13380
ae46c4e0 13381static void
a2369ed3 13382rs6000_elf_unique_section (tree decl, int reloc)
63019373 13383{
f1384257
AM
13384 /* As above, pretend that we're always building for a shared library
13385 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
13386 default_unique_section_1 (decl, reloc,
13387 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 13388}
d9407988 13389\f
d1908feb
JJ
13390/* For a SYMBOL_REF, set generic flags and then perform some
13391 target-specific processing.
13392
d1908feb
JJ
13393 When the AIX ABI is requested on a non-AIX system, replace the
13394 function name with the real name (with a leading .) rather than the
13395 function descriptor name. This saves a lot of overriding code to
13396 read the prefixes. */
d9407988 13397
fb49053f 13398static void
a2369ed3 13399rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 13400{
d1908feb 13401 default_encode_section_info (decl, rtl, first);
b2003250 13402
d1908feb
JJ
13403 if (first
13404 && TREE_CODE (decl) == FUNCTION_DECL
13405 && !TARGET_AIX
13406 && DEFAULT_ABI == ABI_AIX)
d9407988 13407 {
c6a2438a 13408 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
13409 size_t len = strlen (XSTR (sym_ref, 0));
13410 char *str = alloca (len + 2);
13411 str[0] = '.';
13412 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
13413 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 13414 }
d9407988
MM
13415}
13416
0e5dbd9b 13417static bool
a2369ed3 13418rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
13419{
13420 if (rs6000_sdata == SDATA_NONE)
13421 return false;
13422
13423 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
13424 {
13425 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
13426 if (strcmp (section, ".sdata") == 0
13427 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
13428 || strcmp (section, ".sbss") == 0
13429 || strcmp (section, ".sbss2") == 0
13430 || strcmp (section, ".PPC.EMB.sdata0") == 0
13431 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
13432 return true;
13433 }
13434 else
13435 {
13436 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
13437
13438 if (size > 0
307b599c 13439 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
13440 /* If it's not public, and we're not going to reference it there,
13441 there's no need to put it in the small data section. */
0e5dbd9b
DE
13442 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
13443 return true;
13444 }
13445
13446 return false;
13447}
13448
b91da81f 13449#endif /* USING_ELFOS_H */
000034eb 13450
a6c2a102 13451\f
000034eb 13452/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
13453 ADDR can be effectively incremented by incrementing REG.
13454
13455 r0 is special and we must not select it as an address
13456 register by this routine since our caller will try to
13457 increment the returned register via an "la" instruction. */
000034eb
DE
13458
13459struct rtx_def *
a2369ed3 13460find_addr_reg (rtx addr)
000034eb
DE
13461{
13462 while (GET_CODE (addr) == PLUS)
13463 {
02441cd6
JL
13464 if (GET_CODE (XEXP (addr, 0)) == REG
13465 && REGNO (XEXP (addr, 0)) != 0)
000034eb 13466 addr = XEXP (addr, 0);
02441cd6
JL
13467 else if (GET_CODE (XEXP (addr, 1)) == REG
13468 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
13469 addr = XEXP (addr, 1);
13470 else if (CONSTANT_P (XEXP (addr, 0)))
13471 addr = XEXP (addr, 1);
13472 else if (CONSTANT_P (XEXP (addr, 1)))
13473 addr = XEXP (addr, 0);
13474 else
13475 abort ();
13476 }
02441cd6 13477 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
13478 return addr;
13479 abort ();
13480}
13481
a6c2a102 13482void
a2369ed3 13483rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
13484{
13485 fatal_insn ("bad address", op);
13486}
c8023011 13487
ee890fe2
SS
13488#if TARGET_MACHO
13489
13490#if 0
13491/* Returns 1 if OP is either a symbol reference or a sum of a symbol
13492 reference and a constant. */
13493
13494int
a2369ed3 13495symbolic_operand (rtx op)
ee890fe2
SS
13496{
13497 switch (GET_CODE (op))
13498 {
13499 case SYMBOL_REF:
13500 case LABEL_REF:
13501 return 1;
13502 case CONST:
13503 op = XEXP (op, 0);
13504 return (GET_CODE (op) == SYMBOL_REF ||
13505 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
13506 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
13507 && GET_CODE (XEXP (op, 1)) == CONST_INT);
13508 default:
13509 return 0;
13510 }
c8023011 13511}
ee890fe2
SS
13512#endif
13513
13514#ifdef RS6000_LONG_BRANCH
13515
13516static tree stub_list = 0;
13517
13518/* ADD_COMPILER_STUB adds the compiler generated stub for handling
13519 procedure calls to the linked list. */
13520
13521void
a2369ed3 13522add_compiler_stub (tree label_name, tree function_name, int line_number)
ee890fe2
SS
13523{
13524 tree stub = build_tree_list (function_name, label_name);
13525 TREE_TYPE (stub) = build_int_2 (line_number, 0);
13526 TREE_CHAIN (stub) = stub_list;
13527 stub_list = stub;
13528}
13529
13530#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
13531#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
13532#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
13533
a4f6c312
SS
13534/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
13535 handling procedure calls from the linked list and initializes the
13536 linked list. */
ee890fe2 13537
a4f6c312 13538void
863d938c 13539output_compiler_stub (void)
ee890fe2
SS
13540{
13541 char tmp_buf[256];
13542 char label_buf[256];
308c142a 13543 tree stub;
ee890fe2
SS
13544
13545 if (!flag_pic)
13546 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13547 {
13548 fprintf (asm_out_file,
13549 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
13550
13551#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
13552 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
13553 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
13554#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
13555
13556 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
13557 strcpy (label_buf,
13558 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
13559 else
13560 {
13561 label_buf[0] = '_';
13562 strcpy (label_buf+1,
13563 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
13564 }
13565
13566 strcpy (tmp_buf, "lis r12,hi16(");
13567 strcat (tmp_buf, label_buf);
13568 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
13569 strcat (tmp_buf, label_buf);
13570 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
13571 output_asm_insn (tmp_buf, 0);
13572
13573#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
13574 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
13575 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
13576#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
13577 }
13578
13579 stub_list = 0;
13580}
13581
13582/* NO_PREVIOUS_DEF checks in the link list whether the function name is
13583 already there or not. */
13584
a4f6c312 13585int
a2369ed3 13586no_previous_def (tree function_name)
ee890fe2
SS
13587{
13588 tree stub;
13589 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13590 if (function_name == STUB_FUNCTION_NAME (stub))
13591 return 0;
13592 return 1;
13593}
13594
13595/* GET_PREV_LABEL gets the label name from the previous definition of
13596 the function. */
13597
a4f6c312 13598tree
a2369ed3 13599get_prev_label (tree function_name)
ee890fe2
SS
13600{
13601 tree stub;
13602 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13603 if (function_name == STUB_FUNCTION_NAME (stub))
13604 return STUB_LABEL_NAME (stub);
13605 return 0;
13606}
13607
13608/* INSN is either a function call or a millicode call. It may have an
13609 unconditional jump in its delay slot.
13610
13611 CALL_DEST is the routine we are calling. */
13612
13613char *
a2369ed3 13614output_call (rtx insn, rtx call_dest, int operand_number)
ee890fe2
SS
13615{
13616 static char buf[256];
13617 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
13618 {
13619 tree labelname;
13620 tree funname = get_identifier (XSTR (call_dest, 0));
13621
13622 if (no_previous_def (funname))
13623 {
308c142a 13624 int line_number = 0;
ee890fe2
SS
13625 rtx label_rtx = gen_label_rtx ();
13626 char *label_buf, temp_buf[256];
13627 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
13628 CODE_LABEL_NUMBER (label_rtx));
13629 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
13630 labelname = get_identifier (label_buf);
13631 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
13632 if (insn)
13633 line_number = NOTE_LINE_NUMBER (insn);
13634 add_compiler_stub (labelname, funname, line_number);
13635 }
13636 else
13637 labelname = get_prev_label (funname);
13638
13639 sprintf (buf, "jbsr %%z%d,%.246s",
13640 operand_number, IDENTIFIER_POINTER (labelname));
13641 return buf;
13642 }
13643 else
13644 {
13645 sprintf (buf, "bl %%z%d", operand_number);
13646 return buf;
13647 }
13648}
13649
13650#endif /* RS6000_LONG_BRANCH */
13651
ee890fe2
SS
13652/* Generate PIC and indirect symbol stubs. */
13653
13654void
a2369ed3 13655machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
13656{
13657 unsigned int length;
a4f6c312
SS
13658 char *symbol_name, *lazy_ptr_name;
13659 char *local_label_0;
ee890fe2
SS
13660 static int label = 0;
13661
df56a27f 13662 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 13663 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 13664
ee890fe2 13665
ee890fe2
SS
13666 length = strlen (symb);
13667 symbol_name = alloca (length + 32);
13668 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
13669
13670 lazy_ptr_name = alloca (length + 32);
13671 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
13672
ee890fe2 13673 if (flag_pic == 2)
d3c300d2 13674 machopic_picsymbol_stub1_section ();
ee890fe2 13675 else
d3c300d2
DJ
13676 machopic_symbol_stub1_section ();
13677 fprintf (file, "\t.align 2\n");
ee890fe2
SS
13678
13679 fprintf (file, "%s:\n", stub);
13680 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13681
13682 if (flag_pic == 2)
13683 {
876455fa
AP
13684 label++;
13685 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
13686 sprintf (local_label_0, "\"L%011d$spb\"", label);
13687
ee890fe2
SS
13688 fprintf (file, "\tmflr r0\n");
13689 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
13690 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
13691 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
13692 lazy_ptr_name, local_label_0);
13693 fprintf (file, "\tmtlr r0\n");
d3c300d2 13694 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
13695 lazy_ptr_name, local_label_0);
13696 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
13697 fprintf (file, "\tbctr\n");
13698 }
13699 else
ab82a49f
AP
13700 {
13701 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
13702 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
13703 fprintf (file, "\tmtctr r12\n");
13704 fprintf (file, "\tbctr\n");
13705 }
ee890fe2
SS
13706
13707 machopic_lazy_symbol_ptr_section ();
13708 fprintf (file, "%s:\n", lazy_ptr_name);
13709 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13710 fprintf (file, "\t.long dyld_stub_binding_helper\n");
13711}
13712
13713/* Legitimize PIC addresses. If the address is already
13714 position-independent, we return ORIG. Newly generated
13715 position-independent addresses go into a reg. This is REG if non
13716 zero, otherwise we allocate register(s) as necessary. */
13717
c859cda6 13718#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
13719
13720rtx
a2369ed3
DJ
13721rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
13722 rtx reg)
ee890fe2
SS
13723{
13724 rtx base, offset;
13725
13726 if (reg == NULL && ! reload_in_progress && ! reload_completed)
13727 reg = gen_reg_rtx (Pmode);
13728
13729 if (GET_CODE (orig) == CONST)
13730 {
13731 if (GET_CODE (XEXP (orig, 0)) == PLUS
13732 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
13733 return orig;
13734
13735 if (GET_CODE (XEXP (orig, 0)) == PLUS)
13736 {
a4f6c312
SS
13737 base =
13738 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
13739 Pmode, reg);
13740 offset =
13741 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
13742 Pmode, reg);
ee890fe2
SS
13743 }
13744 else
13745 abort ();
13746
13747 if (GET_CODE (offset) == CONST_INT)
13748 {
13749 if (SMALL_INT (offset))
ed8908e7 13750 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
13751 else if (! reload_in_progress && ! reload_completed)
13752 offset = force_reg (Pmode, offset);
13753 else
c859cda6
DJ
13754 {
13755 rtx mem = force_const_mem (Pmode, orig);
13756 return machopic_legitimize_pic_address (mem, Pmode, reg);
13757 }
ee890fe2
SS
13758 }
13759 return gen_rtx (PLUS, Pmode, base, offset);
13760 }
13761
13762 /* Fall back on generic machopic code. */
13763 return machopic_legitimize_pic_address (orig, mode, reg);
13764}
13765
13766/* This is just a placeholder to make linking work without having to
13767 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
13768 ever needed for Darwin (not too likely!) this would have to get a
13769 real definition. */
13770
13771void
863d938c 13772toc_section (void)
ee890fe2
SS
13773{
13774}
13775
13776#endif /* TARGET_MACHO */
7c262518
RH
13777
13778#if TARGET_ELF
13779static unsigned int
a2369ed3 13780rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 13781{
5add3202
DE
13782 unsigned int flags
13783 = default_section_type_flags_1 (decl, name, reloc,
13784 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 13785
270fc29b
RH
13786 if (TARGET_RELOCATABLE)
13787 flags |= SECTION_WRITE;
7c262518 13788
d0101753 13789 return flags;
7c262518 13790}
d9f6800d
RH
13791
13792/* Record an element in the table of global constructors. SYMBOL is
13793 a SYMBOL_REF of the function to be called; PRIORITY is a number
13794 between 0 and MAX_INIT_PRIORITY.
13795
13796 This differs from default_named_section_asm_out_constructor in
13797 that we have special handling for -mrelocatable. */
13798
13799static void
a2369ed3 13800rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
13801{
13802 const char *section = ".ctors";
13803 char buf[16];
13804
13805 if (priority != DEFAULT_INIT_PRIORITY)
13806 {
13807 sprintf (buf, ".ctors.%.5u",
13808 /* Invert the numbering so the linker puts us in the proper
13809 order; constructors are run from right to left, and the
13810 linker sorts in increasing order. */
13811 MAX_INIT_PRIORITY - priority);
13812 section = buf;
13813 }
13814
715bdd29
RH
13815 named_section_flags (section, SECTION_WRITE);
13816 assemble_align (POINTER_SIZE);
d9f6800d
RH
13817
13818 if (TARGET_RELOCATABLE)
13819 {
13820 fputs ("\t.long (", asm_out_file);
13821 output_addr_const (asm_out_file, symbol);
13822 fputs (")@fixup\n", asm_out_file);
13823 }
13824 else
c8af3574 13825 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
13826}
13827
13828static void
a2369ed3 13829rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
13830{
13831 const char *section = ".dtors";
13832 char buf[16];
13833
13834 if (priority != DEFAULT_INIT_PRIORITY)
13835 {
13836 sprintf (buf, ".dtors.%.5u",
13837 /* Invert the numbering so the linker puts us in the proper
13838 order; constructors are run from right to left, and the
13839 linker sorts in increasing order. */
13840 MAX_INIT_PRIORITY - priority);
13841 section = buf;
13842 }
13843
715bdd29
RH
13844 named_section_flags (section, SECTION_WRITE);
13845 assemble_align (POINTER_SIZE);
d9f6800d
RH
13846
13847 if (TARGET_RELOCATABLE)
13848 {
13849 fputs ("\t.long (", asm_out_file);
13850 output_addr_const (asm_out_file, symbol);
13851 fputs (")@fixup\n", asm_out_file);
13852 }
13853 else
c8af3574 13854 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 13855}
9739c90c
JJ
13856
13857void
a2369ed3 13858rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
13859{
13860 if (TARGET_64BIT)
13861 {
13862 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
13863 ASM_OUTPUT_LABEL (file, name);
13864 fputs (DOUBLE_INT_ASM_OP, file);
13865 putc ('.', file);
13866 assemble_name (file, name);
13867 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
13868 assemble_name (file, name);
13869 fputs (",24\n\t.type\t.", file);
13870 assemble_name (file, name);
13871 fputs (",@function\n", file);
13872 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
13873 {
13874 fputs ("\t.globl\t.", file);
13875 assemble_name (file, name);
13876 putc ('\n', file);
13877 }
13878 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
13879 putc ('.', file);
13880 ASM_OUTPUT_LABEL (file, name);
13881 return;
13882 }
13883
13884 if (TARGET_RELOCATABLE
13885 && (get_pool_size () != 0 || current_function_profile)
13886 && uses_TOC())
13887 {
13888 char buf[256];
13889
13890 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
13891
13892 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
13893 fprintf (file, "\t.long ");
13894 assemble_name (file, buf);
13895 putc ('-', file);
13896 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
13897 assemble_name (file, buf);
13898 putc ('\n', file);
13899 }
13900
13901 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
13902 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
13903
13904 if (DEFAULT_ABI == ABI_AIX)
13905 {
13906 const char *desc_name, *orig_name;
13907
13908 orig_name = (*targetm.strip_name_encoding) (name);
13909 desc_name = orig_name;
13910 while (*desc_name == '.')
13911 desc_name++;
13912
13913 if (TREE_PUBLIC (decl))
13914 fprintf (file, "\t.globl %s\n", desc_name);
13915
13916 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
13917 fprintf (file, "%s:\n", desc_name);
13918 fprintf (file, "\t.long %s\n", orig_name);
13919 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
13920 if (DEFAULT_ABI == ABI_AIX)
13921 fputs ("\t.long 0\n", file);
13922 fprintf (file, "\t.previous\n");
13923 }
13924 ASM_OUTPUT_LABEL (file, name);
13925}
7c262518
RH
13926#endif
13927
cbaaba19 13928#if TARGET_XCOFF
7c262518 13929static void
a2369ed3 13930rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
13931{
13932 fputs (GLOBAL_ASM_OP, stream);
13933 RS6000_OUTPUT_BASENAME (stream, name);
13934 putc ('\n', stream);
13935}
13936
13937static void
a2369ed3 13938rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 13939{
0e5dbd9b
DE
13940 int smclass;
13941 static const char * const suffix[3] = { "PR", "RO", "RW" };
13942
13943 if (flags & SECTION_CODE)
13944 smclass = 0;
13945 else if (flags & SECTION_WRITE)
13946 smclass = 2;
13947 else
13948 smclass = 1;
13949
5b5198f7 13950 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 13951 (flags & SECTION_CODE) ? "." : "",
5b5198f7 13952 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 13953}
ae46c4e0
RH
13954
13955static void
a2369ed3
DJ
13956rs6000_xcoff_select_section (tree decl, int reloc,
13957 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 13958{
5add3202 13959 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 13960 {
0e5dbd9b 13961 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13962 read_only_data_section ();
13963 else
13964 read_only_private_data_section ();
13965 }
13966 else
13967 {
0e5dbd9b 13968 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13969 data_section ();
13970 else
13971 private_data_section ();
13972 }
13973}
13974
13975static void
a2369ed3 13976rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
13977{
13978 const char *name;
ae46c4e0 13979
5b5198f7
DE
13980 /* Use select_section for private and uninitialized data. */
13981 if (!TREE_PUBLIC (decl)
13982 || DECL_COMMON (decl)
0e5dbd9b
DE
13983 || DECL_INITIAL (decl) == NULL_TREE
13984 || DECL_INITIAL (decl) == error_mark_node
13985 || (flag_zero_initialized_in_bss
13986 && initializer_zerop (DECL_INITIAL (decl))))
13987 return;
13988
13989 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
13990 name = (*targetm.strip_name_encoding) (name);
13991 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 13992}
b64a1b53 13993
fb49053f
RH
13994/* Select section for constant in constant pool.
13995
13996 On RS/6000, all constants are in the private read-only data area.
13997 However, if this is being placed in the TOC it must be output as a
13998 toc entry. */
13999
b64a1b53 14000static void
a2369ed3
DJ
14001rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
14002 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
14003{
14004 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
14005 toc_section ();
14006 else
14007 read_only_private_data_section ();
14008}
772c5265
RH
14009
14010/* Remove any trailing [DS] or the like from the symbol name. */
14011
14012static const char *
a2369ed3 14013rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
14014{
14015 size_t len;
14016 if (*name == '*')
14017 name++;
14018 len = strlen (name);
14019 if (name[len - 1] == ']')
14020 return ggc_alloc_string (name, len - 4);
14021 else
14022 return name;
14023}
14024
5add3202
DE
14025/* Section attributes. AIX is always PIC. */
14026
14027static unsigned int
a2369ed3 14028rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 14029{
5b5198f7
DE
14030 unsigned int align;
14031 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
14032
14033 /* Align to at least UNIT size. */
14034 if (flags & SECTION_CODE)
14035 align = MIN_UNITS_PER_WORD;
14036 else
14037 /* Increase alignment of large objects if not already stricter. */
14038 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
14039 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
14040 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
14041
14042 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 14043}
a5fe455b 14044
1bc7c5b6
ZW
14045/* Output at beginning of assembler file.
14046
14047 Initialize the section names for the RS/6000 at this point.
14048
14049 Specify filename, including full path, to assembler.
14050
14051 We want to go into the TOC section so at least one .toc will be emitted.
14052 Also, in order to output proper .bs/.es pairs, we need at least one static
14053 [RW] section emitted.
14054
14055 Finally, declare mcount when profiling to make the assembler happy. */
14056
14057static void
863d938c 14058rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
14059{
14060 rs6000_gen_section_name (&xcoff_bss_section_name,
14061 main_input_filename, ".bss_");
14062 rs6000_gen_section_name (&xcoff_private_data_section_name,
14063 main_input_filename, ".rw_");
14064 rs6000_gen_section_name (&xcoff_read_only_section_name,
14065 main_input_filename, ".ro_");
14066
14067 fputs ("\t.file\t", asm_out_file);
14068 output_quoted_string (asm_out_file, main_input_filename);
14069 fputc ('\n', asm_out_file);
14070 toc_section ();
14071 if (write_symbols != NO_DEBUG)
14072 private_data_section ();
14073 text_section ();
14074 if (profile_flag)
14075 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
14076 rs6000_file_start ();
14077}
14078
a5fe455b
ZW
14079/* Output at end of assembler file.
14080 On the RS/6000, referencing data should automatically pull in text. */
14081
14082static void
863d938c 14083rs6000_xcoff_file_end (void)
a5fe455b
ZW
14084{
14085 text_section ();
14086 fputs ("_section_.text:\n", asm_out_file);
14087 data_section ();
14088 fputs (TARGET_32BIT
14089 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
14090 asm_out_file);
14091}
f1384257 14092#endif /* TARGET_XCOFF */
0e5dbd9b 14093
f1384257
AM
14094#if TARGET_MACHO
14095/* Cross-module name binding. Darwin does not support overriding
7f3d8013 14096 functions at dynamic-link time. */
0e5dbd9b 14097
2bcc50d0 14098static bool
a2369ed3 14099rs6000_binds_local_p (tree decl)
0e5dbd9b 14100{
f1384257 14101 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 14102}
f1384257 14103#endif
34bb030a 14104
3c50106f
RH
14105/* Compute a (partial) cost for rtx X. Return true if the complete
14106 cost has been computed, and false if subexpressions should be
14107 scanned. In either case, *TOTAL contains the cost result. */
14108
14109static bool
a2369ed3
DJ
14110rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
14111 int *total)
3c50106f
RH
14112{
14113 switch (code)
14114 {
14115 /* On the RS/6000, if it is valid in the insn, it is free.
14116 So this always returns 0. */
14117 case CONST_INT:
14118 case CONST:
14119 case LABEL_REF:
14120 case SYMBOL_REF:
14121 case CONST_DOUBLE:
14122 case HIGH:
14123 *total = 0;
14124 return true;
14125
14126 case PLUS:
14127 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
14128 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
14129 + 0x8000) >= 0x10000)
14130 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
14131 ? COSTS_N_INSNS (2)
14132 : COSTS_N_INSNS (1));
14133 return true;
14134
14135 case AND:
14136 case IOR:
14137 case XOR:
14138 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
14139 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
14140 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
14141 ? COSTS_N_INSNS (2)
14142 : COSTS_N_INSNS (1));
14143 return true;
14144
14145 case MULT:
14146 if (optimize_size)
14147 {
14148 *total = COSTS_N_INSNS (2);
14149 return true;
14150 }
14151 switch (rs6000_cpu)
14152 {
14153 case PROCESSOR_RIOS1:
14154 case PROCESSOR_PPC405:
14155 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14156 ? COSTS_N_INSNS (5)
14157 : (INTVAL (XEXP (x, 1)) >= -256
14158 && INTVAL (XEXP (x, 1)) <= 255)
14159 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
14160 return true;
14161
02ca7595
DE
14162 case PROCESSOR_PPC440:
14163 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14164 ? COSTS_N_INSNS (3)
14165 : COSTS_N_INSNS (2));
14166 return true;
14167
3c50106f
RH
14168 case PROCESSOR_RS64A:
14169 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14170 ? GET_MODE (XEXP (x, 1)) != DImode
14171 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
14172 : (INTVAL (XEXP (x, 1)) >= -256
14173 && INTVAL (XEXP (x, 1)) <= 255)
14174 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
14175 return true;
14176
14177 case PROCESSOR_RIOS2:
14178 case PROCESSOR_MPCCORE:
14179 case PROCESSOR_PPC604e:
14180 *total = COSTS_N_INSNS (2);
14181 return true;
14182
14183 case PROCESSOR_PPC601:
14184 *total = COSTS_N_INSNS (5);
14185 return true;
14186
14187 case PROCESSOR_PPC603:
14188 case PROCESSOR_PPC7400:
14189 case PROCESSOR_PPC750:
14190 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14191 ? COSTS_N_INSNS (5)
14192 : (INTVAL (XEXP (x, 1)) >= -256
14193 && INTVAL (XEXP (x, 1)) <= 255)
14194 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
14195 return true;
14196
14197 case PROCESSOR_PPC7450:
14198 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14199 ? COSTS_N_INSNS (4)
14200 : COSTS_N_INSNS (3));
14201 return true;
14202
14203 case PROCESSOR_PPC403:
14204 case PROCESSOR_PPC604:
14205 case PROCESSOR_PPC8540:
14206 *total = COSTS_N_INSNS (4);
14207 return true;
14208
14209 case PROCESSOR_PPC620:
14210 case PROCESSOR_PPC630:
3c50106f
RH
14211 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14212 ? GET_MODE (XEXP (x, 1)) != DImode
14213 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
14214 : (INTVAL (XEXP (x, 1)) >= -256
14215 && INTVAL (XEXP (x, 1)) <= 255)
14216 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
14217 return true;
14218
9259f3b0
DE
14219 case PROCESSOR_POWER4:
14220 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
14221 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
14222 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
14223 : COSTS_N_INSNS (2));
9259f3b0
DE
14224 return true;
14225
3c50106f
RH
14226 default:
14227 abort ();
14228 }
14229
14230 case DIV:
14231 case MOD:
14232 if (GET_CODE (XEXP (x, 1)) == CONST_INT
14233 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
14234 {
14235 *total = COSTS_N_INSNS (2);
14236 return true;
14237 }
14238 /* FALLTHRU */
14239
14240 case UDIV:
14241 case UMOD:
14242 switch (rs6000_cpu)
14243 {
14244 case PROCESSOR_RIOS1:
14245 *total = COSTS_N_INSNS (19);
14246 return true;
14247
14248 case PROCESSOR_RIOS2:
14249 *total = COSTS_N_INSNS (13);
14250 return true;
14251
14252 case PROCESSOR_RS64A:
14253 *total = (GET_MODE (XEXP (x, 1)) != DImode
14254 ? COSTS_N_INSNS (65)
14255 : COSTS_N_INSNS (67));
14256 return true;
14257
14258 case PROCESSOR_MPCCORE:
14259 *total = COSTS_N_INSNS (6);
14260 return true;
14261
14262 case PROCESSOR_PPC403:
14263 *total = COSTS_N_INSNS (33);
14264 return true;
14265
14266 case PROCESSOR_PPC405:
14267 *total = COSTS_N_INSNS (35);
14268 return true;
14269
02ca7595
DE
14270 case PROCESSOR_PPC440:
14271 *total = COSTS_N_INSNS (34);
14272 return true;
14273
3c50106f
RH
14274 case PROCESSOR_PPC601:
14275 *total = COSTS_N_INSNS (36);
14276 return true;
14277
14278 case PROCESSOR_PPC603:
14279 *total = COSTS_N_INSNS (37);
14280 return true;
14281
14282 case PROCESSOR_PPC604:
14283 case PROCESSOR_PPC604e:
14284 *total = COSTS_N_INSNS (20);
14285 return true;
14286
14287 case PROCESSOR_PPC620:
14288 case PROCESSOR_PPC630:
3c50106f
RH
14289 *total = (GET_MODE (XEXP (x, 1)) != DImode
14290 ? COSTS_N_INSNS (21)
14291 : COSTS_N_INSNS (37));
14292 return true;
14293
14294 case PROCESSOR_PPC750:
14295 case PROCESSOR_PPC8540:
14296 case PROCESSOR_PPC7400:
14297 *total = COSTS_N_INSNS (19);
14298 return true;
14299
14300 case PROCESSOR_PPC7450:
14301 *total = COSTS_N_INSNS (23);
14302 return true;
984e25ac
DE
14303
14304 case PROCESSOR_POWER4:
14305 *total = (GET_MODE (XEXP (x, 1)) != DImode
14306 ? COSTS_N_INSNS (18)
14307 : COSTS_N_INSNS (34));
14308 return true;
3c50106f
RH
14309
14310 default:
14311 abort ();
14312 }
14313
14314 case FFS:
14315 *total = COSTS_N_INSNS (4);
14316 return true;
14317
14318 case MEM:
14319 /* MEM should be slightly more expensive than (plus (reg) (const)) */
14320 *total = 5;
14321 return true;
14322
14323 default:
14324 return false;
14325 }
14326}
14327
34bb030a
DE
14328/* A C expression returning the cost of moving data from a register of class
14329 CLASS1 to one of CLASS2. */
14330
14331int
a2369ed3
DJ
14332rs6000_register_move_cost (enum machine_mode mode,
14333 enum reg_class from, enum reg_class to)
34bb030a
DE
14334{
14335 /* Moves from/to GENERAL_REGS. */
14336 if (reg_classes_intersect_p (to, GENERAL_REGS)
14337 || reg_classes_intersect_p (from, GENERAL_REGS))
14338 {
14339 if (! reg_classes_intersect_p (to, GENERAL_REGS))
14340 from = to;
14341
14342 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
14343 return (rs6000_memory_move_cost (mode, from, 0)
14344 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
14345
14346/* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/
14347 else if (from == CR_REGS)
14348 return 4;
14349
14350 else
14351/* A move will cost one instruction per GPR moved. */
14352 return 2 * HARD_REGNO_NREGS (0, mode);
14353 }
14354
14355/* Moving between two similar registers is just one instruction. */
14356 else if (reg_classes_intersect_p (to, from))
14357 return mode == TFmode ? 4 : 2;
14358
14359/* Everything else has to go through GENERAL_REGS. */
14360 else
14361 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
14362 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
14363}
14364
14365/* A C expressions returning the cost of moving data of MODE from a register to
14366 or from memory. */
14367
14368int
a2369ed3
DJ
14369rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
14370 int in ATTRIBUTE_UNUSED)
34bb030a
DE
14371{
14372 if (reg_classes_intersect_p (class, GENERAL_REGS))
14373 return 4 * HARD_REGNO_NREGS (0, mode);
14374 else if (reg_classes_intersect_p (class, FLOAT_REGS))
14375 return 4 * HARD_REGNO_NREGS (32, mode);
14376 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
14377 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
14378 else
14379 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
14380}
14381
ded9bf77
AH
14382/* Return an RTX representing where to find the function value of a
14383 function returning MODE. */
14384static rtx
14385rs6000_complex_function_value (enum machine_mode mode)
14386{
14387 unsigned int regno;
14388 rtx r1, r2;
14389 enum machine_mode inner = GET_MODE_INNER (mode);
14390
14391 if (FLOAT_MODE_P (mode))
14392 regno = FP_ARG_RETURN;
14393 else
14394 {
14395 regno = GP_ARG_RETURN;
14396
14397 /* 32-bit is OK since it'll go in r3/r4. */
165848da
AH
14398 if (TARGET_32BIT
14399 && GET_MODE_BITSIZE (inner) >= 32)
ded9bf77
AH
14400 return gen_rtx_REG (mode, regno);
14401 }
14402
14403 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
14404 const0_rtx);
14405 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
14406 GEN_INT (GET_MODE_UNIT_SIZE (inner)));
14407 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
14408}
14409
a6ebc39a
AH
14410/* Define how to find the value returned by a function.
14411 VALTYPE is the data type of the value (as a tree).
14412 If the precise function being called is known, FUNC is its FUNCTION_DECL;
14413 otherwise, FUNC is 0.
14414
14415 On the SPE, both FPs and vectors are returned in r3.
14416
14417 On RS/6000 an integer value is in r3 and a floating-point value is in
14418 fp1, unless -msoft-float. */
14419
14420rtx
14421rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
14422{
14423 enum machine_mode mode;
2a8fa26c 14424 unsigned int regno;
a6ebc39a
AH
14425
14426 if ((INTEGRAL_TYPE_P (valtype)
14427 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
14428 || POINTER_TYPE_P (valtype))
14429 mode = word_mode;
14430 else
14431 mode = TYPE_MODE (valtype);
14432
2a8fa26c
DE
14433 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
14434 regno = FP_ARG_RETURN;
ded9bf77
AH
14435 else if (TREE_CODE (valtype) == COMPLEX_TYPE
14436 && TARGET_HARD_FLOAT
14437 && SPLIT_COMPLEX_ARGS)
14438 return rs6000_complex_function_value (mode);
2a8fa26c 14439 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
14440 regno = ALTIVEC_ARG_RETURN;
14441 else
14442 regno = GP_ARG_RETURN;
14443
14444 return gen_rtx_REG (mode, regno);
14445}
14446
ded9bf77
AH
14447/* Define how to find the value returned by a library function
14448 assuming the value has mode MODE. */
14449rtx
14450rs6000_libcall_value (enum machine_mode mode)
14451{
14452 unsigned int regno;
14453
14454 if (GET_MODE_CLASS (mode) == MODE_FLOAT
14455 && TARGET_HARD_FLOAT && TARGET_FPRS)
14456 regno = FP_ARG_RETURN;
14457 else if (ALTIVEC_VECTOR_MODE (mode))
14458 regno = ALTIVEC_ARG_RETURN;
14459 else if (COMPLEX_MODE_P (mode) && SPLIT_COMPLEX_ARGS)
14460 return rs6000_complex_function_value (mode);
14461 else
14462 regno = GP_ARG_RETURN;
14463
14464 return gen_rtx_REG (mode, regno);
14465}
14466
62e1dfcf
NC
14467/* Return true if TYPE is of type __ev64_opaque__. */
14468
c8e4f0e9 14469static bool
a2369ed3 14470is_ev64_opaque_type (tree type)
62e1dfcf 14471{
c8e4f0e9 14472 return (TARGET_SPE
2abe3e28
AH
14473 && (type == opaque_V2SI_type_node
14474 || type == opaque_V2SF_type_node
36252949 14475 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
14476}
14477
96714395 14478static rtx
a2369ed3 14479rs6000_dwarf_register_span (rtx reg)
96714395
AH
14480{
14481 unsigned regno;
14482
14483 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
14484 return NULL_RTX;
14485
14486 regno = REGNO (reg);
14487
14488 /* The duality of the SPE register size wreaks all kinds of havoc.
14489 This is a way of distinguishing r0 in 32-bits from r0 in
14490 64-bits. */
14491 return
14492 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
14493 BYTES_BIG_ENDIAN
14494 ? gen_rtvec (2,
14495 gen_rtx_REG (SImode, regno + 1200),
14496 gen_rtx_REG (SImode, regno))
14497 : gen_rtvec (2,
14498 gen_rtx_REG (SImode, regno),
14499 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
14500}
14501
17211ab5 14502#include "gt-rs6000.h"