]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
stdc++.h: New.
[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
RK
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
c15c9075
RK
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, MA 02111-1307, USA. */
9878760c 22
956d6950 23#include "config.h"
c4d38ccb 24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
9878760c
RK
27#include "rtl.h"
28#include "regs.h"
29#include "hard-reg-set.h"
30#include "real.h"
31#include "insn-config.h"
32#include "conditions.h"
9878760c
RK
33#include "insn-attr.h"
34#include "flags.h"
35#include "recog.h"
9878760c 36#include "obstack.h"
9b30bae2 37#include "tree.h"
dfafc897 38#include "expr.h"
2fc1c679 39#include "optabs.h"
2a430ec1 40#include "except.h"
a7df97e6 41#include "function.h"
296b8152 42#include "output.h"
d5fa86ba 43#include "basic-block.h"
d0101753 44#include "integrate.h"
296b8152 45#include "toplev.h"
c8023011 46#include "ggc.h"
9ebbca7d
GK
47#include "hashtab.h"
48#include "tm_p.h"
672a6f42
NB
49#include "target.h"
50#include "target-def.h"
3ac88239 51#include "langhooks.h"
24ea750e 52#include "reload.h"
9b30bae2 53
7509c759
MM
54#ifndef TARGET_NO_PROTOTYPE
55#define TARGET_NO_PROTOTYPE 0
56#endif
57
9878760c
RK
58#define min(A,B) ((A) < (B) ? (A) : (B))
59#define max(A,B) ((A) > (B) ? (A) : (B))
60
5248c961
RK
61/* Target cpu type */
62
63enum processor_type rs6000_cpu;
8e3f41e7
MM
64struct rs6000_cpu_select rs6000_select[3] =
65{
815cdc52
MM
66 /* switch name, tune arch */
67 { (const char *)0, "--with-cpu=", 1, 1 },
68 { (const char *)0, "-mcpu=", 1, 1 },
69 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 70};
5248c961 71
6fa3f289
ZW
72/* Size of long double */
73const char *rs6000_long_double_size_string;
74int rs6000_long_double_type_size;
75
76/* Whether -mabi=altivec has appeared */
77int rs6000_altivec_abi;
78
08b57fb3
AH
79/* Whether VRSAVE instructions should be generated. */
80int rs6000_altivec_vrsave;
81
82/* String from -mvrsave= option. */
83const char *rs6000_altivec_vrsave_string;
84
a3170dc6
AH
85/* Nonzero if we want SPE ABI extensions. */
86int rs6000_spe_abi;
87
88/* Whether isel instructions should be generated. */
89int rs6000_isel;
90
91/* Nonzero if we have FPRs. */
92int rs6000_fprs = 1;
93
94/* String from -misel=. */
95const char *rs6000_isel_string;
96
a0ab749a 97/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 98static GTY(()) int common_mode_defined;
c81bebd7 99
9878760c
RK
100/* Save information from a "cmpxx" operation until the branch or scc is
101 emitted. */
9878760c
RK
102rtx rs6000_compare_op0, rs6000_compare_op1;
103int rs6000_compare_fp_p;
874a0744 104
874a0744
MM
105/* Label number of label created for -mrelocatable, to call to so we can
106 get the address of the GOT section */
107int rs6000_pic_labelno;
c81bebd7 108
b91da81f 109#ifdef USING_ELFOS_H
c81bebd7 110/* Which abi to adhere to */
815cdc52 111const char *rs6000_abi_name = RS6000_ABI_NAME;
d9407988
MM
112
113/* Semantics of the small data area */
114enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
115
116/* Which small data model to use */
815cdc52 117const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
118
119/* Counter for labels which are to be placed in .fixup. */
120int fixuplabelno = 0;
874a0744 121#endif
4697a36c 122
b6c9286a
MM
123/* ABI enumeration available for subtarget to use. */
124enum rs6000_abi rs6000_current_abi;
125
0ac081f6
AH
126/* ABI string from -mabi= option. */
127const char *rs6000_abi_string;
128
38c1f2d7 129/* Debug flags */
815cdc52 130const char *rs6000_debug_name;
38c1f2d7
MM
131int rs6000_debug_stack; /* debug stack applications */
132int rs6000_debug_arg; /* debug argument handling */
133
57ac7be9
AM
134const char *rs6000_traceback_name;
135static enum {
136 traceback_default = 0,
137 traceback_none,
138 traceback_part,
139 traceback_full
140} rs6000_traceback;
141
38c1f2d7
MM
142/* Flag to say the TOC is initialized */
143int toc_initialized;
9ebbca7d 144char toc_label_name[10];
38c1f2d7 145
9ebbca7d
GK
146/* Alias set for saves and restores from the rs6000 stack. */
147static int rs6000_sr_alias_set;
c8023011 148
a5c76ee6
ZW
149/* Call distance, overridden by -mlongcall and #pragma longcall(1).
150 The only place that looks at this is rs6000_set_default_type_attributes;
151 everywhere else should rely on the presence or absence of a longcall
152 attribute on the function declaration. */
153int rs6000_default_long_calls;
154const char *rs6000_longcall_switch;
155
a3170dc6
AH
156struct builtin_description
157{
158 /* mask is not const because we're going to alter it below. This
159 nonsense will go away when we rewrite the -march infrastructure
160 to give us more target flag bits. */
161 unsigned int mask;
162 const enum insn_code icode;
163 const char *const name;
164 const enum rs6000_builtins code;
165};
166
4977bab6 167static bool rs6000_function_ok_for_sibcall PARAMS ((tree, tree));
9ebbca7d 168static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
39a10a29
GK
169static void validate_condition_mode
170 PARAMS ((enum rtx_code, enum machine_mode));
171static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
e50f5f3d 172static void rs6000_maybe_dead PARAMS ((rtx));
9ebbca7d
GK
173static void rs6000_emit_stack_tie PARAMS ((void));
174static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
c19de7aa
AH
175static rtx spe_synthesize_frame_save PARAMS ((rtx));
176static bool spe_func_has_64bit_regs_p PARAMS ((void));
89e7058f
AH
177static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode,
178 unsigned int, int, int));
a3170dc6 179static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int));
9ebbca7d
GK
180static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
181static unsigned rs6000_hash_constant PARAMS ((rtx));
182static unsigned toc_hash_function PARAMS ((const void *));
183static int toc_hash_eq PARAMS ((const void *, const void *));
9ebbca7d 184static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
e2500fed 185static struct machine_function * rs6000_init_machine_status PARAMS ((void));
301d03af 186static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
5add3202 187#ifdef HAVE_GAS_HIDDEN
25fdb4dc 188static void rs6000_assemble_visibility PARAMS ((tree, int));
5add3202 189#endif
71f123ca 190static int rs6000_ra_ever_killed PARAMS ((void));
91d231cb
JM
191static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
192const struct attribute_spec rs6000_attribute_table[];
a5c76ee6 193static void rs6000_set_default_type_attributes PARAMS ((tree));
08c148a8
NB
194static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
195static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
3961e8fe
RH
196static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
197 HOST_WIDE_INT, tree));
2bfcf297
DB
198static rtx rs6000_emit_set_long_const PARAMS ((rtx,
199 HOST_WIDE_INT, HOST_WIDE_INT));
7c262518
RH
200#if TARGET_ELF
201static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
202 int));
d9f6800d
RH
203static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
204static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
ae46c4e0 205static void rs6000_elf_select_section PARAMS ((tree, int,
5b71a4e7 206 unsigned HOST_WIDE_INT));
ae46c4e0 207static void rs6000_elf_unique_section PARAMS ((tree, int));
b64a1b53
RH
208static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
209 unsigned HOST_WIDE_INT));
0e5dbd9b
DE
210static void rs6000_elf_encode_section_info PARAMS ((tree, int))
211 ATTRIBUTE_UNUSED;
772c5265 212static const char *rs6000_elf_strip_name_encoding PARAMS ((const char *));
0e5dbd9b 213static bool rs6000_elf_in_small_data_p PARAMS ((tree));
7c262518 214#endif
cbaaba19 215#if TARGET_XCOFF
b275d088
DE
216static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *));
217static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int));
ae46c4e0
RH
218static void rs6000_xcoff_select_section PARAMS ((tree, int,
219 unsigned HOST_WIDE_INT));
220static void rs6000_xcoff_unique_section PARAMS ((tree, int));
b64a1b53
RH
221static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx,
222 unsigned HOST_WIDE_INT));
772c5265 223static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
5add3202 224static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
fb49053f
RH
225static void rs6000_xcoff_encode_section_info PARAMS ((tree, int))
226 ATTRIBUTE_UNUSED;
f1384257
AM
227#endif
228#if TARGET_MACHO
2bcc50d0 229static bool rs6000_binds_local_p PARAMS ((tree));
f1384257 230#endif
b54cf83a 231static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
b54cf83a 232static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
3c50106f 233static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
c237e94a
ZW
234static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
235static int rs6000_adjust_priority PARAMS ((rtx, int));
236static int rs6000_issue_rate PARAMS ((void));
237
6fa3f289 238static void rs6000_init_builtins PARAMS ((void));
92898235
AH
239static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
240static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
241static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 242static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
92898235 243static void altivec_init_builtins PARAMS ((void));
a3170dc6
AH
244static void rs6000_common_init_builtins PARAMS ((void));
245
246static void enable_mask_for_builtins PARAMS ((struct builtin_description *,
247 int, enum rs6000_builtins,
248 enum rs6000_builtins));
249static void spe_init_builtins PARAMS ((void));
250static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *));
251static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx));
252static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx));
253static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx));
254
92898235 255static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
3a9b8c7e
AH
256static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *));
257static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *));
258static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *));
100c4561 259static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
ae4b4a02 260static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
6525c0e7 261static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
0ac081f6 262static void rs6000_parse_abi_options PARAMS ((void));
08b57fb3 263static void rs6000_parse_vrsave_option PARAMS ((void));
a3170dc6 264static void rs6000_parse_isel_option PARAMS ((void));
00b960c7
AH
265static int first_altivec_reg_to_save PARAMS ((void));
266static unsigned int compute_vrsave_mask PARAMS ((void));
267static void is_altivec_return_reg PARAMS ((rtx, void *));
9aa86737 268static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
69ef87e2 269static int easy_vector_constant PARAMS ((rtx));
c8e4f0e9 270static bool is_ev64_opaque_type PARAMS ((tree));
96714395 271static rtx rs6000_dwarf_register_span PARAMS ((rtx));
17211ab5
GK
272
273/* Hash table stuff for keeping track of TOC entries. */
274
275struct toc_hash_struct GTY(())
276{
277 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
278 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
279 rtx key;
280 enum machine_mode key_mode;
281 int labelno;
282};
283
284static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
285\f
286/* Default register names. */
287char rs6000_reg_names[][8] =
288{
802a0058
MM
289 "0", "1", "2", "3", "4", "5", "6", "7",
290 "8", "9", "10", "11", "12", "13", "14", "15",
291 "16", "17", "18", "19", "20", "21", "22", "23",
292 "24", "25", "26", "27", "28", "29", "30", "31",
293 "0", "1", "2", "3", "4", "5", "6", "7",
294 "8", "9", "10", "11", "12", "13", "14", "15",
295 "16", "17", "18", "19", "20", "21", "22", "23",
296 "24", "25", "26", "27", "28", "29", "30", "31",
297 "mq", "lr", "ctr","ap",
298 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
299 "xer",
300 /* AltiVec registers. */
0cd5e3a1
AH
301 "0", "1", "2", "3", "4", "5", "6", "7",
302 "8", "9", "10", "11", "12", "13", "14", "15",
303 "16", "17", "18", "19", "20", "21", "22", "23",
304 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
305 "vrsave", "vscr",
306 /* SPE registers. */
307 "spe_acc", "spefscr"
c81bebd7
MM
308};
309
310#ifdef TARGET_REGNAMES
8b60264b 311static const char alt_reg_names[][8] =
c81bebd7 312{
802a0058
MM
313 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
314 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
315 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
316 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
317 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
318 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
319 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
320 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
321 "mq", "lr", "ctr", "ap",
322 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 323 "xer",
59a4c851 324 /* AltiVec registers. */
0ac081f6 325 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
326 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
327 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
328 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
329 "vrsave", "vscr",
330 /* SPE registers. */
331 "spe_acc", "spefscr"
c81bebd7
MM
332};
333#endif
9878760c 334\f
daf11973
MM
335#ifndef MASK_STRICT_ALIGN
336#define MASK_STRICT_ALIGN 0
337#endif
3961e8fe
RH
338
339/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
340#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
672a6f42
NB
341\f
342/* Initialize the GCC target structure. */
91d231cb
JM
343#undef TARGET_ATTRIBUTE_TABLE
344#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
345#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
346#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 347
301d03af
RS
348#undef TARGET_ASM_ALIGNED_DI_OP
349#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
350
351/* Default unaligned ops are only provided for ELF. Find the ops needed
352 for non-ELF systems. */
353#ifndef OBJECT_FORMAT_ELF
cbaaba19 354#if TARGET_XCOFF
ae6c1efd 355/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
356 64-bit targets. */
357#undef TARGET_ASM_UNALIGNED_HI_OP
358#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
359#undef TARGET_ASM_UNALIGNED_SI_OP
360#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
361#undef TARGET_ASM_UNALIGNED_DI_OP
362#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
363#else
364/* For Darwin. */
365#undef TARGET_ASM_UNALIGNED_HI_OP
366#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
367#undef TARGET_ASM_UNALIGNED_SI_OP
368#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
369#endif
370#endif
371
372/* This hook deals with fixups for relocatable code and DI-mode objects
373 in 64-bit code. */
374#undef TARGET_ASM_INTEGER
375#define TARGET_ASM_INTEGER rs6000_assemble_integer
376
93638d7a
AM
377#ifdef HAVE_GAS_HIDDEN
378#undef TARGET_ASM_ASSEMBLE_VISIBILITY
379#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
380#endif
381
08c148a8
NB
382#undef TARGET_ASM_FUNCTION_PROLOGUE
383#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
384#undef TARGET_ASM_FUNCTION_EPILOGUE
385#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
386
b54cf83a
DE
387#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
388#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
389#undef TARGET_SCHED_VARIABLE_ISSUE
390#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
391
c237e94a
ZW
392#undef TARGET_SCHED_ISSUE_RATE
393#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
394#undef TARGET_SCHED_ADJUST_COST
395#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
396#undef TARGET_SCHED_ADJUST_PRIORITY
397#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
398
0ac081f6
AH
399#undef TARGET_INIT_BUILTINS
400#define TARGET_INIT_BUILTINS rs6000_init_builtins
401
402#undef TARGET_EXPAND_BUILTIN
403#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
404
f1384257 405#if TARGET_MACHO
0e5dbd9b
DE
406#undef TARGET_BINDS_LOCAL_P
407#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 408#endif
0e5dbd9b 409
3961e8fe
RH
410#undef TARGET_ASM_OUTPUT_MI_THUNK
411#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
412
3961e8fe 413#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 414#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 415
4977bab6
ZW
416#undef TARGET_FUNCTION_OK_FOR_SIBCALL
417#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
418
3c50106f
RH
419#undef TARGET_RTX_COSTS
420#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
421#undef TARGET_ADDRESS_COST
422#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 423
c8e4f0e9
AH
424#undef TARGET_VECTOR_OPAQUE_P
425#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 426
96714395
AH
427#undef TARGET_DWARF_REGISTER_SPAN
428#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
429
f6897b10 430struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 431\f
5248c961
RK
432/* Override command line options. Mostly we process the processor
433 type and sometimes adjust other TARGET_ options. */
434
435void
8e3f41e7 436rs6000_override_options (default_cpu)
d330fd93 437 const char *default_cpu;
5248c961 438{
c4d38ccb 439 size_t i, j;
8e3f41e7 440 struct rs6000_cpu_select *ptr;
5248c961 441
85638c0d
RK
442 /* Simplify the entries below by making a mask for any POWER
443 variant and any PowerPC variant. */
444
938937d8 445#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
446#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
447 | MASK_PPC_GFXOPT | MASK_POWERPC64)
448#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 449
5248c961
RK
450 static struct ptt
451 {
8b60264b
KG
452 const char *const name; /* Canonical processor name. */
453 const enum processor_type processor; /* Processor type enum value. */
454 const int target_enable; /* Target flags to enable. */
455 const int target_disable; /* Target flags to disable. */
456 } const processor_target_table[]
cf27b467
MM
457 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
458 POWER_MASKS | POWERPC_MASKS},
db7f1e43 459 {"power", PROCESSOR_POWER,
938937d8 460 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 461 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
462 {"power2", PROCESSOR_POWER,
463 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
464 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
465 {"power3", PROCESSOR_PPC630,
466 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 467 POWER_MASKS},
309323c2 468 {"power4", PROCESSOR_POWER4,
7f3d8013 469 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a12f8290 470 POWER_MASKS},
db7f1e43
RK
471 {"powerpc", PROCESSOR_POWERPC,
472 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 473 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
474 {"powerpc64", PROCESSOR_POWERPC64,
475 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
476 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 477 {"rios", PROCESSOR_RIOS1,
938937d8 478 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
479 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
480 {"rios1", PROCESSOR_RIOS1,
938937d8 481 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
482 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
483 {"rsc", PROCESSOR_PPC601,
938937d8 484 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
485 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
486 {"rsc1", PROCESSOR_PPC601,
938937d8 487 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
488 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
489 {"rios2", PROCESSOR_RIOS2,
938937d8 490 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 491 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
492 {"rs64a", PROCESSOR_RS64A,
493 MASK_POWERPC | MASK_NEW_MNEMONICS,
494 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
495 {"401", PROCESSOR_PPC403,
496 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
497 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 498 {"403", PROCESSOR_PPC403,
daf11973 499 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 500 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
501 {"405", PROCESSOR_PPC405,
502 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
503 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
4977bab6
ZW
504 {"405f", PROCESSOR_PPC405,
505 MASK_POWERPC | MASK_NEW_MNEMONICS,
506 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
507 {"505", PROCESSOR_MPCCORE,
508 MASK_POWERPC | MASK_NEW_MNEMONICS,
509 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 510 {"601", PROCESSOR_PPC601,
938937d8 511 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 512 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 513 {"602", PROCESSOR_PPC603,
cf27b467
MM
514 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
515 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 516 {"603", PROCESSOR_PPC603,
68c49ffa
RK
517 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
518 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
519 {"603e", PROCESSOR_PPC603,
520 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
521 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 522 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
523 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
524 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 525 {"604", PROCESSOR_PPC604,
b6c9286a
MM
526 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
527 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 528 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
529 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
530 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 531 {"620", PROCESSOR_PPC620,
68c49ffa 532 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 533 POWER_MASKS},
3cb999d8
DE
534 {"630", PROCESSOR_PPC630,
535 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 536 POWER_MASKS},
bef84347
VM
537 {"740", PROCESSOR_PPC750,
538 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
539 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
540 {"750", PROCESSOR_PPC750,
541 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
542 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
543 {"7400", PROCESSOR_PPC7400,
544 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
545 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
546 {"7450", PROCESSOR_PPC7450,
547 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
548 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a3170dc6
AH
549 {"8540", PROCESSOR_PPC8540,
550 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
551 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
552 {"801", PROCESSOR_MPCCORE,
553 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
554 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
555 {"821", PROCESSOR_MPCCORE,
556 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
557 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
558 {"823", PROCESSOR_MPCCORE,
559 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
560 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
561 {"860", PROCESSOR_MPCCORE,
562 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
563 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 564
ca7558fc 565 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 566
a4f6c312
SS
567 /* Save current -mmultiple/-mno-multiple status. */
568 int multiple = TARGET_MULTIPLE;
569 /* Save current -mstring/-mno-string status. */
570 int string = TARGET_STRING;
8a61d227 571
a4f6c312 572 /* Identify the processor type. */
8e3f41e7 573 rs6000_select[0].string = default_cpu;
3cb999d8 574 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 575
b6a1cbae 576 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 577 {
8e3f41e7
MM
578 ptr = &rs6000_select[i];
579 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 580 {
8e3f41e7
MM
581 for (j = 0; j < ptt_size; j++)
582 if (! strcmp (ptr->string, processor_target_table[j].name))
583 {
584 if (ptr->set_tune_p)
585 rs6000_cpu = processor_target_table[j].processor;
586
587 if (ptr->set_arch_p)
588 {
589 target_flags |= processor_target_table[j].target_enable;
590 target_flags &= ~processor_target_table[j].target_disable;
591 }
592 break;
593 }
594
4406229e 595 if (j == ptt_size)
8e3f41e7 596 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
597 }
598 }
8a61d227 599
a3170dc6
AH
600 if (rs6000_cpu == PROCESSOR_PPC8540)
601 rs6000_isel = 1;
602
dff9f1b6
DE
603 /* If we are optimizing big endian systems for space, use the load/store
604 multiple and string instructions. */
ef792183 605 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 606 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 607
8a61d227
MM
608 /* If -mmultiple or -mno-multiple was explicitly used, don't
609 override with the processor default */
b21fb038 610 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 611 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 612
a4f6c312
SS
613 /* If -mstring or -mno-string was explicitly used, don't override
614 with the processor default. */
b21fb038 615 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 616 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 617
a4f6c312
SS
618 /* Don't allow -mmultiple or -mstring on little endian systems
619 unless the cpu is a 750, because the hardware doesn't support the
620 instructions used in little endian mode, and causes an alignment
621 trap. The 750 does not cause an alignment trap (except when the
622 target is unaligned). */
bef84347 623
b21fb038 624 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
625 {
626 if (TARGET_MULTIPLE)
627 {
628 target_flags &= ~MASK_MULTIPLE;
b21fb038 629 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
630 warning ("-mmultiple is not supported on little endian systems");
631 }
632
633 if (TARGET_STRING)
634 {
635 target_flags &= ~MASK_STRING;
b21fb038 636 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 637 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
638 }
639 }
3933e0e1 640
38c1f2d7
MM
641 /* Set debug flags */
642 if (rs6000_debug_name)
643 {
bfc79d3b 644 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 645 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 646 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 647 rs6000_debug_stack = 1;
bfc79d3b 648 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
649 rs6000_debug_arg = 1;
650 else
c725bd79 651 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
652 }
653
57ac7be9
AM
654 if (rs6000_traceback_name)
655 {
656 if (! strncmp (rs6000_traceback_name, "full", 4))
657 rs6000_traceback = traceback_full;
658 else if (! strncmp (rs6000_traceback_name, "part", 4))
659 rs6000_traceback = traceback_part;
660 else if (! strncmp (rs6000_traceback_name, "no", 2))
661 rs6000_traceback = traceback_none;
662 else
663 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
664 rs6000_traceback_name);
665 }
666
6fa3f289
ZW
667 /* Set size of long double */
668 rs6000_long_double_type_size = 64;
669 if (rs6000_long_double_size_string)
670 {
671 char *tail;
672 int size = strtol (rs6000_long_double_size_string, &tail, 10);
673 if (*tail != '\0' || (size != 64 && size != 128))
674 error ("Unknown switch -mlong-double-%s",
675 rs6000_long_double_size_string);
676 else
677 rs6000_long_double_type_size = size;
678 }
679
0ac081f6
AH
680 /* Handle -mabi= options. */
681 rs6000_parse_abi_options ();
682
08b57fb3
AH
683 /* Handle -mvrsave= option. */
684 rs6000_parse_vrsave_option ();
685
a3170dc6
AH
686 /* Handle -misel= option. */
687 rs6000_parse_isel_option ();
688
a7ae18e2
AH
689#ifdef SUBTARGET_OVERRIDE_OPTIONS
690 SUBTARGET_OVERRIDE_OPTIONS;
691#endif
692#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
693 SUBSUBTARGET_OVERRIDE_OPTIONS;
694#endif
695
b5044283
AH
696 /* The e500 does not have string instructions, and we set
697 MASK_STRING above when optimizing for size. */
3bd104d1 698 if (rs6000_cpu == PROCESSOR_PPC8540 && (target_flags & MASK_STRING) != 0)
b5044283
AH
699 target_flags = target_flags & ~MASK_STRING;
700
a5c76ee6
ZW
701 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
702 using TARGET_OPTIONS to handle a toggle switch, but we're out of
703 bits in target_flags so TARGET_SWITCHES cannot be used.
704 Assumption here is that rs6000_longcall_switch points into the
705 text of the complete option, rather than being a copy, so we can
706 scan back for the presence or absence of the no- modifier. */
707 if (rs6000_longcall_switch)
708 {
709 const char *base = rs6000_longcall_switch;
710 while (base[-1] != 'm') base--;
711
712 if (*rs6000_longcall_switch != '\0')
713 error ("invalid option `%s'", base);
714 rs6000_default_long_calls = (base[0] != 'n');
715 }
716
c81bebd7 717#ifdef TARGET_REGNAMES
a4f6c312
SS
718 /* If the user desires alternate register names, copy in the
719 alternate names now. */
c81bebd7 720 if (TARGET_REGNAMES)
4e135bdd 721 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
722#endif
723
6fa3f289
ZW
724 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
725 If -maix-struct-return or -msvr4-struct-return was explicitly
726 used, don't override with the ABI default. */
b21fb038 727 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
728 {
729 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
730 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
731 else
732 target_flags |= MASK_AIX_STRUCT_RET;
733 }
734
fcce224d
DE
735 if (TARGET_LONG_DOUBLE_128
736 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
737 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
738
9ebbca7d
GK
739 /* Allocate an alias set for register saves & restores from stack. */
740 rs6000_sr_alias_set = new_alias_set ();
741
742 if (TARGET_TOC)
743 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 744
301d03af
RS
745 /* We can only guarantee the availability of DI pseudo-ops when
746 assembling for 64-bit targets. */
ae6c1efd 747 if (!TARGET_64BIT)
301d03af
RS
748 {
749 targetm.asm_out.aligned_op.di = NULL;
750 targetm.asm_out.unaligned_op.di = NULL;
751 }
752
2792d578
DE
753 /* Set maximum branch target alignment at two instructions, eight bytes. */
754 align_jumps_max_skip = 8;
755 align_loops_max_skip = 8;
756
71f123ca
FS
757 /* Arrange to save and restore machine status around nested functions. */
758 init_machine_status = rs6000_init_machine_status;
5248c961 759}
5accd822 760
a3170dc6
AH
761/* Handle -misel= option. */
762static void
763rs6000_parse_isel_option ()
764{
765 if (rs6000_isel_string == 0)
766 return;
767 else if (! strcmp (rs6000_isel_string, "yes"))
768 rs6000_isel = 1;
769 else if (! strcmp (rs6000_isel_string, "no"))
770 rs6000_isel = 0;
771 else
772 error ("unknown -misel= option specified: '%s'",
773 rs6000_isel_string);
774}
775
08b57fb3
AH
776/* Handle -mvrsave= options. */
777static void
778rs6000_parse_vrsave_option ()
779{
780 /* Generate VRSAVE instructions by default. */
781 if (rs6000_altivec_vrsave_string == 0
782 || ! strcmp (rs6000_altivec_vrsave_string, "yes"))
783 rs6000_altivec_vrsave = 1;
784 else if (! strcmp (rs6000_altivec_vrsave_string, "no"))
785 rs6000_altivec_vrsave = 0;
786 else
787 error ("unknown -mvrsave= option specified: '%s'",
788 rs6000_altivec_vrsave_string);
789}
790
0ac081f6 791/* Handle -mabi= options. */
00b960c7
AH
792static void
793rs6000_parse_abi_options ()
0ac081f6
AH
794{
795 if (rs6000_abi_string == 0)
796 return;
797 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 798 rs6000_altivec_abi = 1;
76a773f3
AH
799 else if (! strcmp (rs6000_abi_string, "no-altivec"))
800 rs6000_altivec_abi = 0;
a3170dc6 801 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
802 {
803 rs6000_spe_abi = 1;
804 if (!TARGET_SPE_ABI)
805 error ("not configured for ABI: '%s'", rs6000_abi_string);
806 }
807
a3170dc6
AH
808 else if (! strcmp (rs6000_abi_string, "no-spe"))
809 rs6000_spe_abi = 0;
0ac081f6 810 else
c725bd79 811 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
812}
813
5accd822
DE
814void
815optimization_options (level, size)
e2c953b6 816 int level ATTRIBUTE_UNUSED;
5accd822
DE
817 int size ATTRIBUTE_UNUSED;
818{
5accd822 819}
3cfa4909
MM
820\f
821/* Do anything needed at the start of the asm file. */
822
823void
824rs6000_file_start (file, default_cpu)
825 FILE *file;
d330fd93 826 const char *default_cpu;
3cfa4909 827{
c4d38ccb 828 size_t i;
3cfa4909 829 char buffer[80];
d330fd93 830 const char *start = buffer;
3cfa4909
MM
831 struct rs6000_cpu_select *ptr;
832
833 if (flag_verbose_asm)
834 {
835 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
836 rs6000_select[0].string = default_cpu;
837
b6a1cbae 838 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
839 {
840 ptr = &rs6000_select[i];
841 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
842 {
843 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
844 start = "";
845 }
846 }
847
b91da81f 848#ifdef USING_ELFOS_H
3cfa4909
MM
849 switch (rs6000_sdata)
850 {
851 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
852 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
853 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
854 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
855 }
856
857 if (rs6000_sdata && g_switch_value)
858 {
859 fprintf (file, "%s -G %d", start, g_switch_value);
860 start = "";
861 }
862#endif
863
864 if (*start == '\0')
949ea356 865 putc ('\n', file);
3cfa4909
MM
866 }
867}
5248c961 868\f
a0ab749a 869/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
870
871int
872direct_return ()
873{
4697a36c
MM
874 if (reload_completed)
875 {
876 rs6000_stack_t *info = rs6000_stack_info ();
877
878 if (info->first_gp_reg_save == 32
879 && info->first_fp_reg_save == 64
00b960c7 880 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
881 && ! info->lr_save_p
882 && ! info->cr_save_p
00b960c7 883 && info->vrsave_mask == 0
c81fc13e 884 && ! info->push_p)
4697a36c
MM
885 return 1;
886 }
887
888 return 0;
9878760c
RK
889}
890
891/* Returns 1 always. */
892
893int
894any_operand (op, mode)
592696dd 895 rtx op ATTRIBUTE_UNUSED;
296b8152 896 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
897{
898 return 1;
899}
900
a4f6c312 901/* Returns 1 if op is the count register. */
38c1f2d7 902int
a4f6c312 903count_register_operand (op, mode)
592696dd 904 rtx op;
296b8152 905 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
906{
907 if (GET_CODE (op) != REG)
908 return 0;
909
910 if (REGNO (op) == COUNT_REGISTER_REGNUM)
911 return 1;
912
913 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
914 return 1;
915
916 return 0;
917}
918
0ec4e2a8
AH
919/* Returns 1 if op is an altivec register. */
920int
921altivec_register_operand (op, mode)
922 rtx op;
923 enum machine_mode mode ATTRIBUTE_UNUSED;
924{
925
926 return (register_operand (op, mode)
927 && (GET_CODE (op) != REG
928 || REGNO (op) > FIRST_PSEUDO_REGISTER
929 || ALTIVEC_REGNO_P (REGNO (op))));
930}
931
38c1f2d7 932int
a4f6c312 933xer_operand (op, mode)
592696dd 934 rtx op;
296b8152 935 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
936{
937 if (GET_CODE (op) != REG)
938 return 0;
939
9ebbca7d 940 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
941 return 1;
942
802a0058
MM
943 return 0;
944}
945
c859cda6 946/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 947 by such constants completes more quickly. */
c859cda6
DJ
948
949int
950s8bit_cint_operand (op, mode)
951 rtx op;
952 enum machine_mode mode ATTRIBUTE_UNUSED;
953{
954 return ( GET_CODE (op) == CONST_INT
955 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
956}
957
9878760c
RK
958/* Return 1 if OP is a constant that can fit in a D field. */
959
960int
961short_cint_operand (op, mode)
592696dd 962 rtx op;
296b8152 963 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 964{
5f59ecb7
DE
965 return (GET_CODE (op) == CONST_INT
966 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
967}
968
5519a4f9 969/* Similar for an unsigned D field. */
9878760c
RK
970
971int
972u_short_cint_operand (op, mode)
592696dd 973 rtx op;
296b8152 974 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 975{
19684119 976 return (GET_CODE (op) == CONST_INT
c1f11548 977 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
978}
979
dcfedcd0
RK
980/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
981
982int
983non_short_cint_operand (op, mode)
592696dd 984 rtx op;
296b8152 985 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
986{
987 return (GET_CODE (op) == CONST_INT
a7653a2c 988 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
989}
990
2bfcf297
DB
991/* Returns 1 if OP is a CONST_INT that is a positive value
992 and an exact power of 2. */
993
994int
995exact_log2_cint_operand (op, mode)
592696dd 996 rtx op;
2bfcf297
DB
997 enum machine_mode mode ATTRIBUTE_UNUSED;
998{
999 return (GET_CODE (op) == CONST_INT
1000 && INTVAL (op) > 0
1001 && exact_log2 (INTVAL (op)) >= 0);
1002}
1003
9878760c
RK
1004/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1005 ctr, or lr). */
1006
1007int
cd2b37d9 1008gpc_reg_operand (op, mode)
592696dd 1009 rtx op;
9878760c
RK
1010 enum machine_mode mode;
1011{
1012 return (register_operand (op, mode)
802a0058 1013 && (GET_CODE (op) != REG
9ebbca7d
GK
1014 || (REGNO (op) >= ARG_POINTER_REGNUM
1015 && !XER_REGNO_P (REGNO (op)))
1016 || REGNO (op) < MQ_REGNO));
9878760c
RK
1017}
1018
1019/* Returns 1 if OP is either a pseudo-register or a register denoting a
1020 CR field. */
1021
1022int
1023cc_reg_operand (op, mode)
592696dd 1024 rtx op;
9878760c
RK
1025 enum machine_mode mode;
1026{
1027 return (register_operand (op, mode)
1028 && (GET_CODE (op) != REG
1029 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1030 || CR_REGNO_P (REGNO (op))));
1031}
1032
815cdc52
MM
1033/* Returns 1 if OP is either a pseudo-register or a register denoting a
1034 CR field that isn't CR0. */
1035
1036int
1037cc_reg_not_cr0_operand (op, mode)
592696dd 1038 rtx op;
815cdc52
MM
1039 enum machine_mode mode;
1040{
1041 return (register_operand (op, mode)
1042 && (GET_CODE (op) != REG
1043 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1044 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1045}
1046
a4f6c312
SS
1047/* Returns 1 if OP is either a constant integer valid for a D-field or
1048 a non-special register. If a register, it must be in the proper
1049 mode unless MODE is VOIDmode. */
9878760c
RK
1050
1051int
1052reg_or_short_operand (op, mode)
592696dd 1053 rtx op;
9878760c
RK
1054 enum machine_mode mode;
1055{
f5a28898 1056 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1057}
1058
a4f6c312
SS
1059/* Similar, except check if the negation of the constant would be
1060 valid for a D-field. */
9878760c
RK
1061
1062int
1063reg_or_neg_short_operand (op, mode)
592696dd 1064 rtx op;
9878760c
RK
1065 enum machine_mode mode;
1066{
1067 if (GET_CODE (op) == CONST_INT)
1068 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1069
cd2b37d9 1070 return gpc_reg_operand (op, mode);
9878760c
RK
1071}
1072
768070a0
TR
1073/* Returns 1 if OP is either a constant integer valid for a DS-field or
1074 a non-special register. If a register, it must be in the proper
1075 mode unless MODE is VOIDmode. */
1076
1077int
1078reg_or_aligned_short_operand (op, mode)
1079 rtx op;
1080 enum machine_mode mode;
1081{
1082 if (gpc_reg_operand (op, mode))
1083 return 1;
1084 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1085 return 1;
1086
1087 return 0;
1088}
1089
1090
a4f6c312
SS
1091/* Return 1 if the operand is either a register or an integer whose
1092 high-order 16 bits are zero. */
9878760c
RK
1093
1094int
1095reg_or_u_short_operand (op, mode)
592696dd 1096 rtx op;
9878760c
RK
1097 enum machine_mode mode;
1098{
e675f625 1099 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1100}
1101
1102/* Return 1 is the operand is either a non-special register or ANY
1103 constant integer. */
1104
1105int
1106reg_or_cint_operand (op, mode)
592696dd 1107 rtx op;
9878760c
RK
1108 enum machine_mode mode;
1109{
a4f6c312 1110 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1111}
1112
1113/* Return 1 is the operand is either a non-special register or ANY
1114 32-bit signed constant integer. */
1115
1116int
1117reg_or_arith_cint_operand (op, mode)
592696dd 1118 rtx op;
f6bf7de2
DE
1119 enum machine_mode mode;
1120{
a4f6c312
SS
1121 return (gpc_reg_operand (op, mode)
1122 || (GET_CODE (op) == CONST_INT
f6bf7de2 1123#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1124 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1125 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1126#endif
a4f6c312 1127 ));
9878760c
RK
1128}
1129
2bfcf297
DB
1130/* Return 1 is the operand is either a non-special register or a 32-bit
1131 signed constant integer valid for 64-bit addition. */
1132
1133int
1134reg_or_add_cint64_operand (op, mode)
592696dd 1135 rtx op;
2bfcf297
DB
1136 enum machine_mode mode;
1137{
a4f6c312
SS
1138 return (gpc_reg_operand (op, mode)
1139 || (GET_CODE (op) == CONST_INT
a65c591c 1140#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1141 && INTVAL (op) < 0x7fff8000
a65c591c 1142#else
a4f6c312
SS
1143 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1144 < 0x100000000ll)
2bfcf297 1145#endif
a4f6c312 1146 ));
2bfcf297
DB
1147}
1148
1149/* Return 1 is the operand is either a non-special register or a 32-bit
1150 signed constant integer valid for 64-bit subtraction. */
1151
1152int
1153reg_or_sub_cint64_operand (op, mode)
592696dd 1154 rtx op;
2bfcf297
DB
1155 enum machine_mode mode;
1156{
a4f6c312
SS
1157 return (gpc_reg_operand (op, mode)
1158 || (GET_CODE (op) == CONST_INT
a65c591c 1159#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1160 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1161#else
a4f6c312
SS
1162 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1163 < 0x100000000ll)
2bfcf297 1164#endif
a4f6c312 1165 ));
2bfcf297
DB
1166}
1167
9ebbca7d
GK
1168/* Return 1 is the operand is either a non-special register or ANY
1169 32-bit unsigned constant integer. */
1170
1171int
1d328b19 1172reg_or_logical_cint_operand (op, mode)
592696dd 1173 rtx op;
9ebbca7d
GK
1174 enum machine_mode mode;
1175{
1d328b19
GK
1176 if (GET_CODE (op) == CONST_INT)
1177 {
1178 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1179 {
1180 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1181 abort ();
1d328b19
GK
1182
1183 if (INTVAL (op) < 0)
1184 return 0;
1185 }
1186
1187 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1188 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1189 }
1190 else if (GET_CODE (op) == CONST_DOUBLE)
1191 {
1192 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1193 || mode != DImode)
a4f6c312 1194 abort ();
1d328b19
GK
1195
1196 return CONST_DOUBLE_HIGH (op) == 0;
1197 }
1198 else
1199 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1200}
1201
51d3e7d6 1202/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1203
1204int
1205got_operand (op, mode)
592696dd 1206 rtx op;
296b8152 1207 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
1208{
1209 return (GET_CODE (op) == SYMBOL_REF
1210 || GET_CODE (op) == CONST
1211 || GET_CODE (op) == LABEL_REF);
1212}
1213
38c1f2d7
MM
1214/* Return 1 if the operand is a simple references that can be loaded via
1215 the GOT (labels involving addition aren't allowed). */
1216
1217int
1218got_no_const_operand (op, mode)
592696dd 1219 rtx op;
296b8152 1220 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
1221{
1222 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1223}
1224
4e74d8ec
MM
1225/* Return the number of instructions it takes to form a constant in an
1226 integer register. */
1227
1228static int
1229num_insns_constant_wide (value)
1230 HOST_WIDE_INT value;
1231{
1232 /* signed constant loadable with {cal|addi} */
5f59ecb7 1233 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1234 return 1;
1235
4e74d8ec 1236 /* constant loadable with {cau|addis} */
5f59ecb7 1237 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1238 return 1;
1239
5f59ecb7 1240#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1241 else if (TARGET_POWERPC64)
4e74d8ec 1242 {
a65c591c
DE
1243 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1244 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1245
a65c591c 1246 if (high == 0 || high == -1)
4e74d8ec
MM
1247 return 2;
1248
a65c591c 1249 high >>= 1;
4e74d8ec 1250
a65c591c 1251 if (low == 0)
4e74d8ec 1252 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1253 else
1254 return (num_insns_constant_wide (high)
e396202a 1255 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1256 }
1257#endif
1258
1259 else
1260 return 2;
1261}
1262
1263int
1264num_insns_constant (op, mode)
1265 rtx op;
1266 enum machine_mode mode;
1267{
4e74d8ec 1268 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1269 {
1270#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1271 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1272 && mask64_operand (op, mode))
0d30d435
DE
1273 return 2;
1274 else
1275#endif
1276 return num_insns_constant_wide (INTVAL (op));
1277 }
4e74d8ec 1278
6fc48950
MM
1279 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1280 {
1281 long l;
1282 REAL_VALUE_TYPE rv;
1283
1284 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1285 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1286 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1287 }
1288
47ad8c61 1289 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1290 {
47ad8c61
MM
1291 HOST_WIDE_INT low;
1292 HOST_WIDE_INT high;
1293 long l[2];
1294 REAL_VALUE_TYPE rv;
1295 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1296
47ad8c61
MM
1297 if (mode == VOIDmode || mode == DImode)
1298 {
1299 high = CONST_DOUBLE_HIGH (op);
1300 low = CONST_DOUBLE_LOW (op);
1301 }
1302 else
1303 {
1304 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1305 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1306 high = l[endian];
1307 low = l[1 - endian];
1308 }
4e74d8ec 1309
47ad8c61
MM
1310 if (TARGET_32BIT)
1311 return (num_insns_constant_wide (low)
1312 + num_insns_constant_wide (high));
4e74d8ec
MM
1313
1314 else
47ad8c61 1315 {
e72247f4 1316 if (high == 0 && low >= 0)
47ad8c61
MM
1317 return num_insns_constant_wide (low);
1318
e72247f4 1319 else if (high == -1 && low < 0)
47ad8c61
MM
1320 return num_insns_constant_wide (low);
1321
a260abc9
DE
1322 else if (mask64_operand (op, mode))
1323 return 2;
1324
47ad8c61
MM
1325 else if (low == 0)
1326 return num_insns_constant_wide (high) + 1;
1327
1328 else
1329 return (num_insns_constant_wide (high)
1330 + num_insns_constant_wide (low) + 1);
1331 }
4e74d8ec
MM
1332 }
1333
1334 else
1335 abort ();
1336}
1337
a4f6c312
SS
1338/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1339 register with one instruction per word. We only do this if we can
1340 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1341
1342int
1343easy_fp_constant (op, mode)
592696dd
SS
1344 rtx op;
1345 enum machine_mode mode;
9878760c 1346{
9878760c
RK
1347 if (GET_CODE (op) != CONST_DOUBLE
1348 || GET_MODE (op) != mode
4e74d8ec 1349 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1350 return 0;
1351
a4f6c312 1352 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1353 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1354 && mode != DImode)
b6c9286a
MM
1355 return 1;
1356
a4f6c312 1357 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1358 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1359 return 0;
1360
5ae4759c 1361#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1362 /* Similarly if we are using -mrelocatable, consider all constants
1363 to be hard. */
5ae4759c
MM
1364 if (TARGET_RELOCATABLE)
1365 return 0;
1366#endif
1367
fcce224d
DE
1368 if (mode == TFmode)
1369 {
1370 long k[4];
1371 REAL_VALUE_TYPE rv;
1372
1373 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1374 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1375
1376 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1377 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1378 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1379 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1380 }
1381
1382 else if (mode == DFmode)
042259f2
DE
1383 {
1384 long k[2];
1385 REAL_VALUE_TYPE rv;
1386
1387 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1388 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1389
a65c591c
DE
1390 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1391 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1392 }
4e74d8ec
MM
1393
1394 else if (mode == SFmode)
042259f2
DE
1395 {
1396 long l;
1397 REAL_VALUE_TYPE rv;
1398
1399 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1400 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1401
4e74d8ec 1402 return num_insns_constant_wide (l) == 1;
042259f2 1403 }
4e74d8ec 1404
a260abc9 1405 else if (mode == DImode)
c81fc13e 1406 return ((TARGET_POWERPC64
a260abc9
DE
1407 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1408 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1409
a9098fd0
GK
1410 else if (mode == SImode)
1411 return 1;
4e74d8ec
MM
1412 else
1413 abort ();
9878760c 1414}
8f75773e 1415
69ef87e2
AH
1416/* Return 1 if the operand is a CONST_INT and can be put into a
1417 register with one instruction. */
1418
1419static int
1420easy_vector_constant (op)
1421 rtx op;
1422{
1423 rtx elt;
1424 int units, i;
1425
1426 if (GET_CODE (op) != CONST_VECTOR)
1427 return 0;
1428
1429 units = CONST_VECTOR_NUNITS (op);
1430
1431 /* We can generate 0 easily. Look for that. */
1432 for (i = 0; i < units; ++i)
1433 {
1434 elt = CONST_VECTOR_ELT (op, i);
1435
1436 /* We could probably simplify this by just checking for equality
1437 with CONST0_RTX for the current mode, but let's be safe
1438 instead. */
1439
98ef3137
JJ
1440 switch (GET_CODE (elt))
1441 {
1442 case CONST_INT:
1443 if (INTVAL (elt) != 0)
1444 return 0;
1445 break;
1446 case CONST_DOUBLE:
1447 if (CONST_DOUBLE_LOW (elt) != 0 || CONST_DOUBLE_HIGH (elt) != 0)
1448 return 0;
1449 break;
1450 default:
1451 return 0;
1452 }
69ef87e2
AH
1453 }
1454
1455 /* We could probably generate a few other constants trivially, but
1456 gcc doesn't generate them yet. FIXME later. */
98ef3137 1457 return 1;
69ef87e2
AH
1458}
1459
1460/* Return 1 if the operand is the constant 0. This works for scalars
1461 as well as vectors. */
1462int
1463zero_constant (op, mode)
1464 rtx op;
1465 enum machine_mode mode;
1466{
1467 return op == CONST0_RTX (mode);
1468}
1469
50a0b056
GK
1470/* Return 1 if the operand is 0.0. */
1471int
1472zero_fp_constant (op, mode)
592696dd
SS
1473 rtx op;
1474 enum machine_mode mode;
50a0b056
GK
1475{
1476 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1477}
1478
a4f6c312
SS
1479/* Return 1 if the operand is in volatile memory. Note that during
1480 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1481 volatile memory references. So this function allows us to
1482 recognize volatile references where its safe. */
1483
1484int
1485volatile_mem_operand (op, mode)
592696dd 1486 rtx op;
b6c9286a
MM
1487 enum machine_mode mode;
1488{
1489 if (GET_CODE (op) != MEM)
1490 return 0;
1491
1492 if (!MEM_VOLATILE_P (op))
1493 return 0;
1494
1495 if (mode != GET_MODE (op))
1496 return 0;
1497
1498 if (reload_completed)
1499 return memory_operand (op, mode);
1500
1501 if (reload_in_progress)
1502 return strict_memory_address_p (mode, XEXP (op, 0));
1503
1504 return memory_address_p (mode, XEXP (op, 0));
1505}
1506
97f6e72f 1507/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1508
1509int
97f6e72f 1510offsettable_mem_operand (op, mode)
592696dd 1511 rtx op;
914c2e77
RK
1512 enum machine_mode mode;
1513{
97f6e72f 1514 return ((GET_CODE (op) == MEM)
677a9668 1515 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1516 mode, XEXP (op, 0)));
914c2e77
RK
1517}
1518
9878760c
RK
1519/* Return 1 if the operand is either an easy FP constant (see above) or
1520 memory. */
1521
1522int
1523mem_or_easy_const_operand (op, mode)
592696dd 1524 rtx op;
9878760c
RK
1525 enum machine_mode mode;
1526{
1527 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1528}
1529
1530/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1531 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1532
1533int
1534add_operand (op, mode)
592696dd 1535 rtx op;
9878760c
RK
1536 enum machine_mode mode;
1537{
2bfcf297 1538 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1539 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1540 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1541
1542 return gpc_reg_operand (op, mode);
9878760c
RK
1543}
1544
dcfedcd0
RK
1545/* Return 1 if OP is a constant but not a valid add_operand. */
1546
1547int
1548non_add_cint_operand (op, mode)
592696dd 1549 rtx op;
296b8152 1550 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1551{
1552 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1553 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1554 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1555}
1556
9878760c
RK
1557/* Return 1 if the operand is a non-special register or a constant that
1558 can be used as the operand of an OR or XOR insn on the RS/6000. */
1559
1560int
1561logical_operand (op, mode)
592696dd 1562 rtx op;
9878760c
RK
1563 enum machine_mode mode;
1564{
40501e5f 1565 HOST_WIDE_INT opl, oph;
1d328b19 1566
dfbdccdb
GK
1567 if (gpc_reg_operand (op, mode))
1568 return 1;
1d328b19 1569
dfbdccdb 1570 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1571 {
1572 opl = INTVAL (op) & GET_MODE_MASK (mode);
1573
1574#if HOST_BITS_PER_WIDE_INT <= 32
1575 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1576 return 0;
1577#endif
1578 }
dfbdccdb
GK
1579 else if (GET_CODE (op) == CONST_DOUBLE)
1580 {
1d328b19 1581 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1582 abort ();
1d328b19
GK
1583
1584 opl = CONST_DOUBLE_LOW (op);
1585 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1586 if (oph != 0)
38886f37 1587 return 0;
dfbdccdb
GK
1588 }
1589 else
1590 return 0;
1d328b19 1591
40501e5f
AM
1592 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1593 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1594}
1595
dcfedcd0 1596/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1597 above), but could be split into one. */
dcfedcd0
RK
1598
1599int
1600non_logical_cint_operand (op, mode)
592696dd 1601 rtx op;
5f59ecb7 1602 enum machine_mode mode;
dcfedcd0 1603{
dfbdccdb 1604 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1605 && ! logical_operand (op, mode)
1606 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1607}
1608
19ba8161 1609/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1610 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1611 Reject all ones and all zeros, since these should have been optimized
1612 away and confuse the making of MB and ME. */
1613
1614int
19ba8161 1615mask_operand (op, mode)
592696dd 1616 rtx op;
19ba8161 1617 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1618{
02071907 1619 HOST_WIDE_INT c, lsb;
9878760c 1620
19ba8161
DE
1621 if (GET_CODE (op) != CONST_INT)
1622 return 0;
1623
1624 c = INTVAL (op);
1625
57deb3a1
AM
1626 /* Fail in 64-bit mode if the mask wraps around because the upper
1627 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1628 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1629 return 0;
1630
c5059423
AM
1631 /* We don't change the number of transitions by inverting,
1632 so make sure we start with the LS bit zero. */
1633 if (c & 1)
1634 c = ~c;
1635
1636 /* Reject all zeros or all ones. */
1637 if (c == 0)
9878760c
RK
1638 return 0;
1639
c5059423
AM
1640 /* Find the first transition. */
1641 lsb = c & -c;
1642
1643 /* Invert to look for a second transition. */
1644 c = ~c;
9878760c 1645
c5059423
AM
1646 /* Erase first transition. */
1647 c &= -lsb;
9878760c 1648
c5059423
AM
1649 /* Find the second transition (if any). */
1650 lsb = c & -c;
1651
1652 /* Match if all the bits above are 1's (or c is zero). */
1653 return c == -lsb;
9878760c
RK
1654}
1655
0ba1b2ff
AM
1656/* Return 1 for the PowerPC64 rlwinm corner case. */
1657
1658int
1659mask_operand_wrap (op, mode)
1660 rtx op;
1661 enum machine_mode mode ATTRIBUTE_UNUSED;
1662{
1663 HOST_WIDE_INT c, lsb;
1664
1665 if (GET_CODE (op) != CONST_INT)
1666 return 0;
1667
1668 c = INTVAL (op);
1669
1670 if ((c & 0x80000001) != 0x80000001)
1671 return 0;
1672
1673 c = ~c;
1674 if (c == 0)
1675 return 0;
1676
1677 lsb = c & -c;
1678 c = ~c;
1679 c &= -lsb;
1680 lsb = c & -c;
1681 return c == -lsb;
1682}
1683
a260abc9
DE
1684/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1685 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
1686 Reject all zeros, since zero should have been optimized away and
1687 confuses the making of MB and ME. */
9878760c
RK
1688
1689int
a260abc9 1690mask64_operand (op, mode)
592696dd 1691 rtx op;
0ba1b2ff 1692 enum machine_mode mode ATTRIBUTE_UNUSED;
a260abc9
DE
1693{
1694 if (GET_CODE (op) == CONST_INT)
1695 {
02071907 1696 HOST_WIDE_INT c, lsb;
a260abc9 1697
c5059423 1698 c = INTVAL (op);
a260abc9 1699
0ba1b2ff 1700 /* Reject all zeros. */
c5059423 1701 if (c == 0)
e2c953b6
DE
1702 return 0;
1703
0ba1b2ff
AM
1704 /* We don't change the number of transitions by inverting,
1705 so make sure we start with the LS bit zero. */
1706 if (c & 1)
1707 c = ~c;
1708
c5059423
AM
1709 /* Find the transition, and check that all bits above are 1's. */
1710 lsb = c & -c;
e3981aab
DE
1711
1712 /* Match if all the bits above are 1's (or c is zero). */
c5059423 1713 return c == -lsb;
e2c953b6 1714 }
0ba1b2ff
AM
1715 return 0;
1716}
1717
1718/* Like mask64_operand, but allow up to three transitions. This
1719 predicate is used by insn patterns that generate two rldicl or
1720 rldicr machine insns. */
1721
1722int
1723mask64_2_operand (op, mode)
1724 rtx op;
1725 enum machine_mode mode ATTRIBUTE_UNUSED;
1726{
1727 if (GET_CODE (op) == CONST_INT)
a260abc9 1728 {
0ba1b2ff 1729 HOST_WIDE_INT c, lsb;
a260abc9 1730
0ba1b2ff 1731 c = INTVAL (op);
a260abc9 1732
0ba1b2ff
AM
1733 /* Disallow all zeros. */
1734 if (c == 0)
1735 return 0;
a260abc9 1736
0ba1b2ff
AM
1737 /* We don't change the number of transitions by inverting,
1738 so make sure we start with the LS bit zero. */
1739 if (c & 1)
1740 c = ~c;
a260abc9 1741
0ba1b2ff
AM
1742 /* Find the first transition. */
1743 lsb = c & -c;
a260abc9 1744
0ba1b2ff
AM
1745 /* Invert to look for a second transition. */
1746 c = ~c;
1747
1748 /* Erase first transition. */
1749 c &= -lsb;
1750
1751 /* Find the second transition. */
1752 lsb = c & -c;
1753
1754 /* Invert to look for a third transition. */
1755 c = ~c;
1756
1757 /* Erase second transition. */
1758 c &= -lsb;
1759
1760 /* Find the third transition (if any). */
1761 lsb = c & -c;
1762
1763 /* Match if all the bits above are 1's (or c is zero). */
1764 return c == -lsb;
1765 }
1766 return 0;
1767}
1768
1769/* Generates shifts and masks for a pair of rldicl or rldicr insns to
1770 implement ANDing by the mask IN. */
1771void
1772build_mask64_2_operands (in, out)
1773 rtx in;
1774 rtx *out;
1775{
1776#if HOST_BITS_PER_WIDE_INT >= 64
1777 unsigned HOST_WIDE_INT c, lsb, m1, m2;
1778 int shift;
1779
1780 if (GET_CODE (in) != CONST_INT)
1781 abort ();
1782
1783 c = INTVAL (in);
1784 if (c & 1)
1785 {
1786 /* Assume c initially something like 0x00fff000000fffff. The idea
1787 is to rotate the word so that the middle ^^^^^^ group of zeros
1788 is at the MS end and can be cleared with an rldicl mask. We then
1789 rotate back and clear off the MS ^^ group of zeros with a
1790 second rldicl. */
1791 c = ~c; /* c == 0xff000ffffff00000 */
1792 lsb = c & -c; /* lsb == 0x0000000000100000 */
1793 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
1794 c = ~c; /* c == 0x00fff000000fffff */
1795 c &= -lsb; /* c == 0x00fff00000000000 */
1796 lsb = c & -c; /* lsb == 0x0000100000000000 */
1797 c = ~c; /* c == 0xff000fffffffffff */
1798 c &= -lsb; /* c == 0xff00000000000000 */
1799 shift = 0;
1800 while ((lsb >>= 1) != 0)
1801 shift++; /* shift == 44 on exit from loop */
1802 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
1803 m1 = ~m1; /* m1 == 0x000000ffffffffff */
1804 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
1805 }
1806 else
0ba1b2ff
AM
1807 {
1808 /* Assume c initially something like 0xff000f0000000000. The idea
1809 is to rotate the word so that the ^^^ middle group of zeros
1810 is at the LS end and can be cleared with an rldicr mask. We then
1811 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
1812 a second rldicr. */
1813 lsb = c & -c; /* lsb == 0x0000010000000000 */
1814 m2 = -lsb; /* m2 == 0xffffff0000000000 */
1815 c = ~c; /* c == 0x00fff0ffffffffff */
1816 c &= -lsb; /* c == 0x00fff00000000000 */
1817 lsb = c & -c; /* lsb == 0x0000100000000000 */
1818 c = ~c; /* c == 0xff000fffffffffff */
1819 c &= -lsb; /* c == 0xff00000000000000 */
1820 shift = 0;
1821 while ((lsb >>= 1) != 0)
1822 shift++; /* shift == 44 on exit from loop */
1823 m1 = ~c; /* m1 == 0x00ffffffffffffff */
1824 m1 >>= shift; /* m1 == 0x0000000000000fff */
1825 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
1826 }
1827
1828 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
1829 masks will be all 1's. We are guaranteed more than one transition. */
1830 out[0] = GEN_INT (64 - shift);
1831 out[1] = GEN_INT (m1);
1832 out[2] = GEN_INT (shift);
1833 out[3] = GEN_INT (m2);
1834#else
045572c7
GK
1835 (void)in;
1836 (void)out;
0ba1b2ff
AM
1837 abort ();
1838#endif
a260abc9
DE
1839}
1840
1841/* Return 1 if the operand is either a non-special register or a constant
1842 that can be used as the operand of a PowerPC64 logical AND insn. */
1843
1844int
1845and64_operand (op, mode)
592696dd 1846 rtx op;
9878760c
RK
1847 enum machine_mode mode;
1848{
a4f6c312 1849 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1850 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1851
1852 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
1853}
1854
0ba1b2ff
AM
1855/* Like the above, but also match constants that can be implemented
1856 with two rldicl or rldicr insns. */
1857
1858int
1859and64_2_operand (op, mode)
1860 rtx op;
1861 enum machine_mode mode;
1862{
1863 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1864 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
1865
1866 return logical_operand (op, mode) || mask64_2_operand (op, mode);
1867}
1868
a260abc9
DE
1869/* Return 1 if the operand is either a non-special register or a
1870 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1871
1872int
a260abc9 1873and_operand (op, mode)
592696dd 1874 rtx op;
a260abc9 1875 enum machine_mode mode;
dcfedcd0 1876{
a4f6c312 1877 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1878 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1879
1880 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
1881}
1882
9878760c
RK
1883/* Return 1 if the operand is a general register or memory operand. */
1884
1885int
1886reg_or_mem_operand (op, mode)
592696dd
SS
1887 rtx op;
1888 enum machine_mode mode;
9878760c 1889{
b6c9286a
MM
1890 return (gpc_reg_operand (op, mode)
1891 || memory_operand (op, mode)
1892 || volatile_mem_operand (op, mode));
9878760c
RK
1893}
1894
a7a813f7 1895/* Return 1 if the operand is a general register or memory operand without
3cb999d8 1896 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
1897 instruction. */
1898
1899int
1900lwa_operand (op, mode)
592696dd
SS
1901 rtx op;
1902 enum machine_mode mode;
a7a813f7
RK
1903{
1904 rtx inner = op;
1905
1906 if (reload_completed && GET_CODE (inner) == SUBREG)
1907 inner = SUBREG_REG (inner);
1908
1909 return gpc_reg_operand (inner, mode)
1910 || (memory_operand (inner, mode)
1911 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
1912 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
1913 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
1914 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
1915 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
1916}
1917
cc4d5fec
JH
1918/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
1919
1920int
1921symbol_ref_operand (op, mode)
1922 rtx op;
1923 enum machine_mode mode;
1924{
1925 if (mode != VOIDmode && GET_MODE (op) != mode)
1926 return 0;
1927
1928 return (GET_CODE (op) == SYMBOL_REF);
1929}
1930
9878760c 1931/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 1932 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
1933
1934int
1935call_operand (op, mode)
592696dd 1936 rtx op;
9878760c
RK
1937 enum machine_mode mode;
1938{
1939 if (mode != VOIDmode && GET_MODE (op) != mode)
1940 return 0;
1941
1942 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
1943 || (GET_CODE (op) == REG
1944 && (REGNO (op) == LINK_REGISTER_REGNUM
1945 || REGNO (op) == COUNT_REGISTER_REGNUM
1946 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
1947}
1948
2af3d377 1949/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
a4f6c312 1950 this file and the function is not weakly defined. */
2af3d377
RK
1951
1952int
1953current_file_function_operand (op, mode)
592696dd 1954 rtx op;
296b8152 1955 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1956{
1957 return (GET_CODE (op) == SYMBOL_REF
1958 && (SYMBOL_REF_FLAG (op)
8f1b829e 1959 || (op == XEXP (DECL_RTL (current_function_decl), 0)
c81fc13e 1960 && ! DECL_WEAK (current_function_decl))));
2af3d377
RK
1961}
1962
9878760c
RK
1963/* Return 1 if this operand is a valid input for a move insn. */
1964
1965int
1966input_operand (op, mode)
592696dd 1967 rtx op;
9878760c
RK
1968 enum machine_mode mode;
1969{
eb4e8003 1970 /* Memory is always valid. */
9878760c
RK
1971 if (memory_operand (op, mode))
1972 return 1;
1973
34792e82 1974 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 1975 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
1976 return 1;
1977
eb4e8003
RK
1978 /* For floating-point, easy constants are valid. */
1979 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1980 && CONSTANT_P (op)
1981 && easy_fp_constant (op, mode))
1982 return 1;
1983
4e74d8ec
MM
1984 /* Allow any integer constant. */
1985 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 1986 && (GET_CODE (op) == CONST_INT
e675f625 1987 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1988 return 1;
1989
eb4e8003
RK
1990 /* For floating-point or multi-word mode, the only remaining valid type
1991 is a register. */
9878760c
RK
1992 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1993 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1994 return register_operand (op, mode);
9878760c 1995
88fe15a1
RK
1996 /* The only cases left are integral modes one word or smaller (we
1997 do not get called for MODE_CC values). These can be in any
1998 register. */
1999 if (register_operand (op, mode))
a8b3aeda 2000 return 1;
88fe15a1 2001
84cf9dda 2002 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 2003 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
2004 return 1;
2005
9ebbca7d
GK
2006 /* A constant pool expression (relative to the TOC) is valid */
2007 if (TOC_RELATIVE_EXPR_P (op))
b6c9286a
MM
2008 return 1;
2009
88228c4b
MM
2010 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2011 to be valid. */
f607bc57 2012 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2013 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2014 && small_data_operand (op, Pmode))
2015 return 1;
2016
042259f2 2017 return 0;
9878760c 2018}
7509c759 2019
a4f6c312 2020/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2021
2022int
2023small_data_operand (op, mode)
296b8152
KG
2024 rtx op ATTRIBUTE_UNUSED;
2025 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 2026{
38c1f2d7 2027#if TARGET_ELF
5f59ecb7 2028 rtx sym_ref;
7509c759 2029
d9407988 2030 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2031 return 0;
a54d04b7 2032
f607bc57 2033 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2034 return 0;
2035
88228c4b
MM
2036 if (GET_CODE (op) == SYMBOL_REF)
2037 sym_ref = op;
2038
2039 else if (GET_CODE (op) != CONST
2040 || GET_CODE (XEXP (op, 0)) != PLUS
2041 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2042 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2043 return 0;
2044
88228c4b 2045 else
dbf55e53
MM
2046 {
2047 rtx sum = XEXP (op, 0);
2048 HOST_WIDE_INT summand;
2049
2050 /* We have to be careful here, because it is the referenced address
2051 that must be 32k from _SDA_BASE_, not just the symbol. */
2052 summand = INTVAL (XEXP (sum, 1));
2053 if (summand < 0 || summand > g_switch_value)
2054 return 0;
2055
2056 sym_ref = XEXP (sum, 0);
2057 }
88228c4b
MM
2058
2059 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
2060 return 0;
2061
2062 return 1;
d9407988
MM
2063
2064#else
2065 return 0;
2066#endif
7509c759 2067}
9ebbca7d
GK
2068\f
2069static int
2070constant_pool_expr_1 (op, have_sym, have_toc)
2071 rtx op;
2072 int *have_sym;
2073 int *have_toc;
2074{
2075 switch (GET_CODE(op))
2076 {
2077 case SYMBOL_REF:
a4f6c312
SS
2078 if (CONSTANT_POOL_ADDRESS_P (op))
2079 {
2080 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2081 {
2082 *have_sym = 1;
2083 return 1;
2084 }
2085 else
2086 return 0;
2087 }
2088 else if (! strcmp (XSTR (op, 0), toc_label_name))
2089 {
2090 *have_toc = 1;
2091 return 1;
2092 }
2093 else
2094 return 0;
9ebbca7d
GK
2095 case PLUS:
2096 case MINUS:
c1f11548
DE
2097 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2098 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2099 case CONST:
a4f6c312 2100 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2101 case CONST_INT:
a4f6c312 2102 return 1;
9ebbca7d 2103 default:
a4f6c312 2104 return 0;
9ebbca7d
GK
2105 }
2106}
2107
2108int
2109constant_pool_expr_p (op)
2110 rtx op;
2111{
2112 int have_sym = 0;
2113 int have_toc = 0;
2114 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2115}
2116
2117int
2118toc_relative_expr_p (op)
2119 rtx op;
2120{
2121 int have_sym = 0;
2122 int have_toc = 0;
2123 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2124}
2125
2126/* Try machine-dependent ways of modifying an illegitimate address
2127 to be legitimate. If we find one, return the new, valid address.
2128 This is used from only one place: `memory_address' in explow.c.
2129
a4f6c312
SS
2130 OLDX is the address as it was before break_out_memory_refs was
2131 called. In some cases it is useful to look at this to decide what
2132 needs to be done.
9ebbca7d 2133
a4f6c312 2134 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2135
a4f6c312
SS
2136 It is always safe for this function to do nothing. It exists to
2137 recognize opportunities to optimize the output.
9ebbca7d
GK
2138
2139 On RS/6000, first check for the sum of a register with a constant
2140 integer that is out of range. If so, generate code to add the
2141 constant with the low-order 16 bits masked to the register and force
2142 this result into another register (this can be done with `cau').
2143 Then generate an address of REG+(CONST&0xffff), allowing for the
2144 possibility of bit 16 being a one.
2145
2146 Then check for the sum of a register and something not constant, try to
2147 load the other things into a register and return the sum. */
2148rtx
2149rs6000_legitimize_address (x, oldx, mode)
2150 rtx x;
2151 rtx oldx ATTRIBUTE_UNUSED;
2152 enum machine_mode mode;
0ac081f6 2153{
9ebbca7d
GK
2154 if (GET_CODE (x) == PLUS
2155 && GET_CODE (XEXP (x, 0)) == REG
2156 && GET_CODE (XEXP (x, 1)) == CONST_INT
2157 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2158 {
2159 HOST_WIDE_INT high_int, low_int;
2160 rtx sum;
a65c591c
DE
2161 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2162 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2163 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2164 GEN_INT (high_int)), 0);
2165 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2166 }
2167 else if (GET_CODE (x) == PLUS
2168 && GET_CODE (XEXP (x, 0)) == REG
2169 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2170 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2171 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2172 || TARGET_POWERPC64
fcce224d 2173 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2174 && (TARGET_POWERPC64 || mode != DImode)
2175 && mode != TImode)
2176 {
2177 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2178 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2179 }
0ac081f6
AH
2180 else if (ALTIVEC_VECTOR_MODE (mode))
2181 {
2182 rtx reg;
2183
2184 /* Make sure both operands are registers. */
2185 if (GET_CODE (x) == PLUS)
9f85ed45 2186 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2187 force_reg (Pmode, XEXP (x, 1)));
2188
2189 reg = force_reg (Pmode, x);
2190 return reg;
2191 }
a3170dc6
AH
2192 else if (SPE_VECTOR_MODE (mode))
2193 {
2194 /* We accept [reg + reg] and [reg + OFFSET]. */
2195
2196 if (GET_CODE (x) == PLUS)
2197 {
2198 rtx op1 = XEXP (x, 0);
2199 rtx op2 = XEXP (x, 1);
2200
2201 op1 = force_reg (Pmode, op1);
2202
2203 if (GET_CODE (op2) != REG
2204 && (GET_CODE (op2) != CONST_INT
2205 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2206 op2 = force_reg (Pmode, op2);
2207
2208 return gen_rtx_PLUS (Pmode, op1, op2);
2209 }
2210
2211 return force_reg (Pmode, x);
2212 }
f1384257
AM
2213 else if (TARGET_ELF
2214 && TARGET_32BIT
2215 && TARGET_NO_TOC
2216 && ! flag_pic
9ebbca7d
GK
2217 && GET_CODE (x) != CONST_INT
2218 && GET_CODE (x) != CONST_DOUBLE
2219 && CONSTANT_P (x)
6ac7bf2c
GK
2220 && GET_MODE_NUNITS (mode) == 1
2221 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2222 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2223 {
2224 rtx reg = gen_reg_rtx (Pmode);
2225 emit_insn (gen_elf_high (reg, (x)));
2226 return gen_rtx_LO_SUM (Pmode, reg, (x));
2227 }
ee890fe2
SS
2228 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2229 && ! flag_pic
ab82a49f
AP
2230#if TARGET_MACHO
2231 && ! MACHO_DYNAMIC_NO_PIC_P
2232#endif
ee890fe2
SS
2233 && GET_CODE (x) != CONST_INT
2234 && GET_CODE (x) != CONST_DOUBLE
2235 && CONSTANT_P (x)
a3170dc6 2236 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2237 && mode != DImode
2238 && mode != TImode)
2239 {
2240 rtx reg = gen_reg_rtx (Pmode);
2241 emit_insn (gen_macho_high (reg, (x)));
2242 return gen_rtx_LO_SUM (Pmode, reg, (x));
2243 }
9ebbca7d
GK
2244 else if (TARGET_TOC
2245 && CONSTANT_POOL_EXPR_P (x)
a9098fd0 2246 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2247 {
2248 return create_TOC_reference (x);
2249 }
2250 else
2251 return NULL_RTX;
2252}
258bfae2 2253
24ea750e
DJ
2254/* The convention appears to be to define this wherever it is used.
2255 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2256 is now used here. */
2257#ifndef REG_MODE_OK_FOR_BASE_P
2258#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2259#endif
2260
2261/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2262 replace the input X, or the original X if no replacement is called for.
2263 The output parameter *WIN is 1 if the calling macro should goto WIN,
2264 0 if it should not.
2265
2266 For RS/6000, we wish to handle large displacements off a base
2267 register by splitting the addend across an addiu/addis and the mem insn.
2268 This cuts number of extra insns needed from 3 to 1.
2269
2270 On Darwin, we use this to generate code for floating point constants.
2271 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2272 The Darwin code is inside #if TARGET_MACHO because only then is
2273 machopic_function_base_name() defined. */
2274rtx
2275rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win)
2276 rtx x;
2277 enum machine_mode mode;
2278 int opnum;
2279 int type;
2280 int ind_levels ATTRIBUTE_UNUSED;
2281 int *win;
2282{
2283 /* We must recognize output that we have already generated ourselves. */
2284 if (GET_CODE (x) == PLUS
2285 && GET_CODE (XEXP (x, 0)) == PLUS
2286 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2287 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2288 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2289 {
2290 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2291 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2292 opnum, (enum reload_type)type);
2293 *win = 1;
2294 return x;
2295 }
3deb2758 2296
24ea750e
DJ
2297#if TARGET_MACHO
2298 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2299 && GET_CODE (x) == LO_SUM
2300 && GET_CODE (XEXP (x, 0)) == PLUS
2301 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2302 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2303 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2304 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2305 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2306 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2307 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2308 {
2309 /* Result of previous invocation of this function on Darwin
6f317ef3 2310 floating point constant. */
24ea750e
DJ
2311 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2312 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2313 opnum, (enum reload_type)type);
2314 *win = 1;
2315 return x;
2316 }
2317#endif
2318 if (GET_CODE (x) == PLUS
2319 && GET_CODE (XEXP (x, 0)) == REG
2320 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2321 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 2322 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 2323 && !SPE_VECTOR_MODE (mode)
78c875e8 2324 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
2325 {
2326 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2327 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2328 HOST_WIDE_INT high
2329 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2330
2331 /* Check for 32-bit overflow. */
2332 if (high + low != val)
2333 {
2334 *win = 0;
2335 return x;
2336 }
2337
2338 /* Reload the high part into a base reg; leave the low part
2339 in the mem directly. */
2340
2341 x = gen_rtx_PLUS (GET_MODE (x),
2342 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2343 GEN_INT (high)),
2344 GEN_INT (low));
2345
2346 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2347 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2348 opnum, (enum reload_type)type);
2349 *win = 1;
2350 return x;
2351 }
2352#if TARGET_MACHO
2353 if (GET_CODE (x) == SYMBOL_REF
2354 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 2355 && !ALTIVEC_VECTOR_MODE (mode)
24ea750e
DJ
2356 && flag_pic)
2357 {
2358 /* Darwin load of floating point constant. */
2359 rtx offset = gen_rtx (CONST, Pmode,
2360 gen_rtx (MINUS, Pmode, x,
2361 gen_rtx (SYMBOL_REF, Pmode,
2362 machopic_function_base_name ())));
2363 x = gen_rtx (LO_SUM, GET_MODE (x),
2364 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
2365 gen_rtx (HIGH, Pmode, offset)), offset);
2366 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2367 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2368 opnum, (enum reload_type)type);
2369 *win = 1;
2370 return x;
2371 }
ab82a49f
AP
2372 if (GET_CODE (x) == SYMBOL_REF
2373 && DEFAULT_ABI == ABI_DARWIN
2374 && !ALTIVEC_VECTOR_MODE (mode)
2375 && MACHO_DYNAMIC_NO_PIC_P)
2376 {
2377 /* Darwin load of floating point constant. */
2378 x = gen_rtx (LO_SUM, GET_MODE (x),
2379 gen_rtx (HIGH, Pmode, x), x);
2380 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2381 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2382 opnum, (enum reload_type)type);
2383 *win = 1;
2384 return x;
2385 }
24ea750e
DJ
2386#endif
2387 if (TARGET_TOC
c1f11548
DE
2388 && CONSTANT_POOL_EXPR_P (x)
2389 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
2390 {
2391 (x) = create_TOC_reference (x);
2392 *win = 1;
2393 return x;
2394 }
2395 *win = 0;
2396 return x;
2397}
2398
258bfae2
FS
2399/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2400 that is a valid memory address for an instruction.
2401 The MODE argument is the machine mode for the MEM expression
2402 that wants to use this address.
2403
2404 On the RS/6000, there are four valid address: a SYMBOL_REF that
2405 refers to a constant pool entry of an address (or the sum of it
2406 plus a constant), a short (16-bit signed) constant plus a register,
2407 the sum of two registers, or a register indirect, possibly with an
5bdc5878 2408 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
2409 we must ensure that both words are addressable or PowerPC64 with offset
2410 word aligned.
2411
2412 For modes spanning multiple registers (DFmode in 32-bit GPRs,
2413 32-bit DImode, TImode), indexed addressing cannot be used because
2414 adjacent memory cells are accessed by adding word-sized offsets
2415 during assembly output. */
2416int
2417rs6000_legitimate_address (mode, x, reg_ok_strict)
2418 enum machine_mode mode;
2419 rtx x;
2420 int reg_ok_strict;
2421{
2422 if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict))
2423 return 1;
2424 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 2425 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 2426 && !SPE_VECTOR_MODE (mode)
258bfae2
FS
2427 && TARGET_UPDATE
2428 && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict))
2429 return 1;
2430 if (LEGITIMATE_SMALL_DATA_P (mode, x))
2431 return 1;
2432 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
2433 return 1;
2434 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
2435 if (! reg_ok_strict
2436 && GET_CODE (x) == PLUS
2437 && GET_CODE (XEXP (x, 0)) == REG
2438 && XEXP (x, 0) == virtual_stack_vars_rtx
2439 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2440 return 1;
2441 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict))
2442 return 1;
2443 if (mode != TImode
a3170dc6
AH
2444 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2445 || TARGET_POWERPC64
fcce224d 2446 || (mode != DFmode && mode != TFmode))
258bfae2
FS
2447 && (TARGET_POWERPC64 || mode != DImode)
2448 && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict))
2449 return 1;
2450 if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict))
2451 return 1;
2452 return 0;
2453}
fb4d4348 2454\f
a4f6c312
SS
2455/* Try to output insns to set TARGET equal to the constant C if it can
2456 be done in less than N insns. Do all computations in MODE.
2457 Returns the place where the output has been placed if it can be
2458 done and the insns have been emitted. If it would take more than N
2459 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
2460
2461rtx
2462rs6000_emit_set_const (dest, mode, source, n)
2463 rtx dest, source;
2464 enum machine_mode mode;
2465 int n ATTRIBUTE_UNUSED;
2466{
af8cb5c5 2467 rtx result, insn, set;
2bfcf297
DB
2468 HOST_WIDE_INT c0, c1;
2469
af8cb5c5 2470 if (mode == QImode || mode == HImode)
2bfcf297
DB
2471 {
2472 if (dest == NULL)
2473 dest = gen_reg_rtx (mode);
2474 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
2475 return dest;
2476 }
af8cb5c5 2477 else if (mode == SImode)
2bfcf297 2478 {
af8cb5c5
DE
2479 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
2480
2481 emit_insn (gen_rtx_SET (VOIDmode, result,
2482 GEN_INT (INTVAL (source)
2483 & (~ (HOST_WIDE_INT) 0xffff))));
2484 emit_insn (gen_rtx_SET (VOIDmode, dest,
2485 gen_rtx_IOR (SImode, result,
2486 GEN_INT (INTVAL (source) & 0xffff))));
2487 result = dest;
2bfcf297 2488 }
af8cb5c5 2489 else if (mode == DImode)
2bfcf297 2490 {
af8cb5c5
DE
2491 if (GET_CODE (source) == CONST_INT)
2492 {
2493 c0 = INTVAL (source);
2494 c1 = -(c0 < 0);
2495 }
2496 else if (GET_CODE (source) == CONST_DOUBLE)
2497 {
2bfcf297 2498#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
2499 c0 = CONST_DOUBLE_LOW (source);
2500 c1 = -(c0 < 0);
2bfcf297 2501#else
af8cb5c5
DE
2502 c0 = CONST_DOUBLE_LOW (source);
2503 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 2504#endif
af8cb5c5
DE
2505 }
2506 else
2507 abort ();
2508
2509 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
2510 }
2511 else
a4f6c312 2512 abort ();
2bfcf297 2513
af8cb5c5
DE
2514 insn = get_last_insn ();
2515 set = single_set (insn);
2516 if (! CONSTANT_P (SET_SRC (set)))
2517 set_unique_reg_note (insn, REG_EQUAL, source);
2518
2519 return result;
2bfcf297
DB
2520}
2521
2522/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
2523 fall back to a straight forward decomposition. We do this to avoid
2524 exponential run times encountered when looking for longer sequences
2525 with rs6000_emit_set_const. */
2526static rtx
2527rs6000_emit_set_long_const (dest, c1, c2)
2528 rtx dest;
2529 HOST_WIDE_INT c1, c2;
2530{
2531 if (!TARGET_POWERPC64)
2532 {
2533 rtx operand1, operand2;
2534
2535 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
2536 DImode);
2537 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
2538 DImode);
2539 emit_move_insn (operand1, GEN_INT (c1));
2540 emit_move_insn (operand2, GEN_INT (c2));
2541 }
2542 else
2543 {
bc06712d 2544 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 2545
bc06712d
TR
2546 ud1 = c1 & 0xffff;
2547 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 2548#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 2549 c2 = c1 >> 32;
2bfcf297 2550#endif
bc06712d
TR
2551 ud3 = c2 & 0xffff;
2552 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 2553
bc06712d
TR
2554 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
2555 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 2556 {
bc06712d
TR
2557 if (ud1 & 0x8000)
2558 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
2559 else
2560 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 2561 }
2bfcf297 2562
bc06712d
TR
2563 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
2564 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 2565 {
bc06712d
TR
2566 if (ud2 & 0x8000)
2567 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
2568 - 0x80000000));
252b88f7 2569 else
bc06712d
TR
2570 emit_move_insn (dest, GEN_INT (ud2 << 16));
2571 if (ud1 != 0)
2572 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 2573 }
bc06712d
TR
2574 else if ((ud4 == 0xffff && (ud3 & 0x8000))
2575 || (ud4 == 0 && ! (ud3 & 0x8000)))
2576 {
2577 if (ud3 & 0x8000)
2578 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
2579 - 0x80000000));
2580 else
2581 emit_move_insn (dest, GEN_INT (ud3 << 16));
2582
2583 if (ud2 != 0)
2584 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
2585 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
2586 if (ud1 != 0)
2587 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2588 }
2589 else
2590 {
2591 if (ud4 & 0x8000)
2592 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
2593 - 0x80000000));
2594 else
2595 emit_move_insn (dest, GEN_INT (ud4 << 16));
2596
2597 if (ud3 != 0)
2598 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 2599
bc06712d
TR
2600 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
2601 if (ud2 != 0)
2602 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
2603 GEN_INT (ud2 << 16)));
2604 if (ud1 != 0)
2605 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2606 }
2607 }
2bfcf297
DB
2608 return dest;
2609}
2610
fb4d4348
GK
2611/* Emit a move from SOURCE to DEST in mode MODE. */
2612void
2613rs6000_emit_move (dest, source, mode)
2614 rtx dest;
2615 rtx source;
2616 enum machine_mode mode;
2617{
2618 rtx operands[2];
2619 operands[0] = dest;
2620 operands[1] = source;
2621
2622 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
2623 if (GET_CODE (operands[1]) == CONST_DOUBLE
2624 && ! FLOAT_MODE_P (mode)
2625 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
2626 {
2627 /* FIXME. This should never happen. */
2628 /* Since it seems that it does, do the safe thing and convert
2629 to a CONST_INT. */
2496c7bd 2630 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
2631 }
2632 if (GET_CODE (operands[1]) == CONST_DOUBLE
2633 && ! FLOAT_MODE_P (mode)
2634 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
2635 && CONST_DOUBLE_LOW (operands[1]) >= 0)
2636 || (CONST_DOUBLE_HIGH (operands[1]) == -1
2637 && CONST_DOUBLE_LOW (operands[1]) < 0)))
2638 abort ();
c9e8cb32
DD
2639
2640 /* Check if GCC is setting up a block move that will end up using FP
2641 registers as temporaries. We must make sure this is acceptable. */
2642 if (GET_CODE (operands[0]) == MEM
2643 && GET_CODE (operands[1]) == MEM
2644 && mode == DImode
41543739
GK
2645 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
2646 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
2647 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
2648 ? 32 : MEM_ALIGN (operands[0])))
2649 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
2650 ? 32
2651 : MEM_ALIGN (operands[1]))))
2652 && ! MEM_VOLATILE_P (operands [0])
2653 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 2654 {
41543739
GK
2655 emit_move_insn (adjust_address (operands[0], SImode, 0),
2656 adjust_address (operands[1], SImode, 0));
2657 emit_move_insn (adjust_address (operands[0], SImode, 4),
2658 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
2659 return;
2660 }
fb4d4348 2661
67cef334
DE
2662 if (!no_new_pseudos)
2663 {
2664 if (GET_CODE (operands[1]) == MEM && optimize > 0
2665 && (mode == QImode || mode == HImode || mode == SImode)
2666 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2667 {
2668 rtx reg = gen_reg_rtx (word_mode);
2669
2670 emit_insn (gen_rtx_SET (word_mode, reg,
2671 gen_rtx_ZERO_EXTEND (word_mode,
2672 operands[1])));
2673 operands[1] = gen_lowpart (mode, reg);
2674 }
2675 if (GET_CODE (operands[0]) != REG)
2676 operands[1] = force_reg (mode, operands[1]);
2677 }
a9098fd0 2678
a3170dc6
AH
2679 if (mode == SFmode && ! TARGET_POWERPC
2680 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 2681 && GET_CODE (operands[0]) == MEM)
fb4d4348 2682 {
ffc14f31
GK
2683 int regnum;
2684
2685 if (reload_in_progress || reload_completed)
2686 regnum = true_regnum (operands[1]);
2687 else if (GET_CODE (operands[1]) == REG)
2688 regnum = REGNO (operands[1]);
2689 else
2690 regnum = -1;
fb4d4348
GK
2691
2692 /* If operands[1] is a register, on POWER it may have
2693 double-precision data in it, so truncate it to single
2694 precision. */
2695 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
2696 {
2697 rtx newreg;
2698 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
2699 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
2700 operands[1] = newreg;
2701 }
2702 }
2703
a9098fd0
GK
2704 /* Handle the case where reload calls us with an invalid address;
2705 and the case of CONSTANT_P_RTX. */
16861f33 2706 if (!ALTIVEC_VECTOR_MODE (mode)
69ef87e2
AH
2707 && (! general_operand (operands[1], mode)
2708 || ! nonimmediate_operand (operands[0], mode)
2709 || GET_CODE (operands[1]) == CONSTANT_P_RTX))
fb4d4348
GK
2710 {
2711 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2712 return;
2713 }
a9098fd0 2714
fb4d4348
GK
2715 /* FIXME: In the long term, this switch statement should go away
2716 and be replaced by a sequence of tests based on things like
2717 mode == Pmode. */
2718 switch (mode)
2719 {
2720 case HImode:
2721 case QImode:
2722 if (CONSTANT_P (operands[1])
2723 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 2724 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2725 break;
2726
06f4e019 2727 case TFmode:
fb4d4348
GK
2728 case DFmode:
2729 case SFmode:
2730 if (CONSTANT_P (operands[1])
2731 && ! easy_fp_constant (operands[1], mode))
a9098fd0 2732 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2733 break;
2734
0ac081f6
AH
2735 case V16QImode:
2736 case V8HImode:
2737 case V4SFmode:
2738 case V4SImode:
a3170dc6
AH
2739 case V4HImode:
2740 case V2SFmode:
2741 case V2SImode:
00a892b8 2742 case V1DImode:
69ef87e2
AH
2743 if (CONSTANT_P (operands[1])
2744 && !easy_vector_constant (operands[1]))
0ac081f6
AH
2745 operands[1] = force_const_mem (mode, operands[1]);
2746 break;
2747
fb4d4348 2748 case SImode:
a9098fd0 2749 case DImode:
fb4d4348
GK
2750 /* Use default pattern for address of ELF small data */
2751 if (TARGET_ELF
a9098fd0 2752 && mode == Pmode
f607bc57 2753 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
2754 && (GET_CODE (operands[1]) == SYMBOL_REF
2755 || GET_CODE (operands[1]) == CONST)
2756 && small_data_operand (operands[1], mode))
fb4d4348
GK
2757 {
2758 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2759 return;
2760 }
2761
f607bc57 2762 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
2763 && mode == Pmode && mode == SImode
2764 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
2765 {
2766 emit_insn (gen_movsi_got (operands[0], operands[1]));
2767 return;
2768 }
2769
ee890fe2 2770 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
2771 && TARGET_NO_TOC
2772 && ! flag_pic
a9098fd0 2773 && mode == Pmode
fb4d4348
GK
2774 && CONSTANT_P (operands[1])
2775 && GET_CODE (operands[1]) != HIGH
2776 && GET_CODE (operands[1]) != CONST_INT)
2777 {
a9098fd0 2778 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
2779
2780 /* If this is a function address on -mcall-aixdesc,
2781 convert it to the address of the descriptor. */
2782 if (DEFAULT_ABI == ABI_AIX
2783 && GET_CODE (operands[1]) == SYMBOL_REF
2784 && XSTR (operands[1], 0)[0] == '.')
2785 {
2786 const char *name = XSTR (operands[1], 0);
2787 rtx new_ref;
2788 while (*name == '.')
2789 name++;
2790 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
2791 CONSTANT_POOL_ADDRESS_P (new_ref)
2792 = CONSTANT_POOL_ADDRESS_P (operands[1]);
2793 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
2794 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
2795 operands[1] = new_ref;
2796 }
7509c759 2797
ee890fe2
SS
2798 if (DEFAULT_ABI == ABI_DARWIN)
2799 {
ab82a49f
AP
2800#if TARGET_MACHO
2801 if (MACHO_DYNAMIC_NO_PIC_P)
2802 {
2803 /* Take care of any required data indirection. */
2804 operands[1] = rs6000_machopic_legitimize_pic_address (
2805 operands[1], mode, operands[0]);
2806 if (operands[0] != operands[1])
2807 emit_insn (gen_rtx_SET (VOIDmode,
2808 operands[0], operands[1]));
2809 return;
2810 }
2811#endif
ee890fe2
SS
2812 emit_insn (gen_macho_high (target, operands[1]));
2813 emit_insn (gen_macho_low (operands[0], target, operands[1]));
2814 return;
2815 }
2816
fb4d4348
GK
2817 emit_insn (gen_elf_high (target, operands[1]));
2818 emit_insn (gen_elf_low (operands[0], target, operands[1]));
2819 return;
2820 }
2821
a9098fd0
GK
2822 /* If this is a SYMBOL_REF that refers to a constant pool entry,
2823 and we have put it in the TOC, we just need to make a TOC-relative
2824 reference to it. */
2825 if (TARGET_TOC
2826 && GET_CODE (operands[1]) == SYMBOL_REF
2827 && CONSTANT_POOL_EXPR_P (operands[1])
2828 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
2829 get_pool_mode (operands[1])))
fb4d4348 2830 {
a9098fd0 2831 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 2832 }
a9098fd0
GK
2833 else if (mode == Pmode
2834 && CONSTANT_P (operands[1])
38886f37
AO
2835 && ((GET_CODE (operands[1]) != CONST_INT
2836 && ! easy_fp_constant (operands[1], mode))
2837 || (GET_CODE (operands[1]) == CONST_INT
2838 && num_insns_constant (operands[1], mode) > 2)
2839 || (GET_CODE (operands[0]) == REG
2840 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0
GK
2841 && GET_CODE (operands[1]) != HIGH
2842 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
2843 && ! TOC_RELATIVE_EXPR_P (operands[1]))
fb4d4348
GK
2844 {
2845 /* Emit a USE operation so that the constant isn't deleted if
2846 expensive optimizations are turned on because nobody
2847 references it. This should only be done for operands that
2848 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
2849 This should not be done for operands that contain LABEL_REFs.
2850 For now, we just handle the obvious case. */
2851 if (GET_CODE (operands[1]) != LABEL_REF)
2852 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
2853
c859cda6 2854#if TARGET_MACHO
ee890fe2 2855 /* Darwin uses a special PIC legitimizer. */
ab82a49f 2856 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 2857 {
ee890fe2
SS
2858 operands[1] =
2859 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
2860 operands[0]);
2861 if (operands[0] != operands[1])
2862 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
2863 return;
2864 }
c859cda6 2865#endif
ee890fe2 2866
fb4d4348
GK
2867 /* If we are to limit the number of things we put in the TOC and
2868 this is a symbol plus a constant we can add in one insn,
2869 just put the symbol in the TOC and add the constant. Don't do
2870 this if reload is in progress. */
2871 if (GET_CODE (operands[1]) == CONST
2872 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
2873 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 2874 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
2875 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
2876 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
2877 && ! side_effects_p (operands[0]))
2878 {
a4f6c312
SS
2879 rtx sym =
2880 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
2881 rtx other = XEXP (XEXP (operands[1], 0), 1);
2882
a9098fd0
GK
2883 sym = force_reg (mode, sym);
2884 if (mode == SImode)
2885 emit_insn (gen_addsi3 (operands[0], sym, other));
2886 else
2887 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
2888 return;
2889 }
2890
a9098fd0 2891 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2892
2893 if (TARGET_TOC
d34c5b80
DE
2894 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
2895 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
2896 get_pool_constant (XEXP (operands[1], 0)),
2897 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 2898 {
ba4828e0
RK
2899 operands[1]
2900 = gen_rtx_MEM (mode,
2901 create_TOC_reference (XEXP (operands[1], 0)));
2902 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 2903 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 2904 }
fb4d4348
GK
2905 }
2906 break;
a9098fd0 2907
fb4d4348
GK
2908 case TImode:
2909 if (GET_CODE (operands[0]) == MEM
2910 && GET_CODE (XEXP (operands[0], 0)) != REG
2911 && ! reload_in_progress)
792760b9
RK
2912 operands[0]
2913 = replace_equiv_address (operands[0],
2914 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
2915
2916 if (GET_CODE (operands[1]) == MEM
2917 && GET_CODE (XEXP (operands[1], 0)) != REG
2918 && ! reload_in_progress)
792760b9
RK
2919 operands[1]
2920 = replace_equiv_address (operands[1],
2921 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
2922 if (TARGET_POWER)
2923 {
2924 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2925 gen_rtvec (2,
2926 gen_rtx_SET (VOIDmode,
2927 operands[0], operands[1]),
2928 gen_rtx_CLOBBER (VOIDmode,
2929 gen_rtx_SCRATCH (SImode)))));
2930 return;
2931 }
fb4d4348
GK
2932 break;
2933
2934 default:
2935 abort ();
2936 }
2937
a9098fd0
GK
2938 /* Above, we may have called force_const_mem which may have returned
2939 an invalid address. If we can, fix this up; otherwise, reload will
2940 have to deal with it. */
2941 if (GET_CODE (operands[1]) == MEM
2942 && ! memory_address_p (mode, XEXP (operands[1], 0))
2943 && ! reload_in_progress)
f4ef873c 2944 operands[1] = adjust_address (operands[1], mode, 0);
a9098fd0 2945
fb4d4348 2946 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
02a4ec28 2947 return;
fb4d4348 2948}
4697a36c
MM
2949\f
2950/* Initialize a variable CUM of type CUMULATIVE_ARGS
2951 for a call to a function whose data type is FNTYPE.
2952 For a library call, FNTYPE is 0.
2953
2954 For incoming args we set the number of arguments in the prototype large
1c20ae99 2955 so we never return a PARALLEL. */
4697a36c
MM
2956
2957void
2958init_cumulative_args (cum, fntype, libname, incoming)
2959 CUMULATIVE_ARGS *cum;
2960 tree fntype;
296b8152 2961 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
2962 int incoming;
2963{
2964 static CUMULATIVE_ARGS zero_cumulative;
2965
2966 *cum = zero_cumulative;
2967 cum->words = 0;
2968 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 2969 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 2970 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 2971 cum->call_cookie = CALL_NORMAL;
4cc833b7 2972 cum->sysv_gregno = GP_ARG_MIN_REG;
4697a36c
MM
2973
2974 if (incoming)
bd227acc 2975 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
2976
2977 else if (cum->prototype)
2978 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
2979 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
2980 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
2981
2982 else
2983 cum->nargs_prototype = 0;
2984
2985 cum->orig_nargs = cum->nargs_prototype;
7509c759 2986
a5c76ee6
ZW
2987 /* Check for a longcall attribute. */
2988 if (fntype
2989 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
2990 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
2991 cum->call_cookie = CALL_LONG;
2992
4697a36c
MM
2993 if (TARGET_DEBUG_ARG)
2994 {
2995 fprintf (stderr, "\ninit_cumulative_args:");
2996 if (fntype)
2997 {
2998 tree ret_type = TREE_TYPE (fntype);
2999 fprintf (stderr, " ret code = %s,",
3000 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3001 }
3002
6a4cee5f
MM
3003 if (cum->call_cookie & CALL_LONG)
3004 fprintf (stderr, " longcall,");
3005
4697a36c
MM
3006 fprintf (stderr, " proto = %d, nargs = %d\n",
3007 cum->prototype, cum->nargs_prototype);
3008 }
3009}
3010\f
c229cba9
DE
3011/* If defined, a C expression which determines whether, and in which
3012 direction, to pad out an argument with extra space. The value
3013 should be of type `enum direction': either `upward' to pad above
3014 the argument, `downward' to pad below, or `none' to inhibit
3015 padding.
3016
3017 For the AIX ABI structs are always stored left shifted in their
3018 argument slot. */
3019
9ebbca7d 3020enum direction
c229cba9
DE
3021function_arg_padding (mode, type)
3022 enum machine_mode mode;
3023 tree type;
3024{
c85f7c16 3025 if (type != 0 && AGGREGATE_TYPE_P (type))
9ebbca7d 3026 return upward;
c229cba9
DE
3027
3028 /* This is the default definition. */
3029 return (! BYTES_BIG_ENDIAN
9ebbca7d 3030 ? upward
c229cba9
DE
3031 : ((mode == BLKmode
3032 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
3033 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
3034 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
9ebbca7d 3035 ? downward : upward));
c229cba9
DE
3036}
3037
b6c9286a
MM
3038/* If defined, a C expression that gives the alignment boundary, in bits,
3039 of an argument with the specified mode and type. If it is not defined,
3040 PARM_BOUNDARY is used for all arguments.
3041
2310f99a 3042 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3043
3044int
3045function_arg_boundary (mode, type)
3046 enum machine_mode mode;
9ebbca7d 3047 tree type ATTRIBUTE_UNUSED;
b6c9286a 3048{
f607bc57 3049 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3050 return 64;
a3170dc6
AH
3051 else if (SPE_VECTOR_MODE (mode))
3052 return 64;
0ac081f6
AH
3053 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3054 return 128;
9ebbca7d 3055 else
b6c9286a 3056 return PARM_BOUNDARY;
b6c9286a
MM
3057}
3058\f
4697a36c
MM
3059/* Update the data in CUM to advance over an argument
3060 of mode MODE and data type TYPE.
3061 (TYPE is null for libcalls where that information may not be available.) */
3062
3063void
3064function_arg_advance (cum, mode, type, named)
3065 CUMULATIVE_ARGS *cum;
3066 enum machine_mode mode;
3067 tree type;
3068 int named;
3069{
3070 cum->nargs_prototype--;
3071
0ac081f6
AH
3072 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3073 {
3074 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
3075 cum->vregno++;
3076 else
3077 cum->words += RS6000_ARG_SIZE (mode, type);
3078 }
a4b0320c
AH
3079 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
3080 && named && cum->sysv_gregno <= GP_ARG_MAX_REG)
3081 cum->sysv_gregno++;
f607bc57 3082 else if (DEFAULT_ABI == ABI_V4)
4697a36c 3083 {
a3170dc6 3084 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 3085 && (mode == SFmode || mode == DFmode))
4697a36c 3086 {
4cc833b7
RH
3087 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3088 cum->fregno++;
3089 else
3090 {
3091 if (mode == DFmode)
3092 cum->words += cum->words & 1;
d34c5b80 3093 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 3094 }
4697a36c 3095 }
4cc833b7
RH
3096 else
3097 {
3098 int n_words;
3099 int gregno = cum->sysv_gregno;
3100
3101 /* Aggregates and IEEE quad get passed by reference. */
3102 if ((type && AGGREGATE_TYPE_P (type))
3103 || mode == TFmode)
3104 n_words = 1;
3105 else
d34c5b80 3106 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3107
a4b0320c 3108 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3109 if (n_words == 2 && (gregno & 1) == 0)
3110 gregno += 1;
3111
a4b0320c
AH
3112 /* Long long and SPE vectors are not split between registers
3113 and stack. */
4cc833b7
RH
3114 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
3115 {
3116 /* Long long is aligned on the stack. */
3117 if (n_words == 2)
3118 cum->words += cum->words & 1;
3119 cum->words += n_words;
3120 }
4697a36c 3121
4cc833b7
RH
3122 /* Note: continuing to accumulate gregno past when we've started
3123 spilling to the stack indicates the fact that we've started
3124 spilling to the stack to expand_builtin_saveregs. */
3125 cum->sysv_gregno = gregno + n_words;
3126 }
4697a36c 3127
4cc833b7
RH
3128 if (TARGET_DEBUG_ARG)
3129 {
3130 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3131 cum->words, cum->fregno);
3132 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
3133 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
3134 fprintf (stderr, "mode = %4s, named = %d\n",
3135 GET_MODE_NAME (mode), named);
3136 }
4697a36c
MM
3137 }
3138 else
4cc833b7
RH
3139 {
3140 int align = (TARGET_32BIT && (cum->words & 1) != 0
3141 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 3142
d34c5b80 3143 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 3144
a3170dc6
AH
3145 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3146 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 3147 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
3148
3149 if (TARGET_DEBUG_ARG)
3150 {
3151 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3152 cum->words, cum->fregno);
3153 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
3154 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
3155 fprintf (stderr, "named = %d, align = %d\n", named, align);
3156 }
3157 }
4697a36c
MM
3158}
3159\f
3160/* Determine where to put an argument to a function.
3161 Value is zero to push the argument on the stack,
3162 or a hard register in which to store the argument.
3163
3164 MODE is the argument's machine mode.
3165 TYPE is the data type of the argument (as a tree).
3166 This is null for libcalls where that information may
3167 not be available.
3168 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3169 the preceding args and about the function being called.
3170 NAMED is nonzero if this argument is a named parameter
3171 (otherwise it is an extra parameter matching an ellipsis).
3172
3173 On RS/6000 the first eight words of non-FP are normally in registers
3174 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
3175 Under V.4, the first 8 FP args are in registers.
3176
3177 If this is floating-point and no prototype is specified, we use
3178 both an FP and integer register (or possibly FP reg and stack). Library
3179 functions (when TYPE is zero) always have the proper types for args,
3180 so we can pass the FP value just in one register. emit_library_function
1c20ae99 3181 doesn't support PARALLEL anyway. */
4697a36c
MM
3182
3183struct rtx_def *
3184function_arg (cum, mode, type, named)
3185 CUMULATIVE_ARGS *cum;
3186 enum machine_mode mode;
3187 tree type;
20c29ebe 3188 int named;
4697a36c 3189{
4cc833b7 3190 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 3191
a4f6c312
SS
3192 /* Return a marker to indicate whether CR1 needs to set or clear the
3193 bit that V.4 uses to say fp args were passed in registers.
3194 Assume that we don't need the marker for software floating point,
3195 or compiler generated library calls. */
4697a36c
MM
3196 if (mode == VOIDmode)
3197 {
f607bc57 3198 if (abi == ABI_V4
7509c759 3199 && cum->nargs_prototype < 0
4697a36c 3200 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 3201 {
a3170dc6
AH
3202 /* For the SPE, we need to crxor CR6 always. */
3203 if (TARGET_SPE_ABI)
3204 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
3205 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
3206 return GEN_INT (cum->call_cookie
3207 | ((cum->fregno == FP_ARG_MIN_REG)
3208 ? CALL_V4_SET_FP_ARGS
3209 : CALL_V4_CLEAR_FP_ARGS));
7509c759 3210 }
4697a36c 3211
7509c759 3212 return GEN_INT (cum->call_cookie);
4697a36c
MM
3213 }
3214
0ac081f6
AH
3215 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3216 {
20c29ebe 3217 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
3218 return gen_rtx_REG (mode, cum->vregno);
3219 else
3220 return NULL;
3221 }
a4b0320c 3222 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) && named)
a3170dc6 3223 {
a4b0320c 3224 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
a3170dc6
AH
3225 return gen_rtx_REG (mode, cum->sysv_gregno);
3226 else
3227 return NULL;
3228 }
f607bc57 3229 else if (abi == ABI_V4)
4697a36c 3230 {
a3170dc6 3231 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
3232 && (mode == SFmode || mode == DFmode))
3233 {
3234 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3235 return gen_rtx_REG (mode, cum->fregno);
3236 else
3237 return NULL;
3238 }
3239 else
3240 {
3241 int n_words;
3242 int gregno = cum->sysv_gregno;
3243
3244 /* Aggregates and IEEE quad get passed by reference. */
3245 if ((type && AGGREGATE_TYPE_P (type))
3246 || mode == TFmode)
3247 n_words = 1;
3248 else
d34c5b80 3249 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3250
a4b0320c 3251 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3252 if (n_words == 2 && (gregno & 1) == 0)
3253 gregno += 1;
3254
a4b0320c
AH
3255 /* Long long and SPE vectors are not split between registers
3256 and stack. */
4cc833b7 3257 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a4b0320c
AH
3258 {
3259 /* SPE vectors in ... get split into 2 registers. */
3260 if (TARGET_SPE && TARGET_SPE_ABI
3261 && SPE_VECTOR_MODE (mode) && !named)
3262 {
3263 rtx r1, r2;
57de2c8f 3264 enum machine_mode m = SImode;
f9dd72da 3265
a4b0320c
AH
3266 r1 = gen_rtx_REG (m, gregno);
3267 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
3268 r2 = gen_rtx_REG (m, gregno + 1);
3269 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
3270 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
3271 }
3272 return gen_rtx_REG (mode, gregno);
3273 }
4cc833b7
RH
3274 else
3275 return NULL;
3276 }
4697a36c 3277 }
4cc833b7
RH
3278 else
3279 {
3280 int align = (TARGET_32BIT && (cum->words & 1) != 0
3281 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
3282 int align_words = cum->words + align;
4697a36c 3283
4cc833b7
RH
3284 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3285 return NULL_RTX;
3286
3287 if (USE_FP_FOR_ARG_P (*cum, mode, type))
3288 {
3289 if (! type
3290 || ((cum->nargs_prototype > 0)
3291 /* IBM AIX extended its linkage convention definition always
3292 to require FP args after register save area hole on the
3293 stack. */
3294 && (DEFAULT_ABI != ABI_AIX
3295 || ! TARGET_XL_CALL
3296 || (align_words < GP_ARG_NUM_REG))))
3297 return gen_rtx_REG (mode, cum->fregno);
3298
3299 return gen_rtx_PARALLEL (mode,
3300 gen_rtvec (2,
39403d82 3301 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
3302 ((align_words >= GP_ARG_NUM_REG)
3303 ? NULL_RTX
3304 : (align_words
d34c5b80 3305 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
3306 > GP_ARG_NUM_REG
3307 /* If this is partially on the stack, then
3308 we only include the portion actually
3309 in registers here. */
39403d82 3310 ? gen_rtx_REG (SImode,
1c20ae99 3311 GP_ARG_MIN_REG + align_words)
39403d82 3312 : gen_rtx_REG (mode,
1c20ae99
JW
3313 GP_ARG_MIN_REG + align_words))),
3314 const0_rtx),
39403d82
DE
3315 gen_rtx_EXPR_LIST (VOIDmode,
3316 gen_rtx_REG (mode, cum->fregno),
1c20ae99 3317 const0_rtx)));
4cc833b7
RH
3318 }
3319 else if (align_words < GP_ARG_NUM_REG)
3320 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
3321 else
3322 return NULL_RTX;
4697a36c 3323 }
4697a36c
MM
3324}
3325\f
3326/* For an arg passed partly in registers and partly in memory,
3327 this is the number of registers used.
3328 For args passed entirely in registers or entirely in memory, zero. */
3329
3330int
3331function_arg_partial_nregs (cum, mode, type, named)
3332 CUMULATIVE_ARGS *cum;
3333 enum machine_mode mode;
3334 tree type;
d34c5b80 3335 int named ATTRIBUTE_UNUSED;
4697a36c 3336{
f607bc57 3337 if (DEFAULT_ABI == ABI_V4)
4697a36c 3338 return 0;
4697a36c 3339
0ac081f6
AH
3340 if (USE_FP_FOR_ARG_P (*cum, mode, type)
3341 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
3342 {
3343 if (cum->nargs_prototype >= 0)
3344 return 0;
3345 }
3346
3347 if (cum->words < GP_ARG_NUM_REG
d34c5b80 3348 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
3349 {
3350 int ret = GP_ARG_NUM_REG - cum->words;
3351 if (ret && TARGET_DEBUG_ARG)
3352 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3353
3354 return ret;
3355 }
3356
3357 return 0;
3358}
3359\f
3360/* A C expression that indicates when an argument must be passed by
3361 reference. If nonzero for an argument, a copy of that argument is
3362 made in memory and a pointer to the argument is passed instead of
3363 the argument itself. The pointer is passed in whatever way is
3364 appropriate for passing a pointer to that type.
3365
c8c99a68
DE
3366 Under V.4, structures and unions are passed by reference.
3367
3368 As an extension to all ABIs, variable sized types are passed by
3369 reference. */
4697a36c
MM
3370
3371int
3372function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
3373 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3374 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 3375 tree type;
296b8152 3376 int named ATTRIBUTE_UNUSED;
4697a36c 3377{
f607bc57 3378 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
3379 && ((type && AGGREGATE_TYPE_P (type))
3380 || mode == TFmode))
4697a36c
MM
3381 {
3382 if (TARGET_DEBUG_ARG)
3383 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
3384
3385 return 1;
3386 }
c8c99a68 3387 return type && int_size_in_bytes (type) <= 0;
4697a36c 3388}
4697a36c
MM
3389\f
3390/* Perform any needed actions needed for a function that is receiving a
3391 variable number of arguments.
3392
3393 CUM is as above.
3394
3395 MODE and TYPE are the mode and type of the current parameter.
3396
3397 PRETEND_SIZE is a variable that should be set to the amount of stack
3398 that must be pushed by the prolog to pretend that our caller pushed
3399 it.
3400
3401 Normally, this macro will push all remaining incoming registers on the
3402 stack and set PRETEND_SIZE to the length of the registers pushed. */
3403
3404void
3405setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
3406 CUMULATIVE_ARGS *cum;
3407 enum machine_mode mode;
3408 tree type;
de62b72c 3409 int *pretend_size ATTRIBUTE_UNUSED;
4697a36c
MM
3410 int no_rtl;
3411
3412{
4cc833b7
RH
3413 CUMULATIVE_ARGS next_cum;
3414 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 3415 rtx save_area = NULL_RTX, mem;
dfafc897 3416 int first_reg_offset, set;
d34c5b80
DE
3417 tree fntype;
3418 int stdarg_p;
4697a36c 3419
d34c5b80
DE
3420 fntype = TREE_TYPE (current_function_decl);
3421 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
3422 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3423 != void_type_node));
4cc833b7 3424
d34c5b80
DE
3425 /* For varargs, we do not want to skip the dummy va_dcl argument.
3426 For stdargs, we do want to skip the last named argument. */
3427 next_cum = *cum;
3428 if (stdarg_p)
3429 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 3430
f607bc57 3431 if (DEFAULT_ABI == ABI_V4)
d34c5b80 3432 {
4cc833b7 3433 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 3434 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 3435 if (! no_rtl)
2c4974b7 3436 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 3437 - RS6000_VARARGS_SIZE);
4cc833b7
RH
3438
3439 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 3440 }
60e2d0ca 3441 else
4697a36c 3442 {
d34c5b80 3443 first_reg_offset = next_cum.words;
4cc833b7 3444 save_area = virtual_incoming_args_rtx;
00dba523 3445 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
3446
3447 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 3448 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 3449 }
4697a36c 3450
dfafc897 3451 set = get_varargs_alias_set ();
c81fc13e 3452 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 3453 {
dfafc897
FS
3454 mem = gen_rtx_MEM (BLKmode,
3455 plus_constant (save_area,
3456 first_reg_offset * reg_size)),
ba4828e0 3457 set_mem_alias_set (mem, set);
8ac61af7 3458 set_mem_align (mem, BITS_PER_WORD);
dfafc897 3459
4cc833b7 3460 move_block_from_reg
dfafc897 3461 (GP_ARG_MIN_REG + first_reg_offset, mem,
4cc833b7
RH
3462 GP_ARG_NUM_REG - first_reg_offset,
3463 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
4697a36c
MM
3464 }
3465
4697a36c 3466 /* Save FP registers if needed. */
f607bc57 3467 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
3468 && TARGET_HARD_FLOAT && TARGET_FPRS
3469 && ! no_rtl
4cc833b7 3470 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 3471 {
4cc833b7 3472 int fregno = next_cum.fregno;
9ebbca7d 3473 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
3474 rtx lab = gen_label_rtx ();
3475 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 3476
4cc833b7 3477 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 3478 pc_rtx,
39403d82 3479 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
3480 gen_rtx_NE (VOIDmode, cr1,
3481 const0_rtx),
39403d82 3482 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
3483 pc_rtx)));
3484
4cc833b7
RH
3485 while (fregno <= FP_ARG_V4_MAX_REG)
3486 {
dfafc897 3487 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 3488 set_mem_alias_set (mem, set);
dfafc897 3489 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
3490 fregno++;
3491 off += 8;
4697a36c 3492 }
4cc833b7
RH
3493
3494 emit_label (lab);
4697a36c 3495 }
4697a36c 3496}
4697a36c 3497
dfafc897 3498/* Create the va_list data type. */
2c4974b7 3499
dfafc897
FS
3500tree
3501rs6000_build_va_list ()
3502{
bab45a51 3503 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4697a36c 3504
9ebbca7d
GK
3505 /* For AIX, prefer 'char *' because that's what the system
3506 header files like. */
f607bc57 3507 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 3508 return build_pointer_type (char_type_node);
dfafc897 3509
f1e639b1 3510 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 3511 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 3512
9ebbca7d
GK
3513 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
3514 unsigned_char_type_node);
3515 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
3516 unsigned_char_type_node);
dfafc897
FS
3517 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
3518 ptr_type_node);
3519 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
3520 ptr_type_node);
3521
3522 DECL_FIELD_CONTEXT (f_gpr) = record;
3523 DECL_FIELD_CONTEXT (f_fpr) = record;
3524 DECL_FIELD_CONTEXT (f_ovf) = record;
3525 DECL_FIELD_CONTEXT (f_sav) = record;
3526
bab45a51
FS
3527 TREE_CHAIN (record) = type_decl;
3528 TYPE_NAME (record) = type_decl;
dfafc897
FS
3529 TYPE_FIELDS (record) = f_gpr;
3530 TREE_CHAIN (f_gpr) = f_fpr;
3531 TREE_CHAIN (f_fpr) = f_ovf;
3532 TREE_CHAIN (f_ovf) = f_sav;
3533
3534 layout_type (record);
3535
3536 /* The correct type is an array type of one element. */
3537 return build_array_type (record, build_index_type (size_zero_node));
3538}
3539
3540/* Implement va_start. */
3541
3542void
e5faf155 3543rs6000_va_start (valist, nextarg)
dfafc897
FS
3544 tree valist;
3545 rtx nextarg;
4697a36c 3546{
dfafc897
FS
3547 HOST_WIDE_INT words, n_gpr, n_fpr;
3548 tree f_gpr, f_fpr, f_ovf, f_sav;
3549 tree gpr, fpr, ovf, sav, t;
2c4974b7 3550
dfafc897 3551 /* Only SVR4 needs something special. */
f607bc57 3552 if (DEFAULT_ABI != ABI_V4)
dfafc897 3553 {
e5faf155 3554 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
3555 return;
3556 }
3557
973a648b 3558 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3559 f_fpr = TREE_CHAIN (f_gpr);
3560 f_ovf = TREE_CHAIN (f_fpr);
3561 f_sav = TREE_CHAIN (f_ovf);
3562
8ebecc3b 3563 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3564 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3565 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3566 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3567 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3568
3569 /* Count number of gp and fp argument registers used. */
4cc833b7 3570 words = current_function_args_info.words;
dfafc897
FS
3571 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
3572 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
3573
3574 if (TARGET_DEBUG_ARG)
78e1b90d
DE
3575 {
3576 fputs ("va_start: words = ", stderr);
3577 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words);
3578 fputs (", n_gpr = ", stderr);
3579 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr);
3580 fputs (", n_fpr = ", stderr);
3581 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr);
3582 putc ('\n', stderr);
3583 }
dfafc897
FS
3584
3585 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
3586 TREE_SIDE_EFFECTS (t) = 1;
3587 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3588
3589 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
3590 TREE_SIDE_EFFECTS (t) = 1;
3591 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3592
3593 /* Find the overflow area. */
3594 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
3595 if (words != 0)
3596 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
3597 build_int_2 (words * UNITS_PER_WORD, 0));
3598 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3599 TREE_SIDE_EFFECTS (t) = 1;
3600 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3601
3602 /* Find the register save area. */
3603 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
3604 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
3605 build_int_2 (-RS6000_VARARGS_SIZE, -1));
3606 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
3607 TREE_SIDE_EFFECTS (t) = 1;
3608 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3609}
3610
3611/* Implement va_arg. */
3612
3613rtx
3614rs6000_va_arg (valist, type)
3615 tree valist, type;
3616{
3617 tree f_gpr, f_fpr, f_ovf, f_sav;
3618 tree gpr, fpr, ovf, sav, reg, t, u;
3619 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
3620 rtx lab_false, lab_over, addr_rtx, r;
3621
f607bc57 3622 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
3623 {
3624 /* Variable sized types are passed by reference. */
3625 if (int_size_in_bytes (type) <= 0)
3626 {
3627 u = build_pointer_type (type);
3628
3629 /* Args grow upward. */
3630 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
3631 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
3632 TREE_SIDE_EFFECTS (t) = 1;
3633
3634 t = build1 (NOP_EXPR, build_pointer_type (u), t);
3635 TREE_SIDE_EFFECTS (t) = 1;
3636
3637 t = build1 (INDIRECT_REF, u, t);
3638 TREE_SIDE_EFFECTS (t) = 1;
3639
3640 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
3641 }
3642 else
3643 return std_expand_builtin_va_arg (valist, type);
3644 }
dfafc897 3645
973a648b 3646 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3647 f_fpr = TREE_CHAIN (f_gpr);
3648 f_ovf = TREE_CHAIN (f_fpr);
3649 f_sav = TREE_CHAIN (f_ovf);
3650
8ebecc3b 3651 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3652 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3653 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3654 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3655 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3656
3657 size = int_size_in_bytes (type);
3658 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 3659
dfafc897 3660 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 3661 {
dfafc897
FS
3662 /* Aggregates and long doubles are passed by reference. */
3663 indirect_p = 1;
3664 reg = gpr;
3665 n_reg = 1;
3666 sav_ofs = 0;
3667 sav_scale = 4;
d3294cd9
FS
3668 size = UNITS_PER_WORD;
3669 rsize = 1;
dfafc897 3670 }
a3170dc6 3671 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
3672 {
3673 /* FP args go in FP registers, if present. */
3674 indirect_p = 0;
3675 reg = fpr;
3676 n_reg = 1;
3677 sav_ofs = 8*4;
3678 sav_scale = 8;
4cc833b7 3679 }
dfafc897
FS
3680 else
3681 {
3682 /* Otherwise into GP registers. */
3683 indirect_p = 0;
3684 reg = gpr;
3685 n_reg = rsize;
3686 sav_ofs = 0;
3687 sav_scale = 4;
3688 }
3689
a4f6c312 3690 /* Pull the value out of the saved registers ... */
dfafc897
FS
3691
3692 lab_false = gen_label_rtx ();
3693 lab_over = gen_label_rtx ();
3694 addr_rtx = gen_reg_rtx (Pmode);
3695
16861f33
AH
3696 /* AltiVec vectors never go in registers. */
3697 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 3698 {
41daaf0e
AH
3699 TREE_THIS_VOLATILE (reg) = 1;
3700 emit_cmp_and_jump_insns
3701 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
3702 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
3703 lab_false);
dfafc897 3704
41daaf0e
AH
3705 /* Long long is aligned in the registers. */
3706 if (n_reg > 1)
3707 {
3708 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
3709 build_int_2 (n_reg - 1, 0));
3710 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
3711 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
3712 TREE_SIDE_EFFECTS (u) = 1;
3713 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
3714 }
2c4974b7 3715
41daaf0e
AH
3716 if (sav_ofs)
3717 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
3718 else
3719 t = sav;
2c4974b7 3720
41daaf0e
AH
3721 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
3722 build_int_2 (n_reg, 0));
3723 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 3724
41daaf0e
AH
3725 u = build1 (CONVERT_EXPR, integer_type_node, u);
3726 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3727
41daaf0e
AH
3728 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
3729 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3730
41daaf0e
AH
3731 t = build (PLUS_EXPR, ptr_type_node, t, u);
3732 TREE_SIDE_EFFECTS (t) = 1;
3733
3734 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3735 if (r != addr_rtx)
3736 emit_move_insn (addr_rtx, r);
3737
3738 emit_jump_insn (gen_jump (lab_over));
3739 emit_barrier ();
3740 }
dfafc897 3741
dfafc897
FS
3742 emit_label (lab_false);
3743
a4f6c312 3744 /* ... otherwise out of the overflow area. */
dfafc897 3745
41daaf0e
AH
3746 /* Make sure we don't find reg 7 for the next int arg.
3747
3748 All AltiVec vectors go in the overflow area. So in the AltiVec
3749 case we need to get the vectors from the overflow area, but
3750 remember where the GPRs and FPRs are. */
16861f33
AH
3751 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
3752 || !TARGET_ALTIVEC))
dfafc897
FS
3753 {
3754 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
3755 TREE_SIDE_EFFECTS (t) = 1;
3756 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3757 }
3758
3759 /* Care for on-stack alignment if needed. */
3760 if (rsize <= 1)
3761 t = ovf;
3762 else
3763 {
41daaf0e
AH
3764 int align;
3765
16861f33
AH
3766 /* AltiVec vectors are 16 byte aligned. */
3767 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
3768 align = 15;
3769 else
3770 align = 7;
3771
3772 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
3773 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
3774 }
3775 t = save_expr (t);
3776
3777 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3778 if (r != addr_rtx)
3779 emit_move_insn (addr_rtx, r);
3780
3781 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
3782 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3783 TREE_SIDE_EFFECTS (t) = 1;
3784 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3785
3786 emit_label (lab_over);
3787
3788 if (indirect_p)
3789 {
3790 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 3791 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
3792 emit_move_insn (addr_rtx, r);
3793 }
3794
3795 return addr_rtx;
4697a36c 3796}
0ac081f6
AH
3797
3798/* Builtins. */
3799
6a2dd09a
RS
3800#define def_builtin(MASK, NAME, TYPE, CODE) \
3801do { \
3802 if ((MASK) & target_flags) \
3803 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
3804 NULL, NULL_TREE); \
0ac081f6
AH
3805} while (0)
3806
24408032
AH
3807/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
3808
2212663f 3809static const struct builtin_description bdesc_3arg[] =
24408032
AH
3810{
3811 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
3812 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
3813 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
3814 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
3815 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
3816 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
3817 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
3818 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
3819 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
3820 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
3821 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
3822 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
3823 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
3824 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
3825 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
3826 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
3827 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
3828 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
3829 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
3830 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
3831 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
3832 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
3833 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
3834};
2212663f 3835
95385cbb
AH
3836/* DST operations: void foo (void *, const int, const char). */
3837
3838static const struct builtin_description bdesc_dst[] =
3839{
3840 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
3841 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
3842 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
3843 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
3844};
3845
2212663f 3846/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 3847
a3170dc6 3848static struct builtin_description bdesc_2arg[] =
0ac081f6 3849{
f18c054f
DB
3850 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
3851 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
3852 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
3853 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
3854 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
3855 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
3856 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
3857 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
3858 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
3859 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
3860 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 3861 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
3862 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
3863 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
3864 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
3865 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
3866 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
3867 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
3868 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
3869 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
3870 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
3871 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
3872 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
3873 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
3874 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
3875 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
3876 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
3877 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
3878 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
3879 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
3880 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
3881 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
3882 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
3883 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
3884 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
3885 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
3886 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
3887 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
3888 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
3889 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
3890 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
3891 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
3892 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
3893 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
3894 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
3895 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
3896 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
3897 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
3898 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
3899 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
3900 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
3901 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
3902 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
3903 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
3904 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
3905 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
3906 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
3907 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
3908 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
3909 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
3910 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
3911 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
3912 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
3913 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
3914 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 3915 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
3916 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
3917 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
3918 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
3919 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
3920 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
3921 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
3922 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
3923 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
3924 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
3925 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
3926 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
3927 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
3928 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
3929 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
3930 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
3931 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
3932 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
3933 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
3934 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
3935 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
3936 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
3937 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 3938 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
3939 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
3940 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
3941 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
3942 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
3943 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
3944 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
3945 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
3946 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
3947 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
3948 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
3949 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
3950 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
3951 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
3952 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
3953 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
3954 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
3955 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
3956 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
3957 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
3958 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
3959 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
3960 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
3961 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 3962 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
3963
3964 /* Place holder, leave as first spe builtin. */
3965 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
3966 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
3967 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
3968 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
3969 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
3970 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
3971 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
3972 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
3973 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
3974 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
3975 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
3976 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
3977 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
3978 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
3979 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
3980 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
3981 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
3982 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
3983 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
3984 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
3985 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
3986 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
3987 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
3988 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
3989 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
3990 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
3991 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
3992 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
3993 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
3994 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
3995 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
3996 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
3997 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
3998 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
3999 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
4000 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
4001 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
4002 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
4003 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
4004 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
4005 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
4006 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
4007 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
4008 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
4009 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
4010 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
4011 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
4012 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
4013 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
4014 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
4015 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
4016 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
4017 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
4018 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
4019 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
4020 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
4021 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
4022 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
4023 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
4024 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
4025 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
4026 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
4027 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
4028 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
4029 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
4030 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
4031 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
4032 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
4033 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
4034 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
4035 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
4036 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
4037 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
4038 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
4039 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
4040 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
4041 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
4042 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
4043 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
4044 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
4045 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
4046 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
4047 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
4048 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
4049 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
4050 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
4051 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
4052 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
4053 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
4054 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
4055 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
4056 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
4057 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
4058 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
4059 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
4060 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
4061 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
4062 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
4063 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
4064 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
4065 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
4066 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
4067 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
4068 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
4069 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
4070 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
4071 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
4072 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
4073 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
4074
4075 /* SPE binary operations expecting a 5-bit unsigned literal. */
4076 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
4077
4078 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
4079 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
4080 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
4081 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
4082 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
4083 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
4084 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
4085 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
4086 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
4087 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
4088 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
4089 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
4090 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
4091 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
4092 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
4093 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
4094 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
4095 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
4096 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
4097 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
4098 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
4099 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
4100 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
4101 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
4102 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
4103 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
4104
4105 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 4106 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
4107};
4108
4109/* AltiVec predicates. */
4110
4111struct builtin_description_predicates
4112{
4113 const unsigned int mask;
4114 const enum insn_code icode;
4115 const char *opcode;
4116 const char *const name;
4117 const enum rs6000_builtins code;
4118};
4119
4120static const struct builtin_description_predicates bdesc_altivec_preds[] =
4121{
4122 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
4123 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
4124 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
4125 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
4126 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
4127 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
4128 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
4129 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
4130 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
4131 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
4132 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
4133 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
4134 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 4135};
24408032 4136
a3170dc6
AH
4137/* SPE predicates. */
4138static struct builtin_description bdesc_spe_predicates[] =
4139{
4140 /* Place-holder. Leave as first. */
4141 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
4142 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
4143 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
4144 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
4145 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
4146 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
4147 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
4148 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
4149 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
4150 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
4151 /* Place-holder. Leave as last. */
4152 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
4153};
4154
4155/* SPE evsel predicates. */
4156static struct builtin_description bdesc_spe_evsel[] =
4157{
4158 /* Place-holder. Leave as first. */
4159 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
4160 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
4161 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
4162 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
4163 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
4164 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
4165 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
4166 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
4167 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
4168 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
4169 /* Place-holder. Leave as last. */
4170 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
4171};
4172
b6d08ca1 4173/* ABS* operations. */
100c4561
AH
4174
4175static const struct builtin_description bdesc_abs[] =
4176{
4177 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
4178 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
4179 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
4180 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
4181 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
4182 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
4183 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
4184};
4185
617e0e1d
DB
4186/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
4187 foo (VECa). */
24408032 4188
a3170dc6 4189static struct builtin_description bdesc_1arg[] =
2212663f 4190{
617e0e1d
DB
4191 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
4192 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
4193 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
4194 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
4195 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
4196 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
4197 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
4198 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
4199 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
4200 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
4201 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
4202 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
4203 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
4204 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
4205 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
4206 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
4207 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
4208
4209 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
4210 end with SPE_BUILTIN_EVSUBFUSIAAW. */
4211 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
4212 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
4213 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
4214 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
4215 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
4216 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
4217 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
4218 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
4219 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
4220 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
4221 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
4222 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
4223 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
4224 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
4225 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
4226 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
4227 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
4228 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
4229 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
4230 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
4231 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
4232 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
4233 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
4234 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
4235 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
4236 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
4237 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
4238 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
4239 { 0, CODE_FOR_spe_evsplatfi, "__builtin_spe_evsplatfi", SPE_BUILTIN_EVSPLATFI },
4240 { 0, CODE_FOR_spe_evsplati, "__builtin_spe_evsplati", SPE_BUILTIN_EVSPLATI },
4241
4242 /* Place-holder. Leave as last unary SPE builtin. */
4243 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
4244};
4245
4246static rtx
92898235 4247rs6000_expand_unop_builtin (icode, arglist, target)
2212663f
DB
4248 enum insn_code icode;
4249 tree arglist;
4250 rtx target;
4251{
4252 rtx pat;
4253 tree arg0 = TREE_VALUE (arglist);
4254 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4255 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4256 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4257
0559cc77
DE
4258 if (icode == CODE_FOR_nothing)
4259 /* Builtin not supported on this processor. */
4260 return 0;
4261
20e26713
AH
4262 /* If we got invalid arguments bail out before generating bad rtl. */
4263 if (arg0 == error_mark_node)
9a171fcd 4264 return const0_rtx;
20e26713 4265
0559cc77
DE
4266 if (icode == CODE_FOR_altivec_vspltisb
4267 || icode == CODE_FOR_altivec_vspltish
4268 || icode == CODE_FOR_altivec_vspltisw
4269 || icode == CODE_FOR_spe_evsplatfi
4270 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
4271 {
4272 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
4273 if (GET_CODE (op0) != CONST_INT
4274 || INTVAL (op0) > 0x1f
4275 || INTVAL (op0) < -0x1f)
4276 {
4277 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 4278 return const0_rtx;
b44140e7 4279 }
b44140e7
AH
4280 }
4281
c62f2db5 4282 if (target == 0
2212663f
DB
4283 || GET_MODE (target) != tmode
4284 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4285 target = gen_reg_rtx (tmode);
4286
4287 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4288 op0 = copy_to_mode_reg (mode0, op0);
4289
4290 pat = GEN_FCN (icode) (target, op0);
4291 if (! pat)
4292 return 0;
4293 emit_insn (pat);
0ac081f6 4294
2212663f
DB
4295 return target;
4296}
ae4b4a02 4297
100c4561
AH
4298static rtx
4299altivec_expand_abs_builtin (icode, arglist, target)
4300 enum insn_code icode;
4301 tree arglist;
4302 rtx target;
4303{
4304 rtx pat, scratch1, scratch2;
4305 tree arg0 = TREE_VALUE (arglist);
4306 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4307 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4308 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4309
4310 /* If we have invalid arguments, bail out before generating bad rtl. */
4311 if (arg0 == error_mark_node)
9a171fcd 4312 return const0_rtx;
100c4561
AH
4313
4314 if (target == 0
4315 || GET_MODE (target) != tmode
4316 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4317 target = gen_reg_rtx (tmode);
4318
4319 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4320 op0 = copy_to_mode_reg (mode0, op0);
4321
4322 scratch1 = gen_reg_rtx (mode0);
4323 scratch2 = gen_reg_rtx (mode0);
4324
4325 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
4326 if (! pat)
4327 return 0;
4328 emit_insn (pat);
4329
4330 return target;
4331}
4332
0ac081f6 4333static rtx
92898235 4334rs6000_expand_binop_builtin (icode, arglist, target)
0ac081f6
AH
4335 enum insn_code icode;
4336 tree arglist;
4337 rtx target;
4338{
4339 rtx pat;
4340 tree arg0 = TREE_VALUE (arglist);
4341 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4342 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4343 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4344 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4345 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4346 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4347
0559cc77
DE
4348 if (icode == CODE_FOR_nothing)
4349 /* Builtin not supported on this processor. */
4350 return 0;
4351
20e26713
AH
4352 /* If we got invalid arguments bail out before generating bad rtl. */
4353 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4354 return const0_rtx;
20e26713 4355
0559cc77
DE
4356 if (icode == CODE_FOR_altivec_vcfux
4357 || icode == CODE_FOR_altivec_vcfsx
4358 || icode == CODE_FOR_altivec_vctsxs
4359 || icode == CODE_FOR_altivec_vctuxs
4360 || icode == CODE_FOR_altivec_vspltb
4361 || icode == CODE_FOR_altivec_vsplth
4362 || icode == CODE_FOR_altivec_vspltw
4363 || icode == CODE_FOR_spe_evaddiw
4364 || icode == CODE_FOR_spe_evldd
4365 || icode == CODE_FOR_spe_evldh
4366 || icode == CODE_FOR_spe_evldw
4367 || icode == CODE_FOR_spe_evlhhesplat
4368 || icode == CODE_FOR_spe_evlhhossplat
4369 || icode == CODE_FOR_spe_evlhhousplat
4370 || icode == CODE_FOR_spe_evlwhe
4371 || icode == CODE_FOR_spe_evlwhos
4372 || icode == CODE_FOR_spe_evlwhou
4373 || icode == CODE_FOR_spe_evlwhsplat
4374 || icode == CODE_FOR_spe_evlwwsplat
4375 || icode == CODE_FOR_spe_evrlwi
4376 || icode == CODE_FOR_spe_evslwi
4377 || icode == CODE_FOR_spe_evsrwis
4378 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
4379 {
4380 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
4381 if (TREE_CODE (arg1) != INTEGER_CST
4382 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4383 {
4384 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 4385 return const0_rtx;
b44140e7 4386 }
b44140e7
AH
4387 }
4388
c62f2db5 4389 if (target == 0
0ac081f6
AH
4390 || GET_MODE (target) != tmode
4391 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4392 target = gen_reg_rtx (tmode);
4393
4394 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4395 op0 = copy_to_mode_reg (mode0, op0);
4396 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4397 op1 = copy_to_mode_reg (mode1, op1);
4398
4399 pat = GEN_FCN (icode) (target, op0, op1);
4400 if (! pat)
4401 return 0;
4402 emit_insn (pat);
4403
4404 return target;
4405}
6525c0e7 4406
ae4b4a02
AH
4407static rtx
4408altivec_expand_predicate_builtin (icode, opcode, arglist, target)
4409 enum insn_code icode;
4410 const char *opcode;
4411 tree arglist;
4412 rtx target;
4413{
4414 rtx pat, scratch;
4415 tree cr6_form = TREE_VALUE (arglist);
4416 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
4417 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4418 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4419 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4420 enum machine_mode tmode = SImode;
4421 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4422 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4423 int cr6_form_int;
4424
4425 if (TREE_CODE (cr6_form) != INTEGER_CST)
4426 {
4427 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 4428 return const0_rtx;
ae4b4a02
AH
4429 }
4430 else
4431 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
4432
4433 if (mode0 != mode1)
4434 abort ();
4435
4436 /* If we have invalid arguments, bail out before generating bad rtl. */
4437 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4438 return const0_rtx;
ae4b4a02
AH
4439
4440 if (target == 0
4441 || GET_MODE (target) != tmode
4442 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4443 target = gen_reg_rtx (tmode);
4444
4445 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4446 op0 = copy_to_mode_reg (mode0, op0);
4447 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4448 op1 = copy_to_mode_reg (mode1, op1);
4449
4450 scratch = gen_reg_rtx (mode0);
4451
4452 pat = GEN_FCN (icode) (scratch, op0, op1,
4453 gen_rtx (SYMBOL_REF, Pmode, opcode));
4454 if (! pat)
4455 return 0;
4456 emit_insn (pat);
4457
4458 /* The vec_any* and vec_all* predicates use the same opcodes for two
4459 different operations, but the bits in CR6 will be different
4460 depending on what information we want. So we have to play tricks
4461 with CR6 to get the right bits out.
4462
4463 If you think this is disgusting, look at the specs for the
4464 AltiVec predicates. */
4465
4466 switch (cr6_form_int)
4467 {
4468 case 0:
4469 emit_insn (gen_cr6_test_for_zero (target));
4470 break;
4471 case 1:
4472 emit_insn (gen_cr6_test_for_zero_reverse (target));
4473 break;
4474 case 2:
4475 emit_insn (gen_cr6_test_for_lt (target));
4476 break;
4477 case 3:
4478 emit_insn (gen_cr6_test_for_lt_reverse (target));
4479 break;
4480 default:
4481 error ("argument 1 of __builtin_altivec_predicate is out of range");
4482 break;
4483 }
4484
4485 return target;
4486}
4487
6525c0e7
AH
4488static rtx
4489altivec_expand_stv_builtin (icode, arglist)
4490 enum insn_code icode;
4491 tree arglist;
4492{
4493 tree arg0 = TREE_VALUE (arglist);
4494 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4495 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4496 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4497 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4498 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4499 rtx pat;
4500 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
4501 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
4502 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
4503
4504 /* Invalid arguments. Bail before doing anything stoopid! */
4505 if (arg0 == error_mark_node
4506 || arg1 == error_mark_node
4507 || arg2 == error_mark_node)
9a171fcd 4508 return const0_rtx;
6525c0e7
AH
4509
4510 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
4511 op0 = copy_to_mode_reg (mode2, op0);
4512 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
4513 op1 = copy_to_mode_reg (mode0, op1);
4514 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
4515 op2 = copy_to_mode_reg (mode1, op2);
4516
4517 pat = GEN_FCN (icode) (op1, op2, op0);
4518 if (pat)
4519 emit_insn (pat);
4520 return NULL_RTX;
4521}
4522
2212663f 4523static rtx
92898235 4524rs6000_expand_ternop_builtin (icode, arglist, target)
2212663f
DB
4525 enum insn_code icode;
4526 tree arglist;
4527 rtx target;
4528{
4529 rtx pat;
4530 tree arg0 = TREE_VALUE (arglist);
4531 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4532 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4533 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4534 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4535 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4536 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4537 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4538 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4539 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 4540
774b5662
DE
4541 if (icode == CODE_FOR_nothing)
4542 /* Builtin not supported on this processor. */
4543 return 0;
4544
20e26713
AH
4545 /* If we got invalid arguments bail out before generating bad rtl. */
4546 if (arg0 == error_mark_node
4547 || arg1 == error_mark_node
4548 || arg2 == error_mark_node)
9a171fcd 4549 return const0_rtx;
20e26713 4550
774b5662
DE
4551 if (icode == CODE_FOR_altivec_vsldoi_4sf
4552 || icode == CODE_FOR_altivec_vsldoi_4si
4553 || icode == CODE_FOR_altivec_vsldoi_8hi
4554 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
4555 {
4556 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
4557 if (TREE_CODE (arg2) != INTEGER_CST
4558 || TREE_INT_CST_LOW (arg2) & ~0xf)
4559 {
4560 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 4561 return const0_rtx;
b44140e7 4562 }
b44140e7
AH
4563 }
4564
c62f2db5 4565 if (target == 0
2212663f
DB
4566 || GET_MODE (target) != tmode
4567 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4568 target = gen_reg_rtx (tmode);
4569
4570 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4571 op0 = copy_to_mode_reg (mode0, op0);
4572 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4573 op1 = copy_to_mode_reg (mode1, op1);
4574 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
4575 op2 = copy_to_mode_reg (mode2, op2);
4576
4577 pat = GEN_FCN (icode) (target, op0, op1, op2);
4578 if (! pat)
4579 return 0;
4580 emit_insn (pat);
4581
4582 return target;
4583}
92898235 4584
3a9b8c7e 4585/* Expand the lvx builtins. */
0ac081f6 4586static rtx
3a9b8c7e 4587altivec_expand_ld_builtin (exp, target, expandedp)
0ac081f6
AH
4588 tree exp;
4589 rtx target;
92898235 4590 bool *expandedp;
0ac081f6 4591{
0ac081f6
AH
4592 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4593 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 4594 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
4595 tree arg0;
4596 enum machine_mode tmode, mode0;
7c3abc73 4597 rtx pat, op0;
3a9b8c7e 4598 enum insn_code icode;
92898235 4599
0ac081f6
AH
4600 switch (fcode)
4601 {
f18c054f
DB
4602 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
4603 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 4604 break;
f18c054f
DB
4605 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
4606 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
4607 break;
4608 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
4609 icode = CODE_FOR_altivec_lvx_4si;
4610 break;
4611 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
4612 icode = CODE_FOR_altivec_lvx_4sf;
4613 break;
4614 default:
4615 *expandedp = false;
4616 return NULL_RTX;
4617 }
0ac081f6 4618
3a9b8c7e 4619 *expandedp = true;
f18c054f 4620
3a9b8c7e
AH
4621 arg0 = TREE_VALUE (arglist);
4622 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4623 tmode = insn_data[icode].operand[0].mode;
4624 mode0 = insn_data[icode].operand[1].mode;
f18c054f 4625
3a9b8c7e
AH
4626 if (target == 0
4627 || GET_MODE (target) != tmode
4628 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4629 target = gen_reg_rtx (tmode);
24408032 4630
3a9b8c7e
AH
4631 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4632 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 4633
3a9b8c7e
AH
4634 pat = GEN_FCN (icode) (target, op0);
4635 if (! pat)
4636 return 0;
4637 emit_insn (pat);
4638 return target;
4639}
f18c054f 4640
3a9b8c7e
AH
4641/* Expand the stvx builtins. */
4642static rtx
4643altivec_expand_st_builtin (exp, target, expandedp)
4644 tree exp;
7c3abc73 4645 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4646 bool *expandedp;
4647{
4648 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4649 tree arglist = TREE_OPERAND (exp, 1);
4650 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4651 tree arg0, arg1;
4652 enum machine_mode mode0, mode1;
7c3abc73 4653 rtx pat, op0, op1;
3a9b8c7e 4654 enum insn_code icode;
f18c054f 4655
3a9b8c7e
AH
4656 switch (fcode)
4657 {
4658 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
4659 icode = CODE_FOR_altivec_stvx_16qi;
4660 break;
4661 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
4662 icode = CODE_FOR_altivec_stvx_8hi;
4663 break;
4664 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
4665 icode = CODE_FOR_altivec_stvx_4si;
4666 break;
4667 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
4668 icode = CODE_FOR_altivec_stvx_4sf;
4669 break;
4670 default:
4671 *expandedp = false;
4672 return NULL_RTX;
4673 }
24408032 4674
3a9b8c7e
AH
4675 arg0 = TREE_VALUE (arglist);
4676 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4677 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4678 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4679 mode0 = insn_data[icode].operand[0].mode;
4680 mode1 = insn_data[icode].operand[1].mode;
f18c054f 4681
3a9b8c7e
AH
4682 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4683 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
4684 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
4685 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 4686
3a9b8c7e
AH
4687 pat = GEN_FCN (icode) (op0, op1);
4688 if (pat)
4689 emit_insn (pat);
f18c054f 4690
3a9b8c7e
AH
4691 *expandedp = true;
4692 return NULL_RTX;
4693}
f18c054f 4694
3a9b8c7e
AH
4695/* Expand the dst builtins. */
4696static rtx
4697altivec_expand_dst_builtin (exp, target, expandedp)
4698 tree exp;
7c3abc73 4699 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4700 bool *expandedp;
4701{
4702 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4703 tree arglist = TREE_OPERAND (exp, 1);
4704 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4705 tree arg0, arg1, arg2;
4706 enum machine_mode mode0, mode1, mode2;
7c3abc73 4707 rtx pat, op0, op1, op2;
3a9b8c7e 4708 struct builtin_description *d;
a3170dc6 4709 size_t i;
f18c054f 4710
3a9b8c7e 4711 *expandedp = false;
f18c054f 4712
3a9b8c7e
AH
4713 /* Handle DST variants. */
4714 d = (struct builtin_description *) bdesc_dst;
4715 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
4716 if (d->code == fcode)
4717 {
4718 arg0 = TREE_VALUE (arglist);
4719 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4720 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4721 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4722 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4723 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4724 mode0 = insn_data[d->icode].operand[0].mode;
4725 mode1 = insn_data[d->icode].operand[1].mode;
4726 mode2 = insn_data[d->icode].operand[2].mode;
24408032 4727
3a9b8c7e
AH
4728 /* Invalid arguments, bail out before generating bad rtl. */
4729 if (arg0 == error_mark_node
4730 || arg1 == error_mark_node
4731 || arg2 == error_mark_node)
4732 return const0_rtx;
f18c054f 4733
3a9b8c7e
AH
4734 if (TREE_CODE (arg2) != INTEGER_CST
4735 || TREE_INT_CST_LOW (arg2) & ~0x3)
4736 {
4737 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
4738 return const0_rtx;
4739 }
f18c054f 4740
3a9b8c7e
AH
4741 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
4742 op0 = copy_to_mode_reg (mode0, op0);
4743 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
4744 op1 = copy_to_mode_reg (mode1, op1);
24408032 4745
3a9b8c7e
AH
4746 pat = GEN_FCN (d->icode) (op0, op1, op2);
4747 if (pat != 0)
4748 emit_insn (pat);
f18c054f 4749
3a9b8c7e
AH
4750 *expandedp = true;
4751 return NULL_RTX;
4752 }
f18c054f 4753
3a9b8c7e
AH
4754 return NULL_RTX;
4755}
24408032 4756
3a9b8c7e
AH
4757/* Expand the builtin in EXP and store the result in TARGET. Store
4758 true in *EXPANDEDP if we found a builtin to expand. */
4759static rtx
4760altivec_expand_builtin (exp, target, expandedp)
4761 tree exp;
4762 rtx target;
4763 bool *expandedp;
4764{
4765 struct builtin_description *d;
4766 struct builtin_description_predicates *dp;
4767 size_t i;
4768 enum insn_code icode;
4769 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4770 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
4771 tree arg0;
4772 rtx op0, pat;
4773 enum machine_mode tmode, mode0;
3a9b8c7e 4774 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 4775
3a9b8c7e
AH
4776 target = altivec_expand_ld_builtin (exp, target, expandedp);
4777 if (*expandedp)
4778 return target;
0ac081f6 4779
3a9b8c7e
AH
4780 target = altivec_expand_st_builtin (exp, target, expandedp);
4781 if (*expandedp)
4782 return target;
4783
4784 target = altivec_expand_dst_builtin (exp, target, expandedp);
4785 if (*expandedp)
4786 return target;
4787
4788 *expandedp = true;
95385cbb 4789
3a9b8c7e
AH
4790 switch (fcode)
4791 {
6525c0e7
AH
4792 case ALTIVEC_BUILTIN_STVX:
4793 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
4794 case ALTIVEC_BUILTIN_STVEBX:
4795 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
4796 case ALTIVEC_BUILTIN_STVEHX:
4797 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
4798 case ALTIVEC_BUILTIN_STVEWX:
4799 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
4800 case ALTIVEC_BUILTIN_STVXL:
4801 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 4802
95385cbb
AH
4803 case ALTIVEC_BUILTIN_MFVSCR:
4804 icode = CODE_FOR_altivec_mfvscr;
4805 tmode = insn_data[icode].operand[0].mode;
4806
4807 if (target == 0
4808 || GET_MODE (target) != tmode
4809 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4810 target = gen_reg_rtx (tmode);
4811
4812 pat = GEN_FCN (icode) (target);
0ac081f6
AH
4813 if (! pat)
4814 return 0;
4815 emit_insn (pat);
95385cbb
AH
4816 return target;
4817
4818 case ALTIVEC_BUILTIN_MTVSCR:
4819 icode = CODE_FOR_altivec_mtvscr;
4820 arg0 = TREE_VALUE (arglist);
4821 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4822 mode0 = insn_data[icode].operand[0].mode;
4823
4824 /* If we got invalid arguments bail out before generating bad rtl. */
4825 if (arg0 == error_mark_node)
9a171fcd 4826 return const0_rtx;
95385cbb
AH
4827
4828 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4829 op0 = copy_to_mode_reg (mode0, op0);
4830
4831 pat = GEN_FCN (icode) (op0);
4832 if (pat)
4833 emit_insn (pat);
4834 return NULL_RTX;
3a9b8c7e 4835
95385cbb
AH
4836 case ALTIVEC_BUILTIN_DSSALL:
4837 emit_insn (gen_altivec_dssall ());
4838 return NULL_RTX;
4839
4840 case ALTIVEC_BUILTIN_DSS:
4841 icode = CODE_FOR_altivec_dss;
4842 arg0 = TREE_VALUE (arglist);
4843 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4844 mode0 = insn_data[icode].operand[0].mode;
4845
4846 /* If we got invalid arguments bail out before generating bad rtl. */
4847 if (arg0 == error_mark_node)
9a171fcd 4848 return const0_rtx;
95385cbb 4849
b44140e7
AH
4850 if (TREE_CODE (arg0) != INTEGER_CST
4851 || TREE_INT_CST_LOW (arg0) & ~0x3)
4852 {
4853 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 4854 return const0_rtx;
b44140e7
AH
4855 }
4856
95385cbb
AH
4857 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4858 op0 = copy_to_mode_reg (mode0, op0);
4859
4860 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
4861 return NULL_RTX;
4862 }
24408032 4863
100c4561
AH
4864 /* Expand abs* operations. */
4865 d = (struct builtin_description *) bdesc_abs;
ca7558fc 4866 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
4867 if (d->code == fcode)
4868 return altivec_expand_abs_builtin (d->icode, arglist, target);
4869
ae4b4a02
AH
4870 /* Expand the AltiVec predicates. */
4871 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 4872 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
4873 if (dp->code == fcode)
4874 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
4875
6525c0e7
AH
4876 /* LV* are funky. We initialized them differently. */
4877 switch (fcode)
4878 {
4879 case ALTIVEC_BUILTIN_LVSL:
92898235 4880 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
4881 arglist, target);
4882 case ALTIVEC_BUILTIN_LVSR:
92898235
AH
4883 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
4884 arglist, target);
6525c0e7 4885 case ALTIVEC_BUILTIN_LVEBX:
92898235
AH
4886 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
4887 arglist, target);
6525c0e7 4888 case ALTIVEC_BUILTIN_LVEHX:
92898235
AH
4889 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
4890 arglist, target);
6525c0e7 4891 case ALTIVEC_BUILTIN_LVEWX:
92898235
AH
4892 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
4893 arglist, target);
6525c0e7 4894 case ALTIVEC_BUILTIN_LVXL:
92898235
AH
4895 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
4896 arglist, target);
6525c0e7 4897 case ALTIVEC_BUILTIN_LVX:
92898235
AH
4898 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
4899 arglist, target);
6525c0e7
AH
4900 default:
4901 break;
4902 /* Fall through. */
4903 }
95385cbb 4904
92898235 4905 *expandedp = false;
0ac081f6
AH
4906 return NULL_RTX;
4907}
4908
a3170dc6
AH
4909/* Binops that need to be initialized manually, but can be expanded
4910 automagically by rs6000_expand_binop_builtin. */
4911static struct builtin_description bdesc_2arg_spe[] =
4912{
4913 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
4914 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
4915 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
4916 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
4917 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
4918 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
4919 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
4920 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
4921 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
4922 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
4923 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
4924 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
4925 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
4926 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
4927 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
4928 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
4929 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
4930 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
4931 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
4932 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
4933 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
4934 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
4935};
4936
4937/* Expand the builtin in EXP and store the result in TARGET. Store
4938 true in *EXPANDEDP if we found a builtin to expand.
4939
4940 This expands the SPE builtins that are not simple unary and binary
4941 operations. */
4942static rtx
4943spe_expand_builtin (exp, target, expandedp)
4944 tree exp;
4945 rtx target;
4946 bool *expandedp;
4947{
4948 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4949 tree arglist = TREE_OPERAND (exp, 1);
4950 tree arg1, arg0;
4951 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4952 enum insn_code icode;
4953 enum machine_mode tmode, mode0;
4954 rtx pat, op0;
4955 struct builtin_description *d;
4956 size_t i;
4957
4958 *expandedp = true;
4959
4960 /* Syntax check for a 5-bit unsigned immediate. */
4961 switch (fcode)
4962 {
4963 case SPE_BUILTIN_EVSTDD:
4964 case SPE_BUILTIN_EVSTDH:
4965 case SPE_BUILTIN_EVSTDW:
4966 case SPE_BUILTIN_EVSTWHE:
4967 case SPE_BUILTIN_EVSTWHO:
4968 case SPE_BUILTIN_EVSTWWE:
4969 case SPE_BUILTIN_EVSTWWO:
4970 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4971 if (TREE_CODE (arg1) != INTEGER_CST
4972 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4973 {
4974 error ("argument 2 must be a 5-bit unsigned literal");
4975 return const0_rtx;
4976 }
4977 break;
4978 default:
4979 break;
4980 }
4981
4982 d = (struct builtin_description *) bdesc_2arg_spe;
4983 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
4984 if (d->code == fcode)
4985 return rs6000_expand_binop_builtin (d->icode, arglist, target);
4986
4987 d = (struct builtin_description *) bdesc_spe_predicates;
4988 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
4989 if (d->code == fcode)
4990 return spe_expand_predicate_builtin (d->icode, arglist, target);
4991
4992 d = (struct builtin_description *) bdesc_spe_evsel;
4993 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
4994 if (d->code == fcode)
4995 return spe_expand_evsel_builtin (d->icode, arglist, target);
4996
4997 switch (fcode)
4998 {
4999 case SPE_BUILTIN_EVSTDDX:
5000 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
5001 case SPE_BUILTIN_EVSTDHX:
5002 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
5003 case SPE_BUILTIN_EVSTDWX:
5004 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
5005 case SPE_BUILTIN_EVSTWHEX:
5006 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
5007 case SPE_BUILTIN_EVSTWHOX:
5008 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
5009 case SPE_BUILTIN_EVSTWWEX:
5010 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
5011 case SPE_BUILTIN_EVSTWWOX:
5012 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
5013 case SPE_BUILTIN_EVSTDD:
5014 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
5015 case SPE_BUILTIN_EVSTDH:
5016 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
5017 case SPE_BUILTIN_EVSTDW:
5018 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
5019 case SPE_BUILTIN_EVSTWHE:
5020 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
5021 case SPE_BUILTIN_EVSTWHO:
5022 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
5023 case SPE_BUILTIN_EVSTWWE:
5024 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
5025 case SPE_BUILTIN_EVSTWWO:
5026 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
5027 case SPE_BUILTIN_MFSPEFSCR:
5028 icode = CODE_FOR_spe_mfspefscr;
5029 tmode = insn_data[icode].operand[0].mode;
5030
5031 if (target == 0
5032 || GET_MODE (target) != tmode
5033 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5034 target = gen_reg_rtx (tmode);
5035
5036 pat = GEN_FCN (icode) (target);
5037 if (! pat)
5038 return 0;
5039 emit_insn (pat);
5040 return target;
5041 case SPE_BUILTIN_MTSPEFSCR:
5042 icode = CODE_FOR_spe_mtspefscr;
5043 arg0 = TREE_VALUE (arglist);
5044 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5045 mode0 = insn_data[icode].operand[0].mode;
5046
5047 if (arg0 == error_mark_node)
5048 return const0_rtx;
5049
5050 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5051 op0 = copy_to_mode_reg (mode0, op0);
5052
5053 pat = GEN_FCN (icode) (op0);
5054 if (pat)
5055 emit_insn (pat);
5056 return NULL_RTX;
5057 default:
5058 break;
5059 }
5060
5061 *expandedp = false;
5062 return NULL_RTX;
5063}
5064
5065static rtx
5066spe_expand_predicate_builtin (icode, arglist, target)
5067 enum insn_code icode;
5068 tree arglist;
5069 rtx target;
5070{
5071 rtx pat, scratch, tmp;
5072 tree form = TREE_VALUE (arglist);
5073 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5074 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5075 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5076 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5077 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5078 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5079 int form_int;
5080 enum rtx_code code;
5081
5082 if (TREE_CODE (form) != INTEGER_CST)
5083 {
5084 error ("argument 1 of __builtin_spe_predicate must be a constant");
5085 return const0_rtx;
5086 }
5087 else
5088 form_int = TREE_INT_CST_LOW (form);
5089
5090 if (mode0 != mode1)
5091 abort ();
5092
5093 if (arg0 == error_mark_node || arg1 == error_mark_node)
5094 return const0_rtx;
5095
5096 if (target == 0
5097 || GET_MODE (target) != SImode
5098 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
5099 target = gen_reg_rtx (SImode);
5100
5101 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5102 op0 = copy_to_mode_reg (mode0, op0);
5103 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5104 op1 = copy_to_mode_reg (mode1, op1);
5105
5106 scratch = gen_reg_rtx (CCmode);
5107
5108 pat = GEN_FCN (icode) (scratch, op0, op1);
5109 if (! pat)
5110 return const0_rtx;
5111 emit_insn (pat);
5112
5113 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
5114 _lower_. We use one compare, but look in different bits of the
5115 CR for each variant.
5116
5117 There are 2 elements in each SPE simd type (upper/lower). The CR
5118 bits are set as follows:
5119
5120 BIT0 | BIT 1 | BIT 2 | BIT 3
5121 U | L | (U | L) | (U & L)
5122
5123 So, for an "all" relationship, BIT 3 would be set.
5124 For an "any" relationship, BIT 2 would be set. Etc.
5125
5126 Following traditional nomenclature, these bits map to:
5127
5128 BIT0 | BIT 1 | BIT 2 | BIT 3
5129 LT | GT | EQ | OV
5130
5131 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
5132 */
5133
5134 switch (form_int)
5135 {
5136 /* All variant. OV bit. */
5137 case 0:
5138 /* We need to get to the OV bit, which is the ORDERED bit. We
5139 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
5140 that's ugly and will trigger a validate_condition_mode abort.
5141 So let's just use another pattern. */
5142 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
5143 return target;
5144 /* Any variant. EQ bit. */
5145 case 1:
5146 code = EQ;
5147 break;
5148 /* Upper variant. LT bit. */
5149 case 2:
5150 code = LT;
5151 break;
5152 /* Lower variant. GT bit. */
5153 case 3:
5154 code = GT;
5155 break;
5156 default:
5157 error ("argument 1 of __builtin_spe_predicate is out of range");
5158 return const0_rtx;
5159 }
5160
5161 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
5162 emit_move_insn (target, tmp);
5163
5164 return target;
5165}
5166
5167/* The evsel builtins look like this:
5168
5169 e = __builtin_spe_evsel_OP (a, b, c, d);
5170
5171 and work like this:
5172
5173 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
5174 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
5175*/
5176
5177static rtx
5178spe_expand_evsel_builtin (icode, arglist, target)
5179 enum insn_code icode;
5180 tree arglist;
5181 rtx target;
5182{
5183 rtx pat, scratch;
5184 tree arg0 = TREE_VALUE (arglist);
5185 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5186 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5187 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
5188 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5189 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5190 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5191 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
5192 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5193 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5194
5195 if (mode0 != mode1)
5196 abort ();
5197
5198 if (arg0 == error_mark_node || arg1 == error_mark_node
5199 || arg2 == error_mark_node || arg3 == error_mark_node)
5200 return const0_rtx;
5201
5202 if (target == 0
5203 || GET_MODE (target) != mode0
5204 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
5205 target = gen_reg_rtx (mode0);
5206
5207 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5208 op0 = copy_to_mode_reg (mode0, op0);
5209 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5210 op1 = copy_to_mode_reg (mode0, op1);
5211 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5212 op2 = copy_to_mode_reg (mode0, op2);
5213 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
5214 op3 = copy_to_mode_reg (mode0, op3);
5215
5216 /* Generate the compare. */
5217 scratch = gen_reg_rtx (CCmode);
5218 pat = GEN_FCN (icode) (scratch, op0, op1);
5219 if (! pat)
5220 return const0_rtx;
5221 emit_insn (pat);
5222
5223 if (mode0 == V2SImode)
5224 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
5225 else
5226 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
5227
5228 return target;
5229}
5230
0ac081f6
AH
5231/* Expand an expression EXP that calls a built-in function,
5232 with result going to TARGET if that's convenient
5233 (and in mode MODE if that's convenient).
5234 SUBTARGET may be used as the target for computing one of EXP's operands.
5235 IGNORE is nonzero if the value is to be ignored. */
5236
5237static rtx
5238rs6000_expand_builtin (exp, target, subtarget, mode, ignore)
5239 tree exp;
5240 rtx target;
00b960c7
AH
5241 rtx subtarget ATTRIBUTE_UNUSED;
5242 enum machine_mode mode ATTRIBUTE_UNUSED;
5243 int ignore ATTRIBUTE_UNUSED;
0ac081f6 5244{
92898235
AH
5245 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5246 tree arglist = TREE_OPERAND (exp, 1);
5247 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5248 struct builtin_description *d;
5249 size_t i;
5250 rtx ret;
5251 bool success;
5252
0ac081f6 5253 if (TARGET_ALTIVEC)
92898235
AH
5254 {
5255 ret = altivec_expand_builtin (exp, target, &success);
5256
a3170dc6
AH
5257 if (success)
5258 return ret;
5259 }
5260 if (TARGET_SPE)
5261 {
5262 ret = spe_expand_builtin (exp, target, &success);
5263
92898235
AH
5264 if (success)
5265 return ret;
5266 }
5267
0559cc77
DE
5268 if (TARGET_ALTIVEC || TARGET_SPE)
5269 {
5270 /* Handle simple unary operations. */
5271 d = (struct builtin_description *) bdesc_1arg;
5272 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
5273 if (d->code == fcode)
5274 return rs6000_expand_unop_builtin (d->icode, arglist, target);
5275
5276 /* Handle simple binary operations. */
5277 d = (struct builtin_description *) bdesc_2arg;
5278 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
5279 if (d->code == fcode)
5280 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5281
5282 /* Handle simple ternary operations. */
5283 d = (struct builtin_description *) bdesc_3arg;
5284 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
5285 if (d->code == fcode)
5286 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
5287 }
0ac081f6
AH
5288
5289 abort ();
92898235 5290 return NULL_RTX;
0ac081f6
AH
5291}
5292
5293static void
6fa3f289 5294rs6000_init_builtins ()
0ac081f6 5295{
a3170dc6
AH
5296 if (TARGET_SPE)
5297 spe_init_builtins ();
0ac081f6
AH
5298 if (TARGET_ALTIVEC)
5299 altivec_init_builtins ();
0559cc77
DE
5300 if (TARGET_ALTIVEC || TARGET_SPE)
5301 rs6000_common_init_builtins ();
0ac081f6
AH
5302}
5303
a3170dc6
AH
5304/* Search through a set of builtins and enable the mask bits.
5305 DESC is an array of builtins.
b6d08ca1 5306 SIZE is the total number of builtins.
a3170dc6
AH
5307 START is the builtin enum at which to start.
5308 END is the builtin enum at which to end. */
0ac081f6 5309static void
a3170dc6
AH
5310enable_mask_for_builtins (desc, size, start, end)
5311 struct builtin_description *desc;
5312 int size;
5313 enum rs6000_builtins start, end;
5314{
5315 int i;
5316
5317 for (i = 0; i < size; ++i)
5318 if (desc[i].code == start)
5319 break;
5320
5321 if (i == size)
5322 return;
5323
5324 for (; i < size; ++i)
5325 {
5326 /* Flip all the bits on. */
5327 desc[i].mask = target_flags;
5328 if (desc[i].code == end)
5329 break;
5330 }
5331}
5332
5333static void
b24c9d35 5334spe_init_builtins ()
0ac081f6 5335{
a3170dc6
AH
5336 tree endlink = void_list_node;
5337 tree puint_type_node = build_pointer_type (unsigned_type_node);
5338 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
5339 tree pv2si_type_node = build_pointer_type (V2SI_type_node);
ae4b4a02 5340 struct builtin_description *d;
0ac081f6
AH
5341 size_t i;
5342
a3170dc6
AH
5343 tree v2si_ftype_4_v2si
5344 = build_function_type
5345 (V2SI_type_node,
5346 tree_cons (NULL_TREE, V2SI_type_node,
5347 tree_cons (NULL_TREE, V2SI_type_node,
5348 tree_cons (NULL_TREE, V2SI_type_node,
5349 tree_cons (NULL_TREE, V2SI_type_node,
5350 endlink)))));
5351
5352 tree v2sf_ftype_4_v2sf
5353 = build_function_type
5354 (V2SF_type_node,
5355 tree_cons (NULL_TREE, V2SF_type_node,
5356 tree_cons (NULL_TREE, V2SF_type_node,
5357 tree_cons (NULL_TREE, V2SF_type_node,
5358 tree_cons (NULL_TREE, V2SF_type_node,
5359 endlink)))));
5360
5361 tree int_ftype_int_v2si_v2si
5362 = build_function_type
5363 (integer_type_node,
5364 tree_cons (NULL_TREE, integer_type_node,
5365 tree_cons (NULL_TREE, V2SI_type_node,
5366 tree_cons (NULL_TREE, V2SI_type_node,
5367 endlink))));
5368
5369 tree int_ftype_int_v2sf_v2sf
5370 = build_function_type
5371 (integer_type_node,
5372 tree_cons (NULL_TREE, integer_type_node,
5373 tree_cons (NULL_TREE, V2SF_type_node,
5374 tree_cons (NULL_TREE, V2SF_type_node,
5375 endlink))));
5376
5377 tree void_ftype_v2si_puint_int
5378 = build_function_type (void_type_node,
5379 tree_cons (NULL_TREE, V2SI_type_node,
5380 tree_cons (NULL_TREE, puint_type_node,
5381 tree_cons (NULL_TREE,
5382 integer_type_node,
5383 endlink))));
5384
5385 tree void_ftype_v2si_puint_char
5386 = build_function_type (void_type_node,
5387 tree_cons (NULL_TREE, V2SI_type_node,
5388 tree_cons (NULL_TREE, puint_type_node,
5389 tree_cons (NULL_TREE,
5390 char_type_node,
5391 endlink))));
5392
5393 tree void_ftype_v2si_pv2si_int
5394 = build_function_type (void_type_node,
5395 tree_cons (NULL_TREE, V2SI_type_node,
5396 tree_cons (NULL_TREE, pv2si_type_node,
5397 tree_cons (NULL_TREE,
5398 integer_type_node,
5399 endlink))));
5400
5401 tree void_ftype_v2si_pv2si_char
5402 = build_function_type (void_type_node,
5403 tree_cons (NULL_TREE, V2SI_type_node,
5404 tree_cons (NULL_TREE, pv2si_type_node,
5405 tree_cons (NULL_TREE,
5406 char_type_node,
5407 endlink))));
5408
5409 tree void_ftype_int
5410 = build_function_type (void_type_node,
5411 tree_cons (NULL_TREE, integer_type_node, endlink));
5412
5413 tree int_ftype_void
5414 = build_function_type (integer_type_node,
5415 tree_cons (NULL_TREE, void_type_node, endlink));
5416
5417 tree v2si_ftype_pv2si_int
5418 = build_function_type (V2SI_type_node,
5419 tree_cons (NULL_TREE, pv2si_type_node,
5420 tree_cons (NULL_TREE, integer_type_node,
5421 endlink)));
5422
5423 tree v2si_ftype_puint_int
5424 = build_function_type (V2SI_type_node,
5425 tree_cons (NULL_TREE, puint_type_node,
5426 tree_cons (NULL_TREE, integer_type_node,
5427 endlink)));
5428
5429 tree v2si_ftype_pushort_int
5430 = build_function_type (V2SI_type_node,
5431 tree_cons (NULL_TREE, pushort_type_node,
5432 tree_cons (NULL_TREE, integer_type_node,
5433 endlink)));
5434
5435 /* The initialization of the simple binary and unary builtins is
5436 done in rs6000_common_init_builtins, but we have to enable the
5437 mask bits here manually because we have run out of `target_flags'
5438 bits. We really need to redesign this mask business. */
5439
5440 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
5441 ARRAY_SIZE (bdesc_2arg),
5442 SPE_BUILTIN_EVADDW,
5443 SPE_BUILTIN_EVXOR);
5444 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
5445 ARRAY_SIZE (bdesc_1arg),
5446 SPE_BUILTIN_EVABS,
5447 SPE_BUILTIN_EVSUBFUSIAAW);
5448 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
5449 ARRAY_SIZE (bdesc_spe_predicates),
5450 SPE_BUILTIN_EVCMPEQ,
5451 SPE_BUILTIN_EVFSTSTLT);
5452 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
5453 ARRAY_SIZE (bdesc_spe_evsel),
5454 SPE_BUILTIN_EVSEL_CMPGTS,
5455 SPE_BUILTIN_EVSEL_FSTSTEQ);
5456
5457 /* Initialize irregular SPE builtins. */
5458
5459 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
5460 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
5461 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
5462 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
5463 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
5464 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
5465 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
5466 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
5467 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
5468 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
5469 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
5470 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
5471 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
5472 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
5473 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
5474 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
5475
5476 /* Loads. */
5477 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
5478 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
5479 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
5480 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
5481 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
5482 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
5483 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
5484 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
5485 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
5486 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
5487 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
5488 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
5489 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
5490 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
5491 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
5492 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
5493 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
5494 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
5495 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
5496 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
5497 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
5498 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
5499
5500 /* Predicates. */
5501 d = (struct builtin_description *) bdesc_spe_predicates;
5502 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
5503 {
5504 tree type;
5505
5506 switch (insn_data[d->icode].operand[1].mode)
5507 {
5508 case V2SImode:
5509 type = int_ftype_int_v2si_v2si;
5510 break;
5511 case V2SFmode:
5512 type = int_ftype_int_v2sf_v2sf;
5513 break;
5514 default:
5515 abort ();
5516 }
5517
5518 def_builtin (d->mask, d->name, type, d->code);
5519 }
5520
5521 /* Evsel predicates. */
5522 d = (struct builtin_description *) bdesc_spe_evsel;
5523 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
5524 {
5525 tree type;
5526
5527 switch (insn_data[d->icode].operand[1].mode)
5528 {
5529 case V2SImode:
5530 type = v2si_ftype_4_v2si;
5531 break;
5532 case V2SFmode:
5533 type = v2sf_ftype_4_v2sf;
5534 break;
5535 default:
5536 abort ();
5537 }
5538
5539 def_builtin (d->mask, d->name, type, d->code);
5540 }
5541}
5542
5543static void
b24c9d35 5544altivec_init_builtins ()
a3170dc6
AH
5545{
5546 struct builtin_description *d;
5547 struct builtin_description_predicates *dp;
5548 size_t i;
5549 tree pfloat_type_node = build_pointer_type (float_type_node);
5550 tree pint_type_node = build_pointer_type (integer_type_node);
5551 tree pshort_type_node = build_pointer_type (short_integer_type_node);
5552 tree pchar_type_node = build_pointer_type (char_type_node);
5553
5554 tree pvoid_type_node = build_pointer_type (void_type_node);
5555
0dbc3651
ZW
5556 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
5557 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
5558 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
5559 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
5560
5561 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
5562
a3170dc6
AH
5563 tree int_ftype_int_v4si_v4si
5564 = build_function_type_list (integer_type_node,
5565 integer_type_node, V4SI_type_node,
5566 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5567 tree v4sf_ftype_pcfloat
5568 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 5569 tree void_ftype_pfloat_v4sf
b4de2f7d 5570 = build_function_type_list (void_type_node,
a3170dc6 5571 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
5572 tree v4si_ftype_pcint
5573 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
5574 tree void_ftype_pint_v4si
b4de2f7d
AH
5575 = build_function_type_list (void_type_node,
5576 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5577 tree v8hi_ftype_pcshort
5578 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 5579 tree void_ftype_pshort_v8hi
b4de2f7d
AH
5580 = build_function_type_list (void_type_node,
5581 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
5582 tree v16qi_ftype_pcchar
5583 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 5584 tree void_ftype_pchar_v16qi
b4de2f7d
AH
5585 = build_function_type_list (void_type_node,
5586 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 5587 tree void_ftype_v4si
b4de2f7d 5588 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5589 tree v8hi_ftype_void
5590 = build_function_type (V8HI_type_node, void_list_node);
5591 tree void_ftype_void
5592 = build_function_type (void_type_node, void_list_node);
5593 tree void_ftype_qi
5594 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651
ZW
5595
5596 tree v16qi_ftype_int_pcvoid
a3170dc6 5597 = build_function_type_list (V16QI_type_node,
0dbc3651
ZW
5598 integer_type_node, pcvoid_type_node, NULL_TREE);
5599 tree v8hi_ftype_int_pcvoid
a3170dc6 5600 = build_function_type_list (V8HI_type_node,
0dbc3651
ZW
5601 integer_type_node, pcvoid_type_node, NULL_TREE);
5602 tree v4si_ftype_int_pcvoid
a3170dc6 5603 = build_function_type_list (V4SI_type_node,
0dbc3651
ZW
5604 integer_type_node, pcvoid_type_node, NULL_TREE);
5605
14b32f4e 5606 tree void_ftype_v4si_int_pvoid
b4de2f7d
AH
5607 = build_function_type_list (void_type_node,
5608 V4SI_type_node, integer_type_node,
5609 pvoid_type_node, NULL_TREE);
6525c0e7 5610 tree void_ftype_v16qi_int_pvoid
b4de2f7d
AH
5611 = build_function_type_list (void_type_node,
5612 V16QI_type_node, integer_type_node,
5613 pvoid_type_node, NULL_TREE);
6525c0e7 5614 tree void_ftype_v8hi_int_pvoid
b4de2f7d
AH
5615 = build_function_type_list (void_type_node,
5616 V8HI_type_node, integer_type_node,
5617 pvoid_type_node, NULL_TREE);
a3170dc6
AH
5618 tree int_ftype_int_v8hi_v8hi
5619 = build_function_type_list (integer_type_node,
5620 integer_type_node, V8HI_type_node,
5621 V8HI_type_node, NULL_TREE);
5622 tree int_ftype_int_v16qi_v16qi
5623 = build_function_type_list (integer_type_node,
5624 integer_type_node, V16QI_type_node,
5625 V16QI_type_node, NULL_TREE);
5626 tree int_ftype_int_v4sf_v4sf
5627 = build_function_type_list (integer_type_node,
5628 integer_type_node, V4SF_type_node,
5629 V4SF_type_node, NULL_TREE);
5630 tree v4si_ftype_v4si
5631 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
5632 tree v8hi_ftype_v8hi
5633 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
5634 tree v16qi_ftype_v16qi
5635 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
5636 tree v4sf_ftype_v4sf
5637 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 5638 tree void_ftype_pcvoid_int_char
a3170dc6 5639 = build_function_type_list (void_type_node,
0dbc3651 5640 pcvoid_type_node, integer_type_node,
a3170dc6 5641 char_type_node, NULL_TREE);
0dbc3651
ZW
5642
5643 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
5644 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
5645 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
5646 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
5647 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
5648 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
5649 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
5650 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
5651 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
5652 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
5653 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
5654 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
5655 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
5656 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
5657 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
5658 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
5659 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
5660 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
5661 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
5662 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
0dbc3651
ZW
5663 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL);
5664 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR);
5665 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX);
5666 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX);
5667 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX);
5668 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL);
5669 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX);
a3170dc6
AH
5670 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX);
5671 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX);
5672 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL);
5673 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX);
5674 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX);
5675
5676 /* Add the DST variants. */
5677 d = (struct builtin_description *) bdesc_dst;
5678 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 5679 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
5680
5681 /* Initialize the predicates. */
5682 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
5683 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
5684 {
5685 enum machine_mode mode1;
5686 tree type;
5687
5688 mode1 = insn_data[dp->icode].operand[1].mode;
5689
5690 switch (mode1)
5691 {
5692 case V4SImode:
5693 type = int_ftype_int_v4si_v4si;
5694 break;
5695 case V8HImode:
5696 type = int_ftype_int_v8hi_v8hi;
5697 break;
5698 case V16QImode:
5699 type = int_ftype_int_v16qi_v16qi;
5700 break;
5701 case V4SFmode:
5702 type = int_ftype_int_v4sf_v4sf;
5703 break;
5704 default:
5705 abort ();
5706 }
5707
5708 def_builtin (dp->mask, dp->name, type, dp->code);
5709 }
5710
5711 /* Initialize the abs* operators. */
5712 d = (struct builtin_description *) bdesc_abs;
5713 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
5714 {
5715 enum machine_mode mode0;
5716 tree type;
5717
5718 mode0 = insn_data[d->icode].operand[0].mode;
5719
5720 switch (mode0)
5721 {
5722 case V4SImode:
5723 type = v4si_ftype_v4si;
5724 break;
5725 case V8HImode:
5726 type = v8hi_ftype_v8hi;
5727 break;
5728 case V16QImode:
5729 type = v16qi_ftype_v16qi;
5730 break;
5731 case V4SFmode:
5732 type = v4sf_ftype_v4sf;
5733 break;
5734 default:
5735 abort ();
5736 }
5737
5738 def_builtin (d->mask, d->name, type, d->code);
5739 }
5740}
5741
5742static void
b24c9d35 5743rs6000_common_init_builtins ()
a3170dc6
AH
5744{
5745 struct builtin_description *d;
5746 size_t i;
5747
5748 tree v4sf_ftype_v4sf_v4sf_v16qi
5749 = build_function_type_list (V4SF_type_node,
5750 V4SF_type_node, V4SF_type_node,
5751 V16QI_type_node, NULL_TREE);
5752 tree v4si_ftype_v4si_v4si_v16qi
5753 = build_function_type_list (V4SI_type_node,
5754 V4SI_type_node, V4SI_type_node,
5755 V16QI_type_node, NULL_TREE);
5756 tree v8hi_ftype_v8hi_v8hi_v16qi
5757 = build_function_type_list (V8HI_type_node,
5758 V8HI_type_node, V8HI_type_node,
5759 V16QI_type_node, NULL_TREE);
5760 tree v16qi_ftype_v16qi_v16qi_v16qi
5761 = build_function_type_list (V16QI_type_node,
5762 V16QI_type_node, V16QI_type_node,
5763 V16QI_type_node, NULL_TREE);
5764 tree v4si_ftype_char
5765 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
5766 tree v8hi_ftype_char
5767 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
5768 tree v16qi_ftype_char
5769 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
5770 tree v8hi_ftype_v16qi
5771 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
5772 tree v4sf_ftype_v4sf
5773 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
5774
5775 tree v2si_ftype_v2si_v2si
5776 = build_function_type_list (V2SI_type_node,
5777 V2SI_type_node, V2SI_type_node, NULL_TREE);
5778
5779 tree v2sf_ftype_v2sf_v2sf
5780 = build_function_type_list (V2SF_type_node,
5781 V2SF_type_node, V2SF_type_node, NULL_TREE);
5782
5783 tree v2si_ftype_int_int
5784 = build_function_type_list (V2SI_type_node,
5785 integer_type_node, integer_type_node,
5786 NULL_TREE);
5787
5788 tree v2si_ftype_v2si
5789 = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
5790
5791 tree v2sf_ftype_v2sf
5792 = build_function_type_list (V2SF_type_node,
5793 V2SF_type_node, NULL_TREE);
5794
5795 tree v2sf_ftype_v2si
5796 = build_function_type_list (V2SF_type_node,
5797 V2SI_type_node, NULL_TREE);
5798
5799 tree v2si_ftype_v2sf
5800 = build_function_type_list (V2SI_type_node,
5801 V2SF_type_node, NULL_TREE);
5802
5803 tree v2si_ftype_v2si_char
5804 = build_function_type_list (V2SI_type_node,
5805 V2SI_type_node, char_type_node, NULL_TREE);
5806
5807 tree v2si_ftype_int_char
5808 = build_function_type_list (V2SI_type_node,
5809 integer_type_node, char_type_node, NULL_TREE);
5810
5811 tree v2si_ftype_char
5812 = build_function_type_list (V2SI_type_node, char_type_node, NULL_TREE);
5813
5814 tree int_ftype_int_int
5815 = build_function_type_list (integer_type_node,
5816 integer_type_node, integer_type_node,
5817 NULL_TREE);
95385cbb 5818
0ac081f6 5819 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
5820 = build_function_type_list (V4SI_type_node,
5821 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 5822 tree v4sf_ftype_v4si_char
b4de2f7d
AH
5823 = build_function_type_list (V4SF_type_node,
5824 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 5825 tree v4si_ftype_v4sf_char
b4de2f7d
AH
5826 = build_function_type_list (V4SI_type_node,
5827 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 5828 tree v4si_ftype_v4si_char
b4de2f7d
AH
5829 = build_function_type_list (V4SI_type_node,
5830 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 5831 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
5832 = build_function_type_list (V8HI_type_node,
5833 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 5834 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
5835 = build_function_type_list (V16QI_type_node,
5836 V16QI_type_node, char_type_node, NULL_TREE);
24408032 5837 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
5838 = build_function_type_list (V16QI_type_node,
5839 V16QI_type_node, V16QI_type_node,
5840 char_type_node, NULL_TREE);
24408032 5841 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
5842 = build_function_type_list (V8HI_type_node,
5843 V8HI_type_node, V8HI_type_node,
5844 char_type_node, NULL_TREE);
24408032 5845 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
5846 = build_function_type_list (V4SI_type_node,
5847 V4SI_type_node, V4SI_type_node,
5848 char_type_node, NULL_TREE);
24408032 5849 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
5850 = build_function_type_list (V4SF_type_node,
5851 V4SF_type_node, V4SF_type_node,
5852 char_type_node, NULL_TREE);
0ac081f6 5853 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
5854 = build_function_type_list (V4SF_type_node,
5855 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 5856 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
5857 = build_function_type_list (V4SF_type_node,
5858 V4SF_type_node, V4SF_type_node,
5859 V4SI_type_node, NULL_TREE);
2212663f 5860 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
5861 = build_function_type_list (V4SF_type_node,
5862 V4SF_type_node, V4SF_type_node,
5863 V4SF_type_node, NULL_TREE);
617e0e1d 5864 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
5865 = build_function_type_list (V4SI_type_node,
5866 V4SI_type_node, V4SI_type_node,
5867 V4SI_type_node, NULL_TREE);
0ac081f6 5868 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
5869 = build_function_type_list (V8HI_type_node,
5870 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 5871 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
5872 = build_function_type_list (V8HI_type_node,
5873 V8HI_type_node, V8HI_type_node,
5874 V8HI_type_node, NULL_TREE);
2212663f 5875 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
5876 = build_function_type_list (V4SI_type_node,
5877 V8HI_type_node, V8HI_type_node,
5878 V4SI_type_node, NULL_TREE);
2212663f 5879 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
5880 = build_function_type_list (V4SI_type_node,
5881 V16QI_type_node, V16QI_type_node,
5882 V4SI_type_node, NULL_TREE);
0ac081f6 5883 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
5884 = build_function_type_list (V16QI_type_node,
5885 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5886 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
5887 = build_function_type_list (V4SI_type_node,
5888 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 5889 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
5890 = build_function_type_list (V8HI_type_node,
5891 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5892 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
5893 = build_function_type_list (V4SI_type_node,
5894 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5895 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
5896 = build_function_type_list (V8HI_type_node,
5897 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 5898 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
5899 = build_function_type_list (V16QI_type_node,
5900 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5901 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
5902 = build_function_type_list (V4SI_type_node,
5903 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 5904 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
5905 = build_function_type_list (V4SI_type_node,
5906 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5907 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
5908 = build_function_type_list (V4SI_type_node,
5909 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5910 tree v4si_ftype_v8hi
5911 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
5912 tree int_ftype_v4si_v4si
5913 = build_function_type_list (integer_type_node,
5914 V4SI_type_node, V4SI_type_node, NULL_TREE);
5915 tree int_ftype_v4sf_v4sf
5916 = build_function_type_list (integer_type_node,
5917 V4SF_type_node, V4SF_type_node, NULL_TREE);
5918 tree int_ftype_v16qi_v16qi
5919 = build_function_type_list (integer_type_node,
5920 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5921 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
5922 = build_function_type_list (integer_type_node,
5923 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5924
6f317ef3 5925 /* Add the simple ternary operators. */
2212663f 5926 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 5927 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
5928 {
5929
5930 enum machine_mode mode0, mode1, mode2, mode3;
5931 tree type;
5932
0559cc77 5933 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
5934 continue;
5935
5936 mode0 = insn_data[d->icode].operand[0].mode;
5937 mode1 = insn_data[d->icode].operand[1].mode;
5938 mode2 = insn_data[d->icode].operand[2].mode;
5939 mode3 = insn_data[d->icode].operand[3].mode;
5940
5941 /* When all four are of the same mode. */
5942 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
5943 {
5944 switch (mode0)
5945 {
617e0e1d
DB
5946 case V4SImode:
5947 type = v4si_ftype_v4si_v4si_v4si;
5948 break;
2212663f
DB
5949 case V4SFmode:
5950 type = v4sf_ftype_v4sf_v4sf_v4sf;
5951 break;
5952 case V8HImode:
5953 type = v8hi_ftype_v8hi_v8hi_v8hi;
5954 break;
5955 case V16QImode:
5956 type = v16qi_ftype_v16qi_v16qi_v16qi;
5957 break;
5958 default:
5959 abort();
5960 }
5961 }
5962 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
5963 {
5964 switch (mode0)
5965 {
5966 case V4SImode:
5967 type = v4si_ftype_v4si_v4si_v16qi;
5968 break;
5969 case V4SFmode:
5970 type = v4sf_ftype_v4sf_v4sf_v16qi;
5971 break;
5972 case V8HImode:
5973 type = v8hi_ftype_v8hi_v8hi_v16qi;
5974 break;
5975 case V16QImode:
5976 type = v16qi_ftype_v16qi_v16qi_v16qi;
5977 break;
5978 default:
5979 abort();
5980 }
5981 }
5982 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
5983 && mode3 == V4SImode)
24408032 5984 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
5985 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
5986 && mode3 == V4SImode)
24408032 5987 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
5988 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
5989 && mode3 == V4SImode)
24408032
AH
5990 type = v4sf_ftype_v4sf_v4sf_v4si;
5991
5992 /* vchar, vchar, vchar, 4 bit literal. */
5993 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
5994 && mode3 == QImode)
5995 type = v16qi_ftype_v16qi_v16qi_char;
5996
5997 /* vshort, vshort, vshort, 4 bit literal. */
5998 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
5999 && mode3 == QImode)
6000 type = v8hi_ftype_v8hi_v8hi_char;
6001
6002 /* vint, vint, vint, 4 bit literal. */
6003 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
6004 && mode3 == QImode)
6005 type = v4si_ftype_v4si_v4si_char;
6006
6007 /* vfloat, vfloat, vfloat, 4 bit literal. */
6008 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
6009 && mode3 == QImode)
6010 type = v4sf_ftype_v4sf_v4sf_char;
6011
2212663f
DB
6012 else
6013 abort ();
6014
6015 def_builtin (d->mask, d->name, type, d->code);
6016 }
6017
0ac081f6 6018 /* Add the simple binary operators. */
00b960c7 6019 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 6020 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
6021 {
6022 enum machine_mode mode0, mode1, mode2;
6023 tree type;
6024
0559cc77 6025 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
6026 continue;
6027
6028 mode0 = insn_data[d->icode].operand[0].mode;
6029 mode1 = insn_data[d->icode].operand[1].mode;
6030 mode2 = insn_data[d->icode].operand[2].mode;
6031
6032 /* When all three operands are of the same mode. */
6033 if (mode0 == mode1 && mode1 == mode2)
6034 {
6035 switch (mode0)
6036 {
6037 case V4SFmode:
6038 type = v4sf_ftype_v4sf_v4sf;
6039 break;
6040 case V4SImode:
6041 type = v4si_ftype_v4si_v4si;
6042 break;
6043 case V16QImode:
6044 type = v16qi_ftype_v16qi_v16qi;
6045 break;
6046 case V8HImode:
6047 type = v8hi_ftype_v8hi_v8hi;
6048 break;
a3170dc6
AH
6049 case V2SImode:
6050 type = v2si_ftype_v2si_v2si;
6051 break;
6052 case V2SFmode:
6053 type = v2sf_ftype_v2sf_v2sf;
6054 break;
6055 case SImode:
6056 type = int_ftype_int_int;
6057 break;
0ac081f6
AH
6058 default:
6059 abort ();
6060 }
6061 }
6062
6063 /* A few other combos we really don't want to do manually. */
6064
6065 /* vint, vfloat, vfloat. */
6066 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
6067 type = v4si_ftype_v4sf_v4sf;
6068
6069 /* vshort, vchar, vchar. */
6070 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
6071 type = v8hi_ftype_v16qi_v16qi;
6072
6073 /* vint, vshort, vshort. */
6074 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
6075 type = v4si_ftype_v8hi_v8hi;
6076
6077 /* vshort, vint, vint. */
6078 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
6079 type = v8hi_ftype_v4si_v4si;
6080
6081 /* vchar, vshort, vshort. */
6082 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
6083 type = v16qi_ftype_v8hi_v8hi;
6084
6085 /* vint, vchar, vint. */
6086 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
6087 type = v4si_ftype_v16qi_v4si;
6088
fa066a23
AH
6089 /* vint, vchar, vchar. */
6090 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
6091 type = v4si_ftype_v16qi_v16qi;
6092
0ac081f6
AH
6093 /* vint, vshort, vint. */
6094 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
6095 type = v4si_ftype_v8hi_v4si;
2212663f
DB
6096
6097 /* vint, vint, 5 bit literal. */
6098 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
6099 type = v4si_ftype_v4si_char;
6100
6101 /* vshort, vshort, 5 bit literal. */
6102 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
6103 type = v8hi_ftype_v8hi_char;
6104
6105 /* vchar, vchar, 5 bit literal. */
6106 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
6107 type = v16qi_ftype_v16qi_char;
0ac081f6 6108
617e0e1d
DB
6109 /* vfloat, vint, 5 bit literal. */
6110 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
6111 type = v4sf_ftype_v4si_char;
6112
6113 /* vint, vfloat, 5 bit literal. */
6114 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
6115 type = v4si_ftype_v4sf_char;
6116
a3170dc6
AH
6117 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
6118 type = v2si_ftype_int_int;
6119
6120 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
6121 type = v2si_ftype_v2si_char;
6122
6123 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
6124 type = v2si_ftype_int_char;
6125
0ac081f6
AH
6126 /* int, x, x. */
6127 else if (mode0 == SImode)
6128 {
6129 switch (mode1)
6130 {
6131 case V4SImode:
6132 type = int_ftype_v4si_v4si;
6133 break;
6134 case V4SFmode:
6135 type = int_ftype_v4sf_v4sf;
6136 break;
6137 case V16QImode:
6138 type = int_ftype_v16qi_v16qi;
6139 break;
6140 case V8HImode:
6141 type = int_ftype_v8hi_v8hi;
6142 break;
6143 default:
6144 abort ();
6145 }
6146 }
6147
6148 else
6149 abort ();
6150
2212663f
DB
6151 def_builtin (d->mask, d->name, type, d->code);
6152 }
24408032 6153
2212663f
DB
6154 /* Add the simple unary operators. */
6155 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 6156 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
6157 {
6158 enum machine_mode mode0, mode1;
6159 tree type;
6160
0559cc77 6161 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6162 continue;
6163
6164 mode0 = insn_data[d->icode].operand[0].mode;
6165 mode1 = insn_data[d->icode].operand[1].mode;
6166
6167 if (mode0 == V4SImode && mode1 == QImode)
6168 type = v4si_ftype_char;
6169 else if (mode0 == V8HImode && mode1 == QImode)
6170 type = v8hi_ftype_char;
6171 else if (mode0 == V16QImode && mode1 == QImode)
6172 type = v16qi_ftype_char;
617e0e1d
DB
6173 else if (mode0 == V4SFmode && mode1 == V4SFmode)
6174 type = v4sf_ftype_v4sf;
20e26713
AH
6175 else if (mode0 == V8HImode && mode1 == V16QImode)
6176 type = v8hi_ftype_v16qi;
6177 else if (mode0 == V4SImode && mode1 == V8HImode)
6178 type = v4si_ftype_v8hi;
a3170dc6
AH
6179 else if (mode0 == V2SImode && mode1 == V2SImode)
6180 type = v2si_ftype_v2si;
6181 else if (mode0 == V2SFmode && mode1 == V2SFmode)
6182 type = v2sf_ftype_v2sf;
6183 else if (mode0 == V2SFmode && mode1 == V2SImode)
6184 type = v2sf_ftype_v2si;
6185 else if (mode0 == V2SImode && mode1 == V2SFmode)
6186 type = v2si_ftype_v2sf;
6187 else if (mode0 == V2SImode && mode1 == QImode)
6188 type = v2si_ftype_char;
2212663f
DB
6189 else
6190 abort ();
6191
0ac081f6
AH
6192 def_builtin (d->mask, d->name, type, d->code);
6193 }
6194}
6195
35aff10b 6196\f
7e69e155
MM
6197/* Expand a block move operation, and return 1 if successful. Return 0
6198 if we should let the compiler generate normal code.
6199
6200 operands[0] is the destination
6201 operands[1] is the source
6202 operands[2] is the length
6203 operands[3] is the alignment */
6204
3933e0e1
MM
6205#define MAX_MOVE_REG 4
6206
7e69e155
MM
6207int
6208expand_block_move (operands)
6209 rtx operands[];
6210{
b6c9286a
MM
6211 rtx orig_dest = operands[0];
6212 rtx orig_src = operands[1];
7e69e155 6213 rtx bytes_rtx = operands[2];
7e69e155 6214 rtx align_rtx = operands[3];
3933e0e1 6215 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 6216 int align;
3933e0e1
MM
6217 int bytes;
6218 int offset;
7e69e155
MM
6219 int move_bytes;
6220
3933e0e1 6221 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 6222 if (! constp)
3933e0e1
MM
6223 return 0;
6224
5ee95df6
FS
6225 /* If this is not a fixed size alignment, abort */
6226 if (GET_CODE (align_rtx) != CONST_INT)
6227 abort ();
6228 align = INTVAL (align_rtx);
6229
7e69e155 6230 /* Anything to move? */
3933e0e1
MM
6231 bytes = INTVAL (bytes_rtx);
6232 if (bytes <= 0)
7e69e155
MM
6233 return 1;
6234
ea9982a8 6235 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 6236 reg_parm_stack_space. */
ea9982a8 6237 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
6238 return 0;
6239
3933e0e1 6240 if (TARGET_STRING) /* string instructions are available */
7e69e155 6241 {
35aff10b 6242 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6243 {
35aff10b
AM
6244 union {
6245 rtx (*movstrsi) PARAMS ((rtx, rtx, rtx, rtx));
6246 rtx (*mov) PARAMS ((rtx, rtx));
6247 } gen_func;
6248 enum machine_mode mode = BLKmode;
6249 rtx src, dest;
6250
3933e0e1 6251 if (bytes > 24 /* move up to 32 bytes at a time */
cc0d9ba8
DE
6252 && ! fixed_regs[5]
6253 && ! fixed_regs[6]
6254 && ! fixed_regs[7]
6255 && ! fixed_regs[8]
6256 && ! fixed_regs[9]
6257 && ! fixed_regs[10]
6258 && ! fixed_regs[11]
6259 && ! fixed_regs[12])
3933e0e1
MM
6260 {
6261 move_bytes = (bytes > 32) ? 32 : bytes;
35aff10b 6262 gen_func.movstrsi = gen_movstrsi_8reg;
3933e0e1
MM
6263 }
6264 else if (bytes > 16 /* move up to 24 bytes at a time */
f9562f27
DE
6265 && ! fixed_regs[5]
6266 && ! fixed_regs[6]
cc0d9ba8
DE
6267 && ! fixed_regs[7]
6268 && ! fixed_regs[8]
6269 && ! fixed_regs[9]
f9562f27 6270 && ! fixed_regs[10])
3933e0e1
MM
6271 {
6272 move_bytes = (bytes > 24) ? 24 : bytes;
35aff10b 6273 gen_func.movstrsi = gen_movstrsi_6reg;
3933e0e1
MM
6274 }
6275 else if (bytes > 8 /* move up to 16 bytes at a time */
f9562f27
DE
6276 && ! fixed_regs[5]
6277 && ! fixed_regs[6]
6278 && ! fixed_regs[7]
6279 && ! fixed_regs[8])
3933e0e1
MM
6280 {
6281 move_bytes = (bytes > 16) ? 16 : bytes;
35aff10b 6282 gen_func.movstrsi = gen_movstrsi_4reg;
3933e0e1 6283 }
acad7ed3 6284 else if (bytes >= 8 && TARGET_POWERPC64
a4f6c312 6285 /* 64-bit loads and stores require word-aligned
82e41834 6286 displacements. */
a4f6c312 6287 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
acad7ed3
DE
6288 {
6289 move_bytes = 8;
35aff10b
AM
6290 mode = DImode;
6291 gen_func.mov = gen_movdi;
acad7ed3 6292 }
09a625f7 6293 else if (bytes > 4 && !TARGET_POWERPC64)
3933e0e1
MM
6294 { /* move up to 8 bytes at a time */
6295 move_bytes = (bytes > 8) ? 8 : bytes;
35aff10b 6296 gen_func.movstrsi = gen_movstrsi_2reg;
3933e0e1 6297 }
cc0d9ba8 6298 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6299 { /* move 4 bytes */
6300 move_bytes = 4;
35aff10b
AM
6301 mode = SImode;
6302 gen_func.mov = gen_movsi;
3933e0e1 6303 }
cc0d9ba8 6304 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6305 { /* move 2 bytes */
6306 move_bytes = 2;
35aff10b
AM
6307 mode = HImode;
6308 gen_func.mov = gen_movhi;
3933e0e1
MM
6309 }
6310 else if (bytes == 1) /* move 1 byte */
6311 {
6312 move_bytes = 1;
35aff10b
AM
6313 mode = QImode;
6314 gen_func.mov = gen_movqi;
3933e0e1
MM
6315 }
6316 else
6317 { /* move up to 4 bytes at a time */
6318 move_bytes = (bytes > 4) ? 4 : bytes;
35aff10b 6319 gen_func.movstrsi = gen_movstrsi_1reg;
3933e0e1 6320 }
4c64a852 6321
35aff10b
AM
6322 src = adjust_address (orig_src, mode, offset);
6323 dest = adjust_address (orig_dest, mode, offset);
6324
6325 if (mode == BLKmode)
015892ee 6326 {
35aff10b
AM
6327 /* Move the address into scratch registers. The movstrsi
6328 patterns require zero offset. */
6329 if (!REG_P (XEXP (src, 0)))
cc0d9ba8 6330 {
35aff10b
AM
6331 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
6332 src = replace_equiv_address (src, src_reg);
cc0d9ba8 6333 }
35aff10b
AM
6334 set_mem_size (src, GEN_INT (move_bytes));
6335
6336 if (!REG_P (XEXP (dest, 0)))
cc0d9ba8 6337 {
35aff10b
AM
6338 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
6339 dest = replace_equiv_address (dest, dest_reg);
cc0d9ba8 6340 }
35aff10b
AM
6341 set_mem_size (dest, GEN_INT (move_bytes));
6342
6343 emit_insn ((*gen_func.movstrsi) (dest, src,
6344 GEN_INT (move_bytes & 31),
6345 align_rtx));
6346 }
6347 else
6348 {
6349 rtx tmp_reg = gen_reg_rtx (mode);
6350
6351 emit_insn ((*gen_func.mov) (tmp_reg, src));
6352 emit_insn ((*gen_func.mov) (dest, tmp_reg));
015892ee 6353 }
4c64a852 6354 }
3933e0e1
MM
6355 }
6356
6357 else /* string instructions not available */
6358 {
35aff10b
AM
6359 rtx stores[MAX_MOVE_REG];
6360 int num_reg = 0;
6361 int i;
6362
6363 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6364 {
35aff10b
AM
6365 rtx (*gen_mov_func) PARAMS ((rtx, rtx));
6366 enum machine_mode mode;
6367 rtx src, dest, tmp_reg;
3933e0e1 6368
cc0d9ba8
DE
6369 /* Generate the appropriate load and store, saving the stores
6370 for later. */
6371 if (bytes >= 8 && TARGET_POWERPC64
a4f6c312
SS
6372 /* 64-bit loads and stores require word-aligned
6373 displacements. */
cc0d9ba8 6374 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
b6c9286a
MM
6375 {
6376 move_bytes = 8;
35aff10b
AM
6377 mode = DImode;
6378 gen_mov_func = gen_movdi;
b6c9286a 6379 }
cc0d9ba8 6380 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6381 {
6382 move_bytes = 4;
35aff10b
AM
6383 mode = SImode;
6384 gen_mov_func = gen_movsi;
3933e0e1 6385 }
cc0d9ba8 6386 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6387 {
6388 move_bytes = 2;
35aff10b
AM
6389 mode = HImode;
6390 gen_mov_func = gen_movhi;
3933e0e1
MM
6391 }
6392 else
6393 {
6394 move_bytes = 1;
35aff10b
AM
6395 mode = QImode;
6396 gen_mov_func = gen_movqi;
3933e0e1
MM
6397 }
6398
35aff10b
AM
6399 src = adjust_address (orig_src, mode, offset);
6400 dest = adjust_address (orig_dest, mode, offset);
6401 tmp_reg = gen_reg_rtx (mode);
6402
6403 emit_insn ((*gen_mov_func) (tmp_reg, src));
6404 stores[num_reg++] = (*gen_mov_func) (dest, tmp_reg);
6405
3933e0e1
MM
6406 if (num_reg >= MAX_MOVE_REG)
6407 {
6408 for (i = 0; i < num_reg; i++)
6409 emit_insn (stores[i]);
6410 num_reg = 0;
7e69e155
MM
6411 }
6412 }
3933e0e1 6413
b6c9286a
MM
6414 for (i = 0; i < num_reg; i++)
6415 emit_insn (stores[i]);
7e69e155
MM
6416 }
6417
6418 return 1;
6419}
6420
9878760c
RK
6421\f
6422/* Return 1 if OP is a load multiple operation. It is known to be a
6423 PARALLEL and the first section will be tested. */
6424
6425int
6426load_multiple_operation (op, mode)
6427 rtx op;
296b8152 6428 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6429{
6430 int count = XVECLEN (op, 0);
e2c953b6 6431 unsigned int dest_regno;
9878760c
RK
6432 rtx src_addr;
6433 int i;
6434
6435 /* Perform a quick check so we don't blow up below. */
6436 if (count <= 1
6437 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6438 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6439 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6440 return 0;
6441
6442 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6443 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6444
6445 for (i = 1; i < count; i++)
6446 {
6447 rtx elt = XVECEXP (op, 0, i);
6448
6449 if (GET_CODE (elt) != SET
6450 || GET_CODE (SET_DEST (elt)) != REG
6451 || GET_MODE (SET_DEST (elt)) != SImode
6452 || REGNO (SET_DEST (elt)) != dest_regno + i
6453 || GET_CODE (SET_SRC (elt)) != MEM
6454 || GET_MODE (SET_SRC (elt)) != SImode
6455 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
6456 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
6457 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
6458 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
6459 return 0;
6460 }
6461
6462 return 1;
6463}
6464
6465/* Similar, but tests for store multiple. Here, the second vector element
6466 is a CLOBBER. It will be tested later. */
6467
6468int
6469store_multiple_operation (op, mode)
6470 rtx op;
296b8152 6471 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6472{
6473 int count = XVECLEN (op, 0) - 1;
e2c953b6 6474 unsigned int src_regno;
9878760c
RK
6475 rtx dest_addr;
6476 int i;
6477
6478 /* Perform a quick check so we don't blow up below. */
6479 if (count <= 1
6480 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6481 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6482 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6483 return 0;
6484
6485 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6486 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6487
6488 for (i = 1; i < count; i++)
6489 {
6490 rtx elt = XVECEXP (op, 0, i + 1);
6491
6492 if (GET_CODE (elt) != SET
6493 || GET_CODE (SET_SRC (elt)) != REG
6494 || GET_MODE (SET_SRC (elt)) != SImode
6495 || REGNO (SET_SRC (elt)) != src_regno + i
6496 || GET_CODE (SET_DEST (elt)) != MEM
6497 || GET_MODE (SET_DEST (elt)) != SImode
6498 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
6499 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
6500 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
6501 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
6502 return 0;
6503 }
6504
6505 return 1;
6506}
9ebbca7d 6507
9caa3eb2
DE
6508/* Return a string to perform a load_multiple operation.
6509 operands[0] is the vector.
6510 operands[1] is the source address.
6511 operands[2] is the first destination register. */
6512
6513const char *
6514rs6000_output_load_multiple (operands)
ebe637e3 6515 rtx operands[3];
9caa3eb2
DE
6516{
6517 /* We have to handle the case where the pseudo used to contain the address
6518 is assigned to one of the output registers. */
6519 int i, j;
6520 int words = XVECLEN (operands[0], 0);
6521 rtx xop[10];
6522
6523 if (XVECLEN (operands[0], 0) == 1)
6524 return "{l|lwz} %2,0(%1)";
6525
6526 for (i = 0; i < words; i++)
6527 if (refers_to_regno_p (REGNO (operands[2]) + i,
6528 REGNO (operands[2]) + i + 1, operands[1], 0))
6529 {
6530 if (i == words-1)
6531 {
6532 xop[0] = GEN_INT (4 * (words-1));
6533 xop[1] = operands[1];
6534 xop[2] = operands[2];
6535 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
6536 return "";
6537 }
6538 else if (i == 0)
6539 {
6540 xop[0] = GEN_INT (4 * (words-1));
6541 xop[1] = operands[1];
6542 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6543 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);
6544 return "";
6545 }
6546 else
6547 {
6548 for (j = 0; j < words; j++)
6549 if (j != i)
6550 {
6551 xop[0] = GEN_INT (j * 4);
6552 xop[1] = operands[1];
6553 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
6554 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
6555 }
6556 xop[0] = GEN_INT (i * 4);
6557 xop[1] = operands[1];
6558 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
6559 return "";
6560 }
6561 }
6562
6563 return "{lsi|lswi} %2,%1,%N0";
6564}
6565
00b960c7
AH
6566/* Return 1 for a parallel vrsave operation. */
6567
6568int
6569vrsave_operation (op, mode)
6570 rtx op;
6571 enum machine_mode mode ATTRIBUTE_UNUSED;
6572{
6573 int count = XVECLEN (op, 0);
6574 unsigned int dest_regno, src_regno;
6575 int i;
6576
6577 if (count <= 1
6578 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6579 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 6580 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
6581 return 0;
6582
6583 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6584 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6585
6586 if (dest_regno != VRSAVE_REGNO
6587 && src_regno != VRSAVE_REGNO)
6588 return 0;
6589
6590 for (i = 1; i < count; i++)
6591 {
6592 rtx elt = XVECEXP (op, 0, i);
6593
9aa86737
AH
6594 if (GET_CODE (elt) != CLOBBER
6595 && GET_CODE (elt) != SET)
00b960c7
AH
6596 return 0;
6597 }
6598
6599 return 1;
6600}
6601
a4f6c312 6602/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
6603
6604int
6605mtcrf_operation (op, mode)
6606 rtx op;
6607 enum machine_mode mode ATTRIBUTE_UNUSED;
6608{
6609 int count = XVECLEN (op, 0);
6610 int i;
9ebbca7d
GK
6611 rtx src_reg;
6612
6613 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
6614 if (count < 1
6615 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6616 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
6617 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 6618 return 0;
e35b9579 6619 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
6620
6621 if (GET_CODE (src_reg) != REG
6622 || GET_MODE (src_reg) != SImode
6623 || ! INT_REGNO_P (REGNO (src_reg)))
6624 return 0;
6625
e35b9579 6626 for (i = 0; i < count; i++)
9ebbca7d
GK
6627 {
6628 rtx exp = XVECEXP (op, 0, i);
6629 rtx unspec;
6630 int maskval;
6631
6632 if (GET_CODE (exp) != SET
6633 || GET_CODE (SET_DEST (exp)) != REG
6634 || GET_MODE (SET_DEST (exp)) != CCmode
6635 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
6636 return 0;
6637 unspec = SET_SRC (exp);
6638 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
6639
6640 if (GET_CODE (unspec) != UNSPEC
6641 || XINT (unspec, 1) != 20
6642 || XVECLEN (unspec, 0) != 2
6643 || XVECEXP (unspec, 0, 0) != src_reg
6644 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
6645 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
6646 return 0;
6647 }
e35b9579 6648 return 1;
9ebbca7d
GK
6649}
6650
a4f6c312 6651/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
6652
6653int
6654lmw_operation (op, mode)
6655 rtx op;
6656 enum machine_mode mode ATTRIBUTE_UNUSED;
6657{
6658 int count = XVECLEN (op, 0);
e2c953b6 6659 unsigned int dest_regno;
9ebbca7d 6660 rtx src_addr;
e2c953b6 6661 unsigned int base_regno;
9ebbca7d
GK
6662 HOST_WIDE_INT offset;
6663 int i;
6664
6665 /* Perform a quick check so we don't blow up below. */
6666 if (count <= 1
6667 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6668 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6669 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6670 return 0;
6671
6672 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6673 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6674
6675 if (dest_regno > 31
e2c953b6 6676 || count != 32 - (int) dest_regno)
9ebbca7d
GK
6677 return 0;
6678
258bfae2 6679 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0))
9ebbca7d
GK
6680 {
6681 offset = 0;
6682 base_regno = REGNO (src_addr);
6683 if (base_regno == 0)
6684 return 0;
6685 }
258bfae2 6686 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0))
9ebbca7d
GK
6687 {
6688 offset = INTVAL (XEXP (src_addr, 1));
6689 base_regno = REGNO (XEXP (src_addr, 0));
6690 }
6691 else
6692 return 0;
6693
6694 for (i = 0; i < count; i++)
6695 {
6696 rtx elt = XVECEXP (op, 0, i);
6697 rtx newaddr;
6698 rtx addr_reg;
6699 HOST_WIDE_INT newoffset;
6700
6701 if (GET_CODE (elt) != SET
6702 || GET_CODE (SET_DEST (elt)) != REG
6703 || GET_MODE (SET_DEST (elt)) != SImode
6704 || REGNO (SET_DEST (elt)) != dest_regno + i
6705 || GET_CODE (SET_SRC (elt)) != MEM
6706 || GET_MODE (SET_SRC (elt)) != SImode)
6707 return 0;
6708 newaddr = XEXP (SET_SRC (elt), 0);
258bfae2 6709 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6710 {
6711 newoffset = 0;
6712 addr_reg = newaddr;
6713 }
258bfae2 6714 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6715 {
6716 addr_reg = XEXP (newaddr, 0);
6717 newoffset = INTVAL (XEXP (newaddr, 1));
6718 }
6719 else
6720 return 0;
6721 if (REGNO (addr_reg) != base_regno
6722 || newoffset != offset + 4 * i)
6723 return 0;
6724 }
6725
6726 return 1;
6727}
6728
a4f6c312 6729/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
6730
6731int
6732stmw_operation (op, mode)
6733 rtx op;
6734 enum machine_mode mode ATTRIBUTE_UNUSED;
6735{
6736 int count = XVECLEN (op, 0);
e2c953b6 6737 unsigned int src_regno;
9ebbca7d 6738 rtx dest_addr;
e2c953b6 6739 unsigned int base_regno;
9ebbca7d
GK
6740 HOST_WIDE_INT offset;
6741 int i;
6742
6743 /* Perform a quick check so we don't blow up below. */
6744 if (count <= 1
6745 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6746 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6747 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6748 return 0;
6749
6750 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6751 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6752
6753 if (src_regno > 31
e2c953b6 6754 || count != 32 - (int) src_regno)
9ebbca7d
GK
6755 return 0;
6756
258bfae2 6757 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0))
9ebbca7d
GK
6758 {
6759 offset = 0;
6760 base_regno = REGNO (dest_addr);
6761 if (base_regno == 0)
6762 return 0;
6763 }
258bfae2 6764 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0))
9ebbca7d
GK
6765 {
6766 offset = INTVAL (XEXP (dest_addr, 1));
6767 base_regno = REGNO (XEXP (dest_addr, 0));
6768 }
6769 else
6770 return 0;
6771
6772 for (i = 0; i < count; i++)
6773 {
6774 rtx elt = XVECEXP (op, 0, i);
6775 rtx newaddr;
6776 rtx addr_reg;
6777 HOST_WIDE_INT newoffset;
6778
6779 if (GET_CODE (elt) != SET
6780 || GET_CODE (SET_SRC (elt)) != REG
6781 || GET_MODE (SET_SRC (elt)) != SImode
6782 || REGNO (SET_SRC (elt)) != src_regno + i
6783 || GET_CODE (SET_DEST (elt)) != MEM
6784 || GET_MODE (SET_DEST (elt)) != SImode)
6785 return 0;
6786 newaddr = XEXP (SET_DEST (elt), 0);
258bfae2 6787 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6788 {
6789 newoffset = 0;
6790 addr_reg = newaddr;
6791 }
258bfae2 6792 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6793 {
6794 addr_reg = XEXP (newaddr, 0);
6795 newoffset = INTVAL (XEXP (newaddr, 1));
6796 }
6797 else
6798 return 0;
6799 if (REGNO (addr_reg) != base_regno
6800 || newoffset != offset + 4 * i)
6801 return 0;
6802 }
6803
6804 return 1;
6805}
9878760c 6806\f
a4f6c312
SS
6807/* A validation routine: say whether CODE, a condition code, and MODE
6808 match. The other alternatives either don't make sense or should
6809 never be generated. */
39a10a29 6810
39a10a29
GK
6811static void
6812validate_condition_mode (code, mode)
6813 enum rtx_code code;
6814 enum machine_mode mode;
6815{
6816 if (GET_RTX_CLASS (code) != '<'
6817 || GET_MODE_CLASS (mode) != MODE_CC)
6818 abort ();
6819
6820 /* These don't make sense. */
6821 if ((code == GT || code == LT || code == GE || code == LE)
6822 && mode == CCUNSmode)
6823 abort ();
6824
6825 if ((code == GTU || code == LTU || code == GEU || code == LEU)
6826 && mode != CCUNSmode)
6827 abort ();
6828
6829 if (mode != CCFPmode
6830 && (code == ORDERED || code == UNORDERED
6831 || code == UNEQ || code == LTGT
6832 || code == UNGT || code == UNLT
6833 || code == UNGE || code == UNLE))
a4f6c312 6834 abort ();
39a10a29 6835
de6c5979 6836 /* These should never be generated except for
ad72b533 6837 flag_unsafe_math_optimizations and flag_finite_math_only. */
39a10a29 6838 if (mode == CCFPmode
de6c5979 6839 && ! flag_unsafe_math_optimizations
ad72b533 6840 && ! flag_finite_math_only
39a10a29
GK
6841 && (code == LE || code == GE
6842 || code == UNEQ || code == LTGT
6843 || code == UNGT || code == UNLT))
6844 abort ();
6845
6846 /* These are invalid; the information is not there. */
6847 if (mode == CCEQmode
6848 && code != EQ && code != NE)
6849 abort ();
6850}
6851
9878760c
RK
6852/* Return 1 if OP is a comparison operation that is valid for a branch insn.
6853 We only check the opcode against the mode of the CC value here. */
6854
6855int
6856branch_comparison_operator (op, mode)
592696dd 6857 rtx op;
296b8152 6858 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6859{
6860 enum rtx_code code = GET_CODE (op);
6861 enum machine_mode cc_mode;
6862
6863 if (GET_RTX_CLASS (code) != '<')
6864 return 0;
6865
6866 cc_mode = GET_MODE (XEXP (op, 0));
6867 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6868 return 0;
6869
39a10a29 6870 validate_condition_mode (code, cc_mode);
9878760c 6871
39a10a29
GK
6872 return 1;
6873}
6874
6875/* Return 1 if OP is a comparison operation that is valid for a branch
6876 insn and which is true if the corresponding bit in the CC register
6877 is set. */
6878
6879int
6880branch_positive_comparison_operator (op, mode)
592696dd 6881 rtx op;
39a10a29
GK
6882 enum machine_mode mode;
6883{
6884 enum rtx_code code;
6885
6886 if (! branch_comparison_operator (op, mode))
9878760c
RK
6887 return 0;
6888
39a10a29
GK
6889 code = GET_CODE (op);
6890 return (code == EQ || code == LT || code == GT
a3170dc6 6891 || (TARGET_SPE && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
6892 || code == LTU || code == GTU
6893 || code == UNORDERED);
9878760c
RK
6894}
6895
6896/* Return 1 if OP is a comparison operation that is valid for an scc insn.
6897 We check the opcode against the mode of the CC value and disallow EQ or
6898 NE comparisons for integers. */
6899
6900int
6901scc_comparison_operator (op, mode)
592696dd 6902 rtx op;
9878760c
RK
6903 enum machine_mode mode;
6904{
6905 enum rtx_code code = GET_CODE (op);
6906 enum machine_mode cc_mode;
6907
6908 if (GET_MODE (op) != mode && mode != VOIDmode)
6909 return 0;
6910
6911 if (GET_RTX_CLASS (code) != '<')
6912 return 0;
6913
6914 cc_mode = GET_MODE (XEXP (op, 0));
6915 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6916 return 0;
6917
39a10a29 6918 validate_condition_mode (code, cc_mode);
9878760c 6919
39a10a29 6920 if (code == NE && cc_mode != CCFPmode)
c5defebb
RK
6921 return 0;
6922
9878760c
RK
6923 return 1;
6924}
e0cd0770
JC
6925
6926int
6927trap_comparison_operator (op, mode)
6928 rtx op;
6929 enum machine_mode mode;
6930{
6931 if (mode != VOIDmode && mode != GET_MODE (op))
6932 return 0;
39a10a29 6933 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 6934}
dfbdccdb
GK
6935
6936int
6937boolean_operator (op, mode)
6938 rtx op;
6939 enum machine_mode mode ATTRIBUTE_UNUSED;
6940{
6941 enum rtx_code code = GET_CODE (op);
6942 return (code == AND || code == IOR || code == XOR);
6943}
1d328b19
GK
6944
6945int
6946boolean_or_operator (op, mode)
6947 rtx op;
6948 enum machine_mode mode ATTRIBUTE_UNUSED;
6949{
6950 enum rtx_code code = GET_CODE (op);
6951 return (code == IOR || code == XOR);
6952}
50a0b056
GK
6953
6954int
6955min_max_operator (op, mode)
6956 rtx op;
6957 enum machine_mode mode ATTRIBUTE_UNUSED;
6958{
6959 enum rtx_code code = GET_CODE (op);
6960 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
6961}
9878760c
RK
6962\f
6963/* Return 1 if ANDOP is a mask that has no bits on that are not in the
6964 mask required to convert the result of a rotate insn into a shift
b1765bde 6965 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
6966
6967int
6968includes_lshift_p (shiftop, andop)
592696dd
SS
6969 rtx shiftop;
6970 rtx andop;
9878760c 6971{
e2c953b6
DE
6972 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
6973
6974 shift_mask <<= INTVAL (shiftop);
9878760c 6975
b1765bde 6976 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
6977}
6978
6979/* Similar, but for right shift. */
6980
6981int
6982includes_rshift_p (shiftop, andop)
592696dd
SS
6983 rtx shiftop;
6984 rtx andop;
9878760c 6985{
a7653a2c 6986 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
6987
6988 shift_mask >>= INTVAL (shiftop);
6989
b1765bde 6990 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
6991}
6992
c5059423
AM
6993/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
6994 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 6995 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
6996
6997int
c5059423 6998includes_rldic_lshift_p (shiftop, andop)
592696dd
SS
6999 rtx shiftop;
7000 rtx andop;
e2c953b6 7001{
c5059423
AM
7002 if (GET_CODE (andop) == CONST_INT)
7003 {
02071907 7004 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 7005
c5059423 7006 c = INTVAL (andop);
02071907 7007 if (c == 0 || c == ~0)
c5059423 7008 return 0;
e2c953b6 7009
02071907 7010 shift_mask = ~0;
c5059423
AM
7011 shift_mask <<= INTVAL (shiftop);
7012
b6d08ca1 7013 /* Find the least significant one bit. */
c5059423
AM
7014 lsb = c & -c;
7015
7016 /* It must coincide with the LSB of the shift mask. */
7017 if (-lsb != shift_mask)
7018 return 0;
e2c953b6 7019
c5059423
AM
7020 /* Invert to look for the next transition (if any). */
7021 c = ~c;
7022
7023 /* Remove the low group of ones (originally low group of zeros). */
7024 c &= -lsb;
7025
7026 /* Again find the lsb, and check we have all 1's above. */
7027 lsb = c & -c;
7028 return c == -lsb;
7029 }
7030 else if (GET_CODE (andop) == CONST_DOUBLE
7031 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7032 {
02071907
AM
7033 HOST_WIDE_INT low, high, lsb;
7034 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
7035
7036 low = CONST_DOUBLE_LOW (andop);
7037 if (HOST_BITS_PER_WIDE_INT < 64)
7038 high = CONST_DOUBLE_HIGH (andop);
7039
7040 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 7041 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
7042 return 0;
7043
7044 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7045 {
02071907 7046 shift_mask_high = ~0;
c5059423
AM
7047 if (INTVAL (shiftop) > 32)
7048 shift_mask_high <<= INTVAL (shiftop) - 32;
7049
7050 lsb = high & -high;
7051
7052 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
7053 return 0;
7054
7055 high = ~high;
7056 high &= -lsb;
7057
7058 lsb = high & -high;
7059 return high == -lsb;
7060 }
7061
02071907 7062 shift_mask_low = ~0;
c5059423
AM
7063 shift_mask_low <<= INTVAL (shiftop);
7064
7065 lsb = low & -low;
7066
7067 if (-lsb != shift_mask_low)
7068 return 0;
7069
7070 if (HOST_BITS_PER_WIDE_INT < 64)
7071 high = ~high;
7072 low = ~low;
7073 low &= -lsb;
7074
7075 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7076 {
7077 lsb = high & -high;
7078 return high == -lsb;
7079 }
7080
7081 lsb = low & -low;
7082 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
7083 }
7084 else
7085 return 0;
7086}
e2c953b6 7087
c5059423
AM
7088/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
7089 to perform a left shift. It must have SHIFTOP or more least
7090 signifigant 0's, with the remainder of the word 1's. */
e2c953b6 7091
c5059423
AM
7092int
7093includes_rldicr_lshift_p (shiftop, andop)
592696dd
SS
7094 rtx shiftop;
7095 rtx andop;
c5059423 7096{
e2c953b6 7097 if (GET_CODE (andop) == CONST_INT)
c5059423 7098 {
02071907 7099 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 7100
02071907 7101 shift_mask = ~0;
c5059423
AM
7102 shift_mask <<= INTVAL (shiftop);
7103 c = INTVAL (andop);
7104
7105 /* Find the least signifigant one bit. */
7106 lsb = c & -c;
7107
7108 /* It must be covered by the shift mask.
a4f6c312 7109 This test also rejects c == 0. */
c5059423
AM
7110 if ((lsb & shift_mask) == 0)
7111 return 0;
7112
7113 /* Check we have all 1's above the transition, and reject all 1's. */
7114 return c == -lsb && lsb != 1;
7115 }
7116 else if (GET_CODE (andop) == CONST_DOUBLE
7117 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7118 {
02071907 7119 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
7120
7121 low = CONST_DOUBLE_LOW (andop);
7122
7123 if (HOST_BITS_PER_WIDE_INT < 64)
7124 {
02071907 7125 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
7126
7127 high = CONST_DOUBLE_HIGH (andop);
7128
7129 if (low == 0)
7130 {
02071907 7131 shift_mask_high = ~0;
c5059423
AM
7132 if (INTVAL (shiftop) > 32)
7133 shift_mask_high <<= INTVAL (shiftop) - 32;
7134
7135 lsb = high & -high;
7136
7137 if ((lsb & shift_mask_high) == 0)
7138 return 0;
7139
7140 return high == -lsb;
7141 }
7142 if (high != ~0)
7143 return 0;
7144 }
7145
02071907 7146 shift_mask_low = ~0;
c5059423
AM
7147 shift_mask_low <<= INTVAL (shiftop);
7148
7149 lsb = low & -low;
7150
7151 if ((lsb & shift_mask_low) == 0)
7152 return 0;
7153
7154 return low == -lsb && lsb != 1;
7155 }
e2c953b6 7156 else
c5059423 7157 return 0;
9878760c 7158}
35068b43
RK
7159
7160/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
7161 for lfq and stfq insns.
7162
7163 Note reg1 and reg2 *must* be hard registers. To be sure we will
7164 abort if we are passed pseudo registers. */
7165
7166int
7167registers_ok_for_quad_peep (reg1, reg2)
7168 rtx reg1, reg2;
7169{
7170 /* We might have been passed a SUBREG. */
7171 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7172 return 0;
7173
7174 return (REGNO (reg1) == REGNO (reg2) - 1);
7175}
7176
a4f6c312
SS
7177/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
7178 addr1 and addr2 must be in consecutive memory locations
7179 (addr2 == addr1 + 8). */
35068b43
RK
7180
7181int
7182addrs_ok_for_quad_peep (addr1, addr2)
592696dd
SS
7183 rtx addr1;
7184 rtx addr2;
35068b43 7185{
e2c953b6 7186 unsigned int reg1;
35068b43
RK
7187 int offset1;
7188
7189 /* Extract an offset (if used) from the first addr. */
7190 if (GET_CODE (addr1) == PLUS)
7191 {
7192 /* If not a REG, return zero. */
7193 if (GET_CODE (XEXP (addr1, 0)) != REG)
7194 return 0;
7195 else
7196 {
7197 reg1 = REGNO (XEXP (addr1, 0));
7198 /* The offset must be constant! */
7199 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7200 return 0;
7201 offset1 = INTVAL (XEXP (addr1, 1));
7202 }
7203 }
7204 else if (GET_CODE (addr1) != REG)
7205 return 0;
7206 else
7207 {
7208 reg1 = REGNO (addr1);
7209 /* This was a simple (mem (reg)) expression. Offset is 0. */
7210 offset1 = 0;
7211 }
7212
acad7ed3 7213 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
35068b43
RK
7214 if (GET_CODE (addr2) != PLUS)
7215 return 0;
7216
7217 if (GET_CODE (XEXP (addr2, 0)) != REG
7218 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7219 return 0;
7220
7221 if (reg1 != REGNO (XEXP (addr2, 0)))
7222 return 0;
7223
7224 /* The offset for the second addr must be 8 more than the first addr. */
7225 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
7226 return 0;
7227
7228 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
7229 instructions. */
7230 return 1;
7231}
9878760c
RK
7232\f
7233/* Return the register class of a scratch register needed to copy IN into
7234 or out of a register in CLASS in MODE. If it can be done directly,
7235 NO_REGS is returned. */
7236
7237enum reg_class
7238secondary_reload_class (class, mode, in)
7239 enum reg_class class;
296b8152 7240 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7241 rtx in;
7242{
5accd822 7243 int regno;
9878760c 7244
ab82a49f
AP
7245 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
7246#if TARGET_MACHO
7247 && MACHOPIC_INDIRECT
7248#endif
7249 ))
46fad5b7
DJ
7250 {
7251 /* We cannot copy a symbolic operand directly into anything
7252 other than BASE_REGS for TARGET_ELF. So indicate that a
7253 register from BASE_REGS is needed as an intermediate
7254 register.
7255
7256 On Darwin, pic addresses require a load from memory, which
7257 needs a base register. */
7258 if (class != BASE_REGS
7259 && (GET_CODE (in) == SYMBOL_REF
7260 || GET_CODE (in) == HIGH
7261 || GET_CODE (in) == LABEL_REF
7262 || GET_CODE (in) == CONST))
7263 return BASE_REGS;
7264 }
e7b7998a 7265
5accd822
DE
7266 if (GET_CODE (in) == REG)
7267 {
7268 regno = REGNO (in);
7269 if (regno >= FIRST_PSEUDO_REGISTER)
7270 {
7271 regno = true_regnum (in);
7272 if (regno >= FIRST_PSEUDO_REGISTER)
7273 regno = -1;
7274 }
7275 }
7276 else if (GET_CODE (in) == SUBREG)
7277 {
7278 regno = true_regnum (in);
7279 if (regno >= FIRST_PSEUDO_REGISTER)
7280 regno = -1;
7281 }
7282 else
7283 regno = -1;
7284
9878760c
RK
7285 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
7286 into anything. */
7287 if (class == GENERAL_REGS || class == BASE_REGS
7288 || (regno >= 0 && INT_REGNO_P (regno)))
7289 return NO_REGS;
7290
7291 /* Constants, memory, and FP registers can go into FP registers. */
7292 if ((regno == -1 || FP_REGNO_P (regno))
7293 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
7294 return NO_REGS;
7295
0ac081f6
AH
7296 /* Memory, and AltiVec registers can go into AltiVec registers. */
7297 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
7298 && class == ALTIVEC_REGS)
7299 return NO_REGS;
7300
9878760c
RK
7301 /* We can copy among the CR registers. */
7302 if ((class == CR_REGS || class == CR0_REGS)
7303 && regno >= 0 && CR_REGNO_P (regno))
7304 return NO_REGS;
7305
7306 /* Otherwise, we need GENERAL_REGS. */
7307 return GENERAL_REGS;
7308}
7309\f
7310/* Given a comparison operation, return the bit number in CCR to test. We
7311 know this is a valid comparison.
7312
7313 SCC_P is 1 if this is for an scc. That means that %D will have been
7314 used instead of %C, so the bits will be in different places.
7315
b4ac57ab 7316 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
7317
7318int
7319ccr_bit (op, scc_p)
592696dd 7320 rtx op;
9878760c
RK
7321 int scc_p;
7322{
7323 enum rtx_code code = GET_CODE (op);
7324 enum machine_mode cc_mode;
7325 int cc_regnum;
7326 int base_bit;
9ebbca7d 7327 rtx reg;
9878760c
RK
7328
7329 if (GET_RTX_CLASS (code) != '<')
7330 return -1;
7331
9ebbca7d
GK
7332 reg = XEXP (op, 0);
7333
7334 if (GET_CODE (reg) != REG
7335 || ! CR_REGNO_P (REGNO (reg)))
7336 abort ();
7337
7338 cc_mode = GET_MODE (reg);
7339 cc_regnum = REGNO (reg);
7340 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 7341
39a10a29 7342 validate_condition_mode (code, cc_mode);
c5defebb 7343
9878760c
RK
7344 switch (code)
7345 {
7346 case NE:
a3170dc6
AH
7347 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7348 return base_bit + 1;
9878760c
RK
7349 return scc_p ? base_bit + 3 : base_bit + 2;
7350 case EQ:
a3170dc6
AH
7351 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7352 return base_bit + 1;
9878760c 7353 return base_bit + 2;
1c882ea4 7354 case GT: case GTU: case UNLE:
9878760c 7355 return base_bit + 1;
1c882ea4 7356 case LT: case LTU: case UNGE:
9878760c 7357 return base_bit;
1c882ea4
GK
7358 case ORDERED: case UNORDERED:
7359 return base_bit + 3;
9878760c
RK
7360
7361 case GE: case GEU:
39a10a29 7362 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
7363 unordered position. So test that bit. For integer, this is ! LT
7364 unless this is an scc insn. */
39a10a29 7365 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
7366
7367 case LE: case LEU:
39a10a29 7368 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 7369
9878760c
RK
7370 default:
7371 abort ();
7372 }
7373}
1ff7789b 7374\f
8d30c4ee 7375/* Return the GOT register. */
1ff7789b
MM
7376
7377struct rtx_def *
7378rs6000_got_register (value)
5f59ecb7 7379 rtx value ATTRIBUTE_UNUSED;
1ff7789b 7380{
a4f6c312
SS
7381 /* The second flow pass currently (June 1999) can't update
7382 regs_ever_live without disturbing other parts of the compiler, so
7383 update it here to make the prolog/epilogue code happy. */
1db02437
FS
7384 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
7385 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 7386
8d30c4ee 7387 current_function_uses_pic_offset_table = 1;
3cb999d8 7388
1ff7789b
MM
7389 return pic_offset_table_rtx;
7390}
a7df97e6 7391\f
e2500fed
GK
7392/* Function to init struct machine_function.
7393 This will be called, via a pointer variable,
7394 from push_function_context. */
a7df97e6 7395
e2500fed
GK
7396static struct machine_function *
7397rs6000_init_machine_status ()
a7df97e6 7398{
e2500fed 7399 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 7400}
9878760c 7401\f
0ba1b2ff
AM
7402/* These macros test for integers and extract the low-order bits. */
7403#define INT_P(X) \
7404((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
7405 && GET_MODE (X) == VOIDmode)
7406
7407#define INT_LOWPART(X) \
7408 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
7409
7410int
7411extract_MB (op)
7412 rtx op;
7413{
7414 int i;
7415 unsigned long val = INT_LOWPART (op);
7416
7417 /* If the high bit is zero, the value is the first 1 bit we find
7418 from the left. */
7419 if ((val & 0x80000000) == 0)
7420 {
7421 if ((val & 0xffffffff) == 0)
7422 abort ();
7423
7424 i = 1;
7425 while (((val <<= 1) & 0x80000000) == 0)
7426 ++i;
7427 return i;
7428 }
7429
7430 /* If the high bit is set and the low bit is not, or the mask is all
7431 1's, the value is zero. */
7432 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
7433 return 0;
7434
7435 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7436 from the right. */
7437 i = 31;
7438 while (((val >>= 1) & 1) != 0)
7439 --i;
7440
7441 return i;
7442}
7443
7444int
7445extract_ME (op)
7446 rtx op;
7447{
7448 int i;
7449 unsigned long val = INT_LOWPART (op);
7450
7451 /* If the low bit is zero, the value is the first 1 bit we find from
7452 the right. */
7453 if ((val & 1) == 0)
7454 {
7455 if ((val & 0xffffffff) == 0)
7456 abort ();
7457
7458 i = 30;
7459 while (((val >>= 1) & 1) == 0)
7460 --i;
7461
7462 return i;
7463 }
7464
7465 /* If the low bit is set and the high bit is not, or the mask is all
7466 1's, the value is 31. */
7467 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
7468 return 31;
7469
7470 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7471 from the left. */
7472 i = 0;
7473 while (((val <<= 1) & 0x80000000) != 0)
7474 ++i;
7475
7476 return i;
7477}
7478
9878760c
RK
7479/* Print an operand. Recognize special options, documented below. */
7480
38c1f2d7 7481#if TARGET_ELF
d9407988 7482#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 7483#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
7484#else
7485#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 7486#define SMALL_DATA_REG 0
ba5e43aa
MM
7487#endif
7488
9878760c
RK
7489void
7490print_operand (file, x, code)
7491 FILE *file;
7492 rtx x;
9ebbca7d 7493 int code;
9878760c
RK
7494{
7495 int i;
a260abc9 7496 HOST_WIDE_INT val;
0ba1b2ff 7497 unsigned HOST_WIDE_INT uval;
9878760c
RK
7498
7499 switch (code)
7500 {
a8b3aeda 7501 case '.':
a85d226b
RK
7502 /* Write out an instruction after the call which may be replaced
7503 with glue code by the loader. This depends on the AIX version. */
7504 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
7505 return;
7506
81eace42
GK
7507 /* %a is output_address. */
7508
9854d9ed
RK
7509 case 'A':
7510 /* If X is a constant integer whose low-order 5 bits are zero,
7511 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 7512 in the AIX assembler where "sri" with a zero shift count
20e26713 7513 writes a trash instruction. */
9854d9ed 7514 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 7515 putc ('l', file);
9854d9ed 7516 else
76229ac8 7517 putc ('r', file);
9854d9ed
RK
7518 return;
7519
7520 case 'b':
e2c953b6
DE
7521 /* If constant, low-order 16 bits of constant, unsigned.
7522 Otherwise, write normally. */
7523 if (INT_P (x))
7524 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
7525 else
7526 print_operand (file, x, 0);
cad12a8d
RK
7527 return;
7528
a260abc9
DE
7529 case 'B':
7530 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
7531 for 64-bit mask direction. */
296b8152 7532 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 7533 return;
a260abc9 7534
81eace42
GK
7535 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
7536 output_operand. */
7537
9854d9ed 7538 case 'D':
39a10a29
GK
7539 /* There used to be a comment for 'C' reading "This is an
7540 optional cror needed for certain floating-point
7541 comparisons. Otherwise write nothing." */
7542
9854d9ed
RK
7543 /* Similar, except that this is for an scc, so we must be able to
7544 encode the test in a single bit that is one. We do the above
7545 for any LE, GE, GEU, or LEU and invert the bit for NE. */
7546 if (GET_CODE (x) == LE || GET_CODE (x) == GE
7547 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
7548 {
9ebbca7d 7549 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7550
7551 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
7552 base_bit + 2,
7553 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
7554 }
7555
7556 else if (GET_CODE (x) == NE)
7557 {
9ebbca7d 7558 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7559
7560 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
7561 base_bit + 2, base_bit + 2);
7562 }
a3170dc6
AH
7563 else if (TARGET_SPE && TARGET_HARD_FLOAT
7564 && GET_CODE (x) == EQ
7565 && GET_MODE (XEXP (x, 0)) == CCFPmode)
7566 {
7567 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
7568
7569 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 1,
7570 base_bit + 1, base_bit + 1);
7571 }
9854d9ed
RK
7572 return;
7573
7574 case 'E':
39a10a29 7575 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
7576 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7577 output_operand_lossage ("invalid %%E value");
78fbdbf7 7578 else
39a10a29 7579 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 7580 return;
9854d9ed
RK
7581
7582 case 'f':
7583 /* X is a CR register. Print the shift count needed to move it
7584 to the high-order four bits. */
7585 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7586 output_operand_lossage ("invalid %%f value");
7587 else
9ebbca7d 7588 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7589 return;
7590
7591 case 'F':
7592 /* Similar, but print the count for the rotate in the opposite
7593 direction. */
7594 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7595 output_operand_lossage ("invalid %%F value");
7596 else
9ebbca7d 7597 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7598 return;
7599
7600 case 'G':
7601 /* X is a constant integer. If it is negative, print "m",
43aa4e05 7602 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
7603 if (GET_CODE (x) != CONST_INT)
7604 output_operand_lossage ("invalid %%G value");
7605 else if (INTVAL (x) >= 0)
76229ac8 7606 putc ('z', file);
9854d9ed 7607 else
76229ac8 7608 putc ('m', file);
9854d9ed 7609 return;
e2c953b6 7610
9878760c 7611 case 'h':
a4f6c312
SS
7612 /* If constant, output low-order five bits. Otherwise, write
7613 normally. */
9878760c 7614 if (INT_P (x))
5f59ecb7 7615 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
7616 else
7617 print_operand (file, x, 0);
7618 return;
7619
64305719 7620 case 'H':
a4f6c312
SS
7621 /* If constant, output low-order six bits. Otherwise, write
7622 normally. */
64305719 7623 if (INT_P (x))
5f59ecb7 7624 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
7625 else
7626 print_operand (file, x, 0);
7627 return;
7628
9854d9ed
RK
7629 case 'I':
7630 /* Print `i' if this is a constant, else nothing. */
9878760c 7631 if (INT_P (x))
76229ac8 7632 putc ('i', file);
9878760c
RK
7633 return;
7634
9854d9ed
RK
7635 case 'j':
7636 /* Write the bit number in CCR for jump. */
7637 i = ccr_bit (x, 0);
7638 if (i == -1)
7639 output_operand_lossage ("invalid %%j code");
9878760c 7640 else
9854d9ed 7641 fprintf (file, "%d", i);
9878760c
RK
7642 return;
7643
9854d9ed
RK
7644 case 'J':
7645 /* Similar, but add one for shift count in rlinm for scc and pass
7646 scc flag to `ccr_bit'. */
7647 i = ccr_bit (x, 1);
7648 if (i == -1)
7649 output_operand_lossage ("invalid %%J code");
7650 else
a0466a68
RK
7651 /* If we want bit 31, write a shift count of zero, not 32. */
7652 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
7653 return;
7654
9854d9ed
RK
7655 case 'k':
7656 /* X must be a constant. Write the 1's complement of the
7657 constant. */
9878760c 7658 if (! INT_P (x))
9854d9ed 7659 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
7660 else
7661 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
7662 return;
7663
81eace42 7664 case 'K':
9ebbca7d
GK
7665 /* X must be a symbolic constant on ELF. Write an
7666 expression suitable for an 'addi' that adds in the low 16
7667 bits of the MEM. */
7668 if (GET_CODE (x) != CONST)
7669 {
7670 print_operand_address (file, x);
7671 fputs ("@l", file);
7672 }
7673 else
7674 {
7675 if (GET_CODE (XEXP (x, 0)) != PLUS
7676 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
7677 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
7678 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 7679 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
7680 print_operand_address (file, XEXP (XEXP (x, 0), 0));
7681 fputs ("@l", file);
ed8d2920
MM
7682 /* For GNU as, there must be a non-alphanumeric character
7683 between 'l' and the number. The '-' is added by
7684 print_operand() already. */
7685 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
7686 fputs ("+", file);
9ebbca7d
GK
7687 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
7688 }
81eace42
GK
7689 return;
7690
7691 /* %l is output_asm_label. */
9ebbca7d 7692
9854d9ed
RK
7693 case 'L':
7694 /* Write second word of DImode or DFmode reference. Works on register
7695 or non-indexed memory only. */
7696 if (GET_CODE (x) == REG)
5ebfb2ba 7697 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
7698 else if (GET_CODE (x) == MEM)
7699 {
7700 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 7701 we have already done it, we can just use an offset of word. */
9854d9ed
RK
7702 if (GET_CODE (XEXP (x, 0)) == PRE_INC
7703 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
7704 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
7705 UNITS_PER_WORD));
9854d9ed 7706 else
d7624dc0
RK
7707 output_address (XEXP (adjust_address_nv (x, SImode,
7708 UNITS_PER_WORD),
7709 0));
ed8908e7 7710
ba5e43aa 7711 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
7712 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
7713 reg_names[SMALL_DATA_REG]);
9854d9ed 7714 }
9878760c 7715 return;
9854d9ed 7716
9878760c
RK
7717 case 'm':
7718 /* MB value for a mask operand. */
b1765bde 7719 if (! mask_operand (x, SImode))
9878760c
RK
7720 output_operand_lossage ("invalid %%m value");
7721
0ba1b2ff 7722 fprintf (file, "%d", extract_MB (x));
9878760c
RK
7723 return;
7724
7725 case 'M':
7726 /* ME value for a mask operand. */
b1765bde 7727 if (! mask_operand (x, SImode))
a260abc9 7728 output_operand_lossage ("invalid %%M value");
9878760c 7729
0ba1b2ff 7730 fprintf (file, "%d", extract_ME (x));
9878760c
RK
7731 return;
7732
81eace42
GK
7733 /* %n outputs the negative of its operand. */
7734
9878760c
RK
7735 case 'N':
7736 /* Write the number of elements in the vector times 4. */
7737 if (GET_CODE (x) != PARALLEL)
7738 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
7739 else
7740 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
7741 return;
7742
7743 case 'O':
7744 /* Similar, but subtract 1 first. */
7745 if (GET_CODE (x) != PARALLEL)
1427100a 7746 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
7747 else
7748 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
7749 return;
7750
9854d9ed
RK
7751 case 'p':
7752 /* X is a CONST_INT that is a power of two. Output the logarithm. */
7753 if (! INT_P (x)
2bfcf297 7754 || INT_LOWPART (x) < 0
9854d9ed
RK
7755 || (i = exact_log2 (INT_LOWPART (x))) < 0)
7756 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
7757 else
7758 fprintf (file, "%d", i);
9854d9ed
RK
7759 return;
7760
9878760c
RK
7761 case 'P':
7762 /* The operand must be an indirect memory reference. The result
a4f6c312 7763 is the register number. */
9878760c
RK
7764 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
7765 || REGNO (XEXP (x, 0)) >= 32)
7766 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
7767 else
7768 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
7769 return;
7770
dfbdccdb
GK
7771 case 'q':
7772 /* This outputs the logical code corresponding to a boolean
7773 expression. The expression may have one or both operands
39a10a29
GK
7774 negated (if one, only the first one). For condition register
7775 logical operations, it will also treat the negated
7776 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 7777 {
63bc1d05 7778 const char *const *t = 0;
dfbdccdb
GK
7779 const char *s;
7780 enum rtx_code code = GET_CODE (x);
7781 static const char * const tbl[3][3] = {
7782 { "and", "andc", "nor" },
7783 { "or", "orc", "nand" },
7784 { "xor", "eqv", "xor" } };
7785
7786 if (code == AND)
7787 t = tbl[0];
7788 else if (code == IOR)
7789 t = tbl[1];
7790 else if (code == XOR)
7791 t = tbl[2];
7792 else
7793 output_operand_lossage ("invalid %%q value");
7794
7795 if (GET_CODE (XEXP (x, 0)) != NOT)
7796 s = t[0];
7797 else
7798 {
7799 if (GET_CODE (XEXP (x, 1)) == NOT)
7800 s = t[2];
7801 else
7802 s = t[1];
7803 }
7804
7805 fputs (s, file);
7806 }
7807 return;
7808
9854d9ed
RK
7809 case 'R':
7810 /* X is a CR register. Print the mask for `mtcrf'. */
7811 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7812 output_operand_lossage ("invalid %%R value");
7813 else
9ebbca7d 7814 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 7815 return;
9854d9ed
RK
7816
7817 case 's':
7818 /* Low 5 bits of 32 - value */
7819 if (! INT_P (x))
7820 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
7821 else
7822 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 7823 return;
9854d9ed 7824
a260abc9 7825 case 'S':
0ba1b2ff 7826 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
7827 CONST_INT 32-bit mask is considered sign-extended so any
7828 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 7829 if (! mask64_operand (x, DImode))
a260abc9
DE
7830 output_operand_lossage ("invalid %%S value");
7831
0ba1b2ff 7832 uval = INT_LOWPART (x);
a260abc9 7833
0ba1b2ff 7834 if (uval & 1) /* Clear Left */
a260abc9 7835 {
f099d360
GK
7836#if HOST_BITS_PER_WIDE_INT > 64
7837 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7838#endif
0ba1b2ff 7839 i = 64;
a260abc9 7840 }
0ba1b2ff 7841 else /* Clear Right */
a260abc9 7842 {
0ba1b2ff 7843 uval = ~uval;
f099d360
GK
7844#if HOST_BITS_PER_WIDE_INT > 64
7845 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7846#endif
0ba1b2ff 7847 i = 63;
a260abc9 7848 }
0ba1b2ff
AM
7849 while (uval != 0)
7850 --i, uval >>= 1;
7851 if (i < 0)
7852 abort ();
7853 fprintf (file, "%d", i);
7854 return;
a260abc9 7855
a3170dc6
AH
7856 case 't':
7857 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
7858 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
7859 abort ();
7860
7861 /* Bit 3 is OV bit. */
7862 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
7863
7864 /* If we want bit 31, write a shift count of zero, not 32. */
7865 fprintf (file, "%d", i == 31 ? 0 : i + 1);
7866 return;
7867
cccf3bdc
DE
7868 case 'T':
7869 /* Print the symbolic name of a branch target register. */
7870 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
7871 && REGNO (x) != COUNT_REGISTER_REGNUM))
7872 output_operand_lossage ("invalid %%T value");
e2c953b6 7873 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
7874 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
7875 else
7876 fputs ("ctr", file);
7877 return;
7878
9854d9ed 7879 case 'u':
802a0058 7880 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
7881 if (! INT_P (x))
7882 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
7883 else
7884 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7885 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
7886 return;
7887
802a0058
MM
7888 case 'v':
7889 /* High-order 16 bits of constant for use in signed operand. */
7890 if (! INT_P (x))
7891 output_operand_lossage ("invalid %%v value");
e2c953b6 7892 else
134c32f6
DE
7893 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7894 (INT_LOWPART (x) >> 16) & 0xffff);
7895 return;
802a0058 7896
9854d9ed
RK
7897 case 'U':
7898 /* Print `u' if this has an auto-increment or auto-decrement. */
7899 if (GET_CODE (x) == MEM
7900 && (GET_CODE (XEXP (x, 0)) == PRE_INC
7901 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 7902 putc ('u', file);
9854d9ed 7903 return;
9878760c 7904
e0cd0770
JC
7905 case 'V':
7906 /* Print the trap code for this operand. */
7907 switch (GET_CODE (x))
7908 {
7909 case EQ:
7910 fputs ("eq", file); /* 4 */
7911 break;
7912 case NE:
7913 fputs ("ne", file); /* 24 */
7914 break;
7915 case LT:
7916 fputs ("lt", file); /* 16 */
7917 break;
7918 case LE:
7919 fputs ("le", file); /* 20 */
7920 break;
7921 case GT:
7922 fputs ("gt", file); /* 8 */
7923 break;
7924 case GE:
7925 fputs ("ge", file); /* 12 */
7926 break;
7927 case LTU:
7928 fputs ("llt", file); /* 2 */
7929 break;
7930 case LEU:
7931 fputs ("lle", file); /* 6 */
7932 break;
7933 case GTU:
7934 fputs ("lgt", file); /* 1 */
7935 break;
7936 case GEU:
7937 fputs ("lge", file); /* 5 */
7938 break;
7939 default:
7940 abort ();
7941 }
7942 break;
7943
9854d9ed
RK
7944 case 'w':
7945 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
7946 normally. */
7947 if (INT_P (x))
5f59ecb7
DE
7948 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
7949 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
7950 else
7951 print_operand (file, x, 0);
9878760c
RK
7952 return;
7953
9854d9ed 7954 case 'W':
e2c953b6 7955 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
7956 val = (GET_CODE (x) == CONST_INT
7957 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
7958
7959 if (val < 0)
7960 i = -1;
9854d9ed 7961 else
e2c953b6
DE
7962 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
7963 if ((val <<= 1) < 0)
7964 break;
7965
7966#if HOST_BITS_PER_WIDE_INT == 32
7967 if (GET_CODE (x) == CONST_INT && i >= 0)
7968 i += 32; /* zero-extend high-part was all 0's */
7969 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
7970 {
7971 val = CONST_DOUBLE_LOW (x);
7972
7973 if (val == 0)
a4f6c312 7974 abort ();
e2c953b6
DE
7975 else if (val < 0)
7976 --i;
7977 else
7978 for ( ; i < 64; i++)
7979 if ((val <<= 1) < 0)
7980 break;
7981 }
7982#endif
7983
7984 fprintf (file, "%d", i + 1);
9854d9ed 7985 return;
9878760c 7986
9854d9ed
RK
7987 case 'X':
7988 if (GET_CODE (x) == MEM
258bfae2 7989 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0))
76229ac8 7990 putc ('x', file);
9854d9ed 7991 return;
9878760c 7992
9854d9ed
RK
7993 case 'Y':
7994 /* Like 'L', for third word of TImode */
7995 if (GET_CODE (x) == REG)
5ebfb2ba 7996 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 7997 else if (GET_CODE (x) == MEM)
9878760c 7998 {
9854d9ed
RK
7999 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8000 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8001 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 8002 else
d7624dc0 8003 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 8004 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8005 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8006 reg_names[SMALL_DATA_REG]);
9878760c
RK
8007 }
8008 return;
9854d9ed 8009
9878760c 8010 case 'z':
b4ac57ab
RS
8011 /* X is a SYMBOL_REF. Write out the name preceded by a
8012 period and without any trailing data in brackets. Used for function
4d30c363
MM
8013 names. If we are configured for System V (or the embedded ABI) on
8014 the PowerPC, do not emit the period, since those systems do not use
8015 TOCs and the like. */
9878760c
RK
8016 if (GET_CODE (x) != SYMBOL_REF)
8017 abort ();
8018
b6c9286a
MM
8019 if (XSTR (x, 0)[0] != '.')
8020 {
8021 switch (DEFAULT_ABI)
8022 {
8023 default:
8024 abort ();
8025
8026 case ABI_AIX:
8027 putc ('.', file);
8028 break;
8029
8030 case ABI_V4:
8031 case ABI_AIX_NODESC:
ee890fe2 8032 case ABI_DARWIN:
b6c9286a 8033 break;
b6c9286a
MM
8034 }
8035 }
54ee9799
DE
8036#if TARGET_AIX
8037 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
8038#else
9ebbca7d 8039 assemble_name (file, XSTR (x, 0));
54ee9799 8040#endif
9878760c
RK
8041 return;
8042
9854d9ed
RK
8043 case 'Z':
8044 /* Like 'L', for last word of TImode. */
8045 if (GET_CODE (x) == REG)
5ebfb2ba 8046 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
8047 else if (GET_CODE (x) == MEM)
8048 {
8049 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8050 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8051 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 8052 else
d7624dc0 8053 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 8054 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8055 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8056 reg_names[SMALL_DATA_REG]);
9854d9ed 8057 }
5c23c401 8058 return;
0ac081f6 8059
a3170dc6 8060 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
8061 case 'y':
8062 {
8063 rtx tmp;
8064
8065 if (GET_CODE (x) != MEM)
8066 abort ();
8067
8068 tmp = XEXP (x, 0);
8069
a3170dc6
AH
8070 if (TARGET_SPE)
8071 {
8072 /* Handle [reg]. */
8073 if (GET_CODE (tmp) == REG)
8074 {
8075 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
8076 break;
8077 }
8078 /* Handle [reg+UIMM]. */
8079 else if (GET_CODE (tmp) == PLUS &&
8080 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
8081 {
8082 int x;
8083
8084 if (GET_CODE (XEXP (tmp, 0)) != REG)
8085 abort ();
8086
8087 x = INTVAL (XEXP (tmp, 1));
8088 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
8089 break;
8090 }
8091
8092 /* Fall through. Must be [reg+reg]. */
8093 }
0ac081f6 8094 if (GET_CODE (tmp) == REG)
c62f2db5 8095 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
8096 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
8097 {
8098 if (REGNO (XEXP (tmp, 0)) == 0)
8099 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
8100 reg_names[ REGNO (XEXP (tmp, 0)) ]);
8101 else
8102 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
8103 reg_names[ REGNO (XEXP (tmp, 1)) ]);
8104 }
8105 else
8106 abort ();
8107 break;
8108 }
9854d9ed 8109
9878760c
RK
8110 case 0:
8111 if (GET_CODE (x) == REG)
8112 fprintf (file, "%s", reg_names[REGNO (x)]);
8113 else if (GET_CODE (x) == MEM)
8114 {
8115 /* We need to handle PRE_INC and PRE_DEC here, since we need to
8116 know the width from the mode. */
8117 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
8118 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
8119 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8120 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
8121 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
8122 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8123 else
a54d04b7 8124 output_address (XEXP (x, 0));
9878760c
RK
8125 }
8126 else
a54d04b7 8127 output_addr_const (file, x);
a85d226b 8128 return;
9878760c
RK
8129
8130 default:
8131 output_operand_lossage ("invalid %%xn code");
8132 }
8133}
8134\f
8135/* Print the address of an operand. */
8136
8137void
8138print_operand_address (file, x)
8139 FILE *file;
592696dd 8140 rtx x;
9878760c
RK
8141{
8142 if (GET_CODE (x) == REG)
4697a36c 8143 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
8144 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
8145 || GET_CODE (x) == LABEL_REF)
9878760c
RK
8146 {
8147 output_addr_const (file, x);
ba5e43aa 8148 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8149 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8150 reg_names[SMALL_DATA_REG]);
9ebbca7d 8151 else if (TARGET_TOC)
a4f6c312 8152 abort ();
9878760c
RK
8153 }
8154 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
8155 {
8156 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
8157 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
8158 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 8159 else
4697a36c
MM
8160 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
8161 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
8162 }
8163 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
5f59ecb7
DE
8164 {
8165 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
8166 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8167 }
3cb999d8
DE
8168#if TARGET_ELF
8169 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8170 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
8171 {
8172 output_addr_const (file, XEXP (x, 1));
8173 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8174 }
c859cda6
DJ
8175#endif
8176#if TARGET_MACHO
8177 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8178 && CONSTANT_P (XEXP (x, 1)))
8179 {
8180 fprintf (file, "lo16(");
8181 output_addr_const (file, XEXP (x, 1));
8182 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8183 }
3cb999d8 8184#endif
9ebbca7d
GK
8185 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
8186 {
2bfcf297 8187 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 8188 {
2bfcf297
DB
8189 rtx contains_minus = XEXP (x, 1);
8190 rtx minus, symref;
8191 const char *name;
9ebbca7d
GK
8192
8193 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 8194 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
8195 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
8196 contains_minus = XEXP (contains_minus, 0);
8197
2bfcf297
DB
8198 minus = XEXP (contains_minus, 0);
8199 symref = XEXP (minus, 0);
8200 XEXP (contains_minus, 0) = symref;
8201 if (TARGET_ELF)
8202 {
8203 char *newname;
8204
8205 name = XSTR (symref, 0);
8206 newname = alloca (strlen (name) + sizeof ("@toc"));
8207 strcpy (newname, name);
8208 strcat (newname, "@toc");
8209 XSTR (symref, 0) = newname;
8210 }
8211 output_addr_const (file, XEXP (x, 1));
8212 if (TARGET_ELF)
8213 XSTR (symref, 0) = name;
9ebbca7d
GK
8214 XEXP (contains_minus, 0) = minus;
8215 }
8216 else
8217 output_addr_const (file, XEXP (x, 1));
8218
8219 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
8220 }
9878760c
RK
8221 else
8222 abort ();
8223}
8224\f
88cad84b 8225/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
8226 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
8227 is defined. It also needs to handle DI-mode objects on 64-bit
8228 targets. */
8229
8230static bool
8231rs6000_assemble_integer (x, size, aligned_p)
8232 rtx x;
8233 unsigned int size;
8234 int aligned_p;
8235{
8236#ifdef RELOCATABLE_NEEDS_FIXUP
8237 /* Special handling for SI values. */
8238 if (size == 4 && aligned_p)
8239 {
8240 extern int in_toc_section PARAMS ((void));
8241 static int recurse = 0;
8242
8243 /* For -mrelocatable, we mark all addresses that need to be fixed up
8244 in the .fixup section. */
8245 if (TARGET_RELOCATABLE
8246 && !in_toc_section ()
8247 && !in_text_section ()
8248 && !recurse
8249 && GET_CODE (x) != CONST_INT
8250 && GET_CODE (x) != CONST_DOUBLE
8251 && CONSTANT_P (x))
8252 {
8253 char buf[256];
8254
8255 recurse = 1;
8256 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
8257 fixuplabelno++;
8258 ASM_OUTPUT_LABEL (asm_out_file, buf);
8259 fprintf (asm_out_file, "\t.long\t(");
8260 output_addr_const (asm_out_file, x);
8261 fprintf (asm_out_file, ")@fixup\n");
8262 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
8263 ASM_OUTPUT_ALIGN (asm_out_file, 2);
8264 fprintf (asm_out_file, "\t.long\t");
8265 assemble_name (asm_out_file, buf);
8266 fprintf (asm_out_file, "\n\t.previous\n");
8267 recurse = 0;
8268 return true;
8269 }
8270 /* Remove initial .'s to turn a -mcall-aixdesc function
8271 address into the address of the descriptor, not the function
8272 itself. */
8273 else if (GET_CODE (x) == SYMBOL_REF
8274 && XSTR (x, 0)[0] == '.'
8275 && DEFAULT_ABI == ABI_AIX)
8276 {
8277 const char *name = XSTR (x, 0);
8278 while (*name == '.')
8279 name++;
8280
8281 fprintf (asm_out_file, "\t.long\t%s\n", name);
8282 return true;
8283 }
8284 }
8285#endif /* RELOCATABLE_NEEDS_FIXUP */
8286 return default_assemble_integer (x, size, aligned_p);
8287}
93638d7a
AM
8288
8289#ifdef HAVE_GAS_HIDDEN
8290/* Emit an assembler directive to set symbol visibility for DECL to
8291 VISIBILITY_TYPE. */
8292
5add3202 8293static void
25fdb4dc 8294rs6000_assemble_visibility (decl, vis)
93638d7a 8295 tree decl;
25fdb4dc 8296 int vis;
93638d7a 8297{
93638d7a
AM
8298 /* Functions need to have their entry point symbol visibility set as
8299 well as their descriptor symbol visibility. */
8300 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
8301 {
25fdb4dc
RH
8302 static const char * const visibility_types[] = {
8303 NULL, "internal", "hidden", "protected"
8304 };
8305
8306 const char *name, *type;
93638d7a
AM
8307
8308 name = ((* targetm.strip_name_encoding)
8309 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 8310 type = visibility_types[vis];
93638d7a 8311
25fdb4dc
RH
8312 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
8313 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 8314 }
25fdb4dc
RH
8315 else
8316 default_assemble_visibility (decl, vis);
93638d7a
AM
8317}
8318#endif
301d03af 8319\f
39a10a29
GK
8320enum rtx_code
8321rs6000_reverse_condition (mode, code)
8322 enum machine_mode mode;
8323 enum rtx_code code;
8324{
8325 /* Reversal of FP compares takes care -- an ordered compare
8326 becomes an unordered compare and vice versa. */
de40e1df 8327 if (mode == CCFPmode && !flag_unsafe_math_optimizations)
bab6226b 8328 return reverse_condition_maybe_unordered (code);
39a10a29 8329 else
bab6226b 8330 return reverse_condition (code);
39a10a29
GK
8331}
8332
39a10a29
GK
8333/* Generate a compare for CODE. Return a brand-new rtx that
8334 represents the result of the compare. */
a4f6c312 8335
39a10a29
GK
8336static rtx
8337rs6000_generate_compare (code)
8338 enum rtx_code code;
8339{
8340 enum machine_mode comp_mode;
8341 rtx compare_result;
8342
8343 if (rs6000_compare_fp_p)
8344 comp_mode = CCFPmode;
8345 else if (code == GTU || code == LTU
8346 || code == GEU || code == LEU)
8347 comp_mode = CCUNSmode;
8348 else
8349 comp_mode = CCmode;
8350
8351 /* First, the compare. */
8352 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
8353
8354 /* SPE FP compare instructions on the GPRs. Yuck! */
8355 if ((TARGET_SPE && TARGET_HARD_FLOAT) && rs6000_compare_fp_p)
8356 {
8357 rtx cmp, or1, or2, or_result, compare_result2;
8358
8359 switch (code)
8360 {
8361 case EQ:
8362 case UNEQ:
8363 case NE:
8364 case LTGT:
8365 cmp = flag_unsafe_math_optimizations
8366 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
8367 rs6000_compare_op1)
8368 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
8369 rs6000_compare_op1);
8370 break;
8371 case GT:
8372 case GTU:
8373 case UNGT:
8374 case UNGE:
8375 case GE:
8376 case GEU:
8377 cmp = flag_unsafe_math_optimizations
8378 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
8379 rs6000_compare_op1)
8380 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
8381 rs6000_compare_op1);
8382 break;
8383 case LT:
8384 case LTU:
8385 case UNLT:
8386 case UNLE:
8387 case LE:
8388 case LEU:
8389 cmp = flag_unsafe_math_optimizations
8390 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
8391 rs6000_compare_op1)
8392 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
8393 rs6000_compare_op1);
8394 break;
8395 default:
8396 abort ();
8397 }
8398
8399 /* Synthesize LE and GE from LT/GT || EQ. */
8400 if (code == LE || code == GE || code == LEU || code == GEU)
8401 {
8402 /* Synthesize GE/LE frome GT/LT || EQ. */
8403
8404 emit_insn (cmp);
8405
8406 switch (code)
8407 {
8408 case LE: code = LT; break;
8409 case GE: code = GT; break;
8410 case LEU: code = LT; break;
8411 case GEU: code = GT; break;
8412 default: abort ();
8413 }
8414
8415 or1 = gen_reg_rtx (SImode);
8416 or2 = gen_reg_rtx (SImode);
8417 or_result = gen_reg_rtx (CCEQmode);
8418 compare_result2 = gen_reg_rtx (CCFPmode);
8419
8420 /* Do the EQ. */
8421 cmp = flag_unsafe_math_optimizations
8422 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
8423 rs6000_compare_op1)
8424 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
8425 rs6000_compare_op1);
8426 emit_insn (cmp);
8427
8428 /* The MC8540 FP compare instructions set the CR bits
8429 differently than other PPC compare instructions. For
8430 that matter, there is no generic test instruction, but a
8431 testgt, testlt, and testeq. For a true condition, bit 2
8432 is set (x1xx) in the CR. Following the traditional CR
8433 values:
8434
8435 LT GT EQ OV
8436 bit3 bit2 bit1 bit0
8437
8438 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 8439 look in the GT bits for the branch instructions.
a3170dc6
AH
8440 However, we must be careful to emit correct RTL in
8441 the meantime, so optimizations don't get confused. */
8442
8443 or1 = gen_rtx (NE, SImode, compare_result, const0_rtx);
8444 or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx);
8445
8446 /* OR them together. */
8447 cmp = gen_rtx_SET (VOIDmode, or_result,
8448 gen_rtx_COMPARE (CCEQmode,
8449 gen_rtx_IOR (SImode, or1, or2),
8450 const_true_rtx));
8451 compare_result = or_result;
8452 code = EQ;
8453 }
8454 else
8455 {
8456 /* We only care about 1 bit (x1xx), so map everything to NE to
8457 maintain rtl sanity. We'll get to the right bit (x1xx) at
8458 code output time. */
8459 if (code == NE || code == LTGT)
8460 /* Do the inverse here because we have no cmpne
8461 instruction. We use the cmpeq instruction and expect
8462 to get a 0 instead. */
8463 code = EQ;
8464 else
8465 code = NE;
8466 }
8467
8468 emit_insn (cmp);
8469 }
8470 else
8471 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
8472 gen_rtx_COMPARE (comp_mode,
8473 rs6000_compare_op0,
8474 rs6000_compare_op1)));
39a10a29 8475
ca5adc63 8476 /* Some kinds of FP comparisons need an OR operation;
de6c5979 8477 except for flag_unsafe_math_optimizations we don't bother. */
39a10a29 8478 if (rs6000_compare_fp_p
de6c5979 8479 && ! flag_unsafe_math_optimizations
a3170dc6 8480 && ! (TARGET_HARD_FLOAT && TARGET_SPE)
39a10a29
GK
8481 && (code == LE || code == GE
8482 || code == UNEQ || code == LTGT
8483 || code == UNGT || code == UNLT))
8484 {
8485 enum rtx_code or1, or2;
8486 rtx or1_rtx, or2_rtx, compare2_rtx;
8487 rtx or_result = gen_reg_rtx (CCEQmode);
8488
8489 switch (code)
8490 {
8491 case LE: or1 = LT; or2 = EQ; break;
8492 case GE: or1 = GT; or2 = EQ; break;
8493 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
8494 case LTGT: or1 = LT; or2 = GT; break;
8495 case UNGT: or1 = UNORDERED; or2 = GT; break;
8496 case UNLT: or1 = UNORDERED; or2 = LT; break;
8497 default: abort ();
8498 }
8499 validate_condition_mode (or1, comp_mode);
8500 validate_condition_mode (or2, comp_mode);
8501 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
8502 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
8503 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
8504 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
8505 const_true_rtx);
8506 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
8507
8508 compare_result = or_result;
8509 code = EQ;
8510 }
8511
8512 validate_condition_mode (code, GET_MODE (compare_result));
8513
8514 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
8515}
8516
8517
8518/* Emit the RTL for an sCOND pattern. */
8519
8520void
8521rs6000_emit_sCOND (code, result)
8522 enum rtx_code code;
8523 rtx result;
8524{
8525 rtx condition_rtx;
8526 enum machine_mode op_mode;
8527
8528 condition_rtx = rs6000_generate_compare (code);
8529
8530 op_mode = GET_MODE (rs6000_compare_op0);
8531 if (op_mode == VOIDmode)
8532 op_mode = GET_MODE (rs6000_compare_op1);
8533
8534 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
8535 {
8536 PUT_MODE (condition_rtx, DImode);
8537 convert_move (result, condition_rtx, 0);
8538 }
8539 else
8540 {
8541 PUT_MODE (condition_rtx, SImode);
8542 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
8543 }
8544}
8545
39a10a29
GK
8546/* Emit a branch of kind CODE to location LOC. */
8547
8548void
8549rs6000_emit_cbranch (code, loc)
8550 enum rtx_code code;
8551 rtx loc;
8552{
8553 rtx condition_rtx, loc_ref;
8554
8555 condition_rtx = rs6000_generate_compare (code);
8556 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
8557 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
8558 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
8559 loc_ref, pc_rtx)));
8560}
8561
12a4e8c5
GK
8562/* Return the string to output a conditional branch to LABEL, which is
8563 the operand number of the label, or -1 if the branch is really a
8564 conditional return.
8565
8566 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
8567 condition code register and its mode specifies what kind of
8568 comparison we made.
8569
a0ab749a 8570 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
8571
8572 INSN is the insn. */
8573
8574char *
8575output_cbranch (op, label, reversed, insn)
8576 rtx op;
8577 const char * label;
8578 int reversed;
8579 rtx insn;
8580{
8581 static char string[64];
8582 enum rtx_code code = GET_CODE (op);
8583 rtx cc_reg = XEXP (op, 0);
8584 enum machine_mode mode = GET_MODE (cc_reg);
8585 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 8586 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
8587 int really_reversed = reversed ^ need_longbranch;
8588 char *s = string;
8589 const char *ccode;
8590 const char *pred;
8591 rtx note;
8592
39a10a29
GK
8593 validate_condition_mode (code, mode);
8594
8595 /* Work out which way this really branches. We could use
8596 reverse_condition_maybe_unordered here always but this
8597 makes the resulting assembler clearer. */
12a4e8c5 8598 if (really_reversed)
de40e1df
DJ
8599 {
8600 /* Reversal of FP compares takes care -- an ordered compare
8601 becomes an unordered compare and vice versa. */
8602 if (mode == CCFPmode)
8603 code = reverse_condition_maybe_unordered (code);
8604 else
8605 code = reverse_condition (code);
8606 }
12a4e8c5 8607
a3170dc6
AH
8608 if ((TARGET_SPE && TARGET_HARD_FLOAT) && mode == CCFPmode)
8609 {
8610 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
8611 to the GT bit. */
8612 if (code == EQ)
8613 /* Opposite of GT. */
8614 code = UNLE;
8615 else if (code == NE)
8616 code = GT;
8617 else
8618 abort ();
8619 }
8620
39a10a29 8621 switch (code)
12a4e8c5
GK
8622 {
8623 /* Not all of these are actually distinct opcodes, but
8624 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
8625 case NE: case LTGT:
8626 ccode = "ne"; break;
8627 case EQ: case UNEQ:
8628 ccode = "eq"; break;
8629 case GE: case GEU:
8630 ccode = "ge"; break;
8631 case GT: case GTU: case UNGT:
8632 ccode = "gt"; break;
8633 case LE: case LEU:
8634 ccode = "le"; break;
8635 case LT: case LTU: case UNLT:
8636 ccode = "lt"; break;
12a4e8c5
GK
8637 case UNORDERED: ccode = "un"; break;
8638 case ORDERED: ccode = "nu"; break;
8639 case UNGE: ccode = "nl"; break;
8640 case UNLE: ccode = "ng"; break;
8641 default:
a4f6c312 8642 abort ();
12a4e8c5
GK
8643 }
8644
94a54f47
GK
8645 /* Maybe we have a guess as to how likely the branch is.
8646 The old mnemonics don't have a way to specify this information. */
f4857b9b 8647 pred = "";
12a4e8c5
GK
8648 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
8649 if (note != NULL_RTX)
8650 {
8651 /* PROB is the difference from 50%. */
8652 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
8653 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
8654
8655 /* Only hint for highly probable/improbable branches on newer
8656 cpus as static prediction overrides processor dynamic
8657 prediction. For older cpus we may as well always hint, but
8658 assume not taken for branches that are very close to 50% as a
8659 mispredicted taken branch is more expensive than a
8660 mispredicted not-taken branch. */
8661 if (always_hint
8662 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
8663 {
8664 if (abs (prob) > REG_BR_PROB_BASE / 20
8665 && ((prob > 0) ^ need_longbranch))
7f3d8013 8666 pred = "+";
f4857b9b
AM
8667 else
8668 pred = "-";
8669 }
12a4e8c5 8670 }
12a4e8c5
GK
8671
8672 if (label == NULL)
94a54f47 8673 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 8674 else
94a54f47 8675 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 8676
37c67319
GK
8677 /* We need to escape any '%' characters in the reg_names string.
8678 Assume they'd only be the first character... */
8679 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
8680 *s++ = '%';
94a54f47 8681 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
8682
8683 if (label != NULL)
8684 {
8685 /* If the branch distance was too far, we may have to use an
8686 unconditional branch to go the distance. */
8687 if (need_longbranch)
44518ddd 8688 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
8689 else
8690 s += sprintf (s, ",%s", label);
8691 }
8692
8693 return string;
8694}
50a0b056
GK
8695
8696/* Emit a conditional move: move TRUE_COND to DEST if OP of the
8697 operands of the last comparison is nonzero/true, FALSE_COND if it
8698 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 8699
50a0b056
GK
8700int
8701rs6000_emit_cmove (dest, op, true_cond, false_cond)
8702 rtx dest;
8703 rtx op;
8704 rtx true_cond;
8705 rtx false_cond;
8706{
8707 enum rtx_code code = GET_CODE (op);
8708 rtx op0 = rs6000_compare_op0;
8709 rtx op1 = rs6000_compare_op1;
8710 REAL_VALUE_TYPE c1;
3148ad6d
DJ
8711 enum machine_mode compare_mode = GET_MODE (op0);
8712 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
8713 rtx temp;
8714
3148ad6d 8715 /* These modes should always match. */
a3170dc6
AH
8716 if (GET_MODE (op1) != compare_mode
8717 /* In the isel case however, we can use a compare immediate, so
8718 op1 may be a small constant. */
8719 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 8720 return 0;
178c3eff 8721 if (GET_MODE (true_cond) != result_mode)
3148ad6d 8722 return 0;
178c3eff 8723 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
8724 return 0;
8725
50a0b056
GK
8726 /* First, work out if the hardware can do this at all, or
8727 if it's too slow... */
50a0b056 8728 if (! rs6000_compare_fp_p)
a3170dc6
AH
8729 {
8730 if (TARGET_ISEL)
8731 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
8732 return 0;
8733 }
50a0b056
GK
8734
8735 /* Eliminate half of the comparisons by switching operands, this
8736 makes the remaining code simpler. */
8737 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
8738 || code == LTGT || code == LT)
8739 {
8740 code = reverse_condition_maybe_unordered (code);
8741 temp = true_cond;
8742 true_cond = false_cond;
8743 false_cond = temp;
8744 }
8745
8746 /* UNEQ and LTGT take four instructions for a comparison with zero,
8747 it'll probably be faster to use a branch here too. */
8748 if (code == UNEQ)
8749 return 0;
8750
8751 if (GET_CODE (op1) == CONST_DOUBLE)
8752 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
8753
b6d08ca1 8754 /* We're going to try to implement comparisons by performing
50a0b056
GK
8755 a subtract, then comparing against zero. Unfortunately,
8756 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 8757 know that the operand is finite and the comparison
50a0b056
GK
8758 would treat EQ different to UNORDERED, we can't do it. */
8759 if (! flag_unsafe_math_optimizations
8760 && code != GT && code != UNGE
045572c7 8761 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
8762 /* Constructs of the form (a OP b ? a : b) are safe. */
8763 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
8764 || (! rtx_equal_p (op0, true_cond)
8765 && ! rtx_equal_p (op1, true_cond))))
8766 return 0;
8767 /* At this point we know we can use fsel. */
8768
8769 /* Reduce the comparison to a comparison against zero. */
3148ad6d 8770 temp = gen_reg_rtx (compare_mode);
50a0b056 8771 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8772 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 8773 op0 = temp;
3148ad6d 8774 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
8775
8776 /* If we don't care about NaNs we can reduce some of the comparisons
8777 down to faster ones. */
8778 if (flag_unsafe_math_optimizations)
8779 switch (code)
8780 {
8781 case GT:
8782 code = LE;
8783 temp = true_cond;
8784 true_cond = false_cond;
8785 false_cond = temp;
8786 break;
8787 case UNGE:
8788 code = GE;
8789 break;
8790 case UNEQ:
8791 code = EQ;
8792 break;
8793 default:
8794 break;
8795 }
8796
8797 /* Now, reduce everything down to a GE. */
8798 switch (code)
8799 {
8800 case GE:
8801 break;
8802
8803 case LE:
3148ad6d
DJ
8804 temp = gen_reg_rtx (compare_mode);
8805 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8806 op0 = temp;
8807 break;
8808
8809 case ORDERED:
3148ad6d
DJ
8810 temp = gen_reg_rtx (compare_mode);
8811 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
8812 op0 = temp;
8813 break;
8814
8815 case EQ:
3148ad6d 8816 temp = gen_reg_rtx (compare_mode);
50a0b056 8817 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
8818 gen_rtx_NEG (compare_mode,
8819 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
8820 op0 = temp;
8821 break;
8822
8823 case UNGE:
3148ad6d 8824 temp = gen_reg_rtx (result_mode);
50a0b056 8825 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8826 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8827 gen_rtx_GE (VOIDmode,
8828 op0, op1),
8829 true_cond, false_cond)));
8830 false_cond = temp;
8831 true_cond = false_cond;
8832
3148ad6d
DJ
8833 temp = gen_reg_rtx (compare_mode);
8834 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8835 op0 = temp;
8836 break;
8837
8838 case GT:
3148ad6d 8839 temp = gen_reg_rtx (result_mode);
50a0b056 8840 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8841 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8842 gen_rtx_GE (VOIDmode,
8843 op0, op1),
8844 true_cond, false_cond)));
8845 true_cond = temp;
8846 false_cond = true_cond;
8847
3148ad6d
DJ
8848 temp = gen_reg_rtx (compare_mode);
8849 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8850 op0 = temp;
8851 break;
8852
8853 default:
8854 abort ();
8855 }
8856
8857 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 8858 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8859 gen_rtx_GE (VOIDmode,
8860 op0, op1),
8861 true_cond, false_cond)));
8862 return 1;
8863}
8864
a3170dc6
AH
8865/* Same as above, but for ints (isel). */
8866
8867static int
8868rs6000_emit_int_cmove (dest, op, true_cond, false_cond)
8869 rtx dest;
8870 rtx op;
8871 rtx true_cond;
8872 rtx false_cond;
8873{
8874 rtx condition_rtx, cr;
8875
8876 /* All isel implementations thus far are 32-bits. */
8877 if (GET_MODE (rs6000_compare_op0) != SImode)
8878 return 0;
8879
8880 /* We still have to do the compare, because isel doesn't do a
8881 compare, it just looks at the CRx bits set by a previous compare
8882 instruction. */
8883 condition_rtx = rs6000_generate_compare (GET_CODE (op));
8884 cr = XEXP (condition_rtx, 0);
8885
8886 if (GET_MODE (cr) == CCmode)
8887 emit_insn (gen_isel_signed (dest, condition_rtx,
8888 true_cond, false_cond, cr));
8889 else
8890 emit_insn (gen_isel_unsigned (dest, condition_rtx,
8891 true_cond, false_cond, cr));
8892
8893 return 1;
8894}
8895
8896const char *
8897output_isel (operands)
8898 rtx *operands;
8899{
8900 enum rtx_code code;
8901
8902 code = GET_CODE (operands[1]);
8903 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
8904 {
8905 PUT_CODE (operands[1], reverse_condition (code));
8906 return "isel %0,%3,%2,%j1";
8907 }
8908 else
8909 return "isel %0,%2,%3,%j1";
8910}
8911
50a0b056
GK
8912void
8913rs6000_emit_minmax (dest, code, op0, op1)
8914 rtx dest;
8915 enum rtx_code code;
8916 rtx op0;
8917 rtx op1;
8918{
8919 enum machine_mode mode = GET_MODE (op0);
5dc8d536 8920 enum rtx_code c;
50a0b056 8921 rtx target;
5dc8d536
AH
8922
8923 if (code == SMAX || code == SMIN)
8924 c = GE;
8925 else
8926 c = GEU;
8927
50a0b056 8928 if (code == SMAX || code == UMAX)
5dc8d536 8929 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8930 op0, op1, mode, 0);
8931 else
5dc8d536 8932 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8933 op1, op0, mode, 0);
8934 if (target == NULL_RTX)
8935 abort ();
8936 if (target != dest)
8937 emit_move_insn (dest, target);
8938}
12a4e8c5 8939\f
a4f6c312
SS
8940/* This page contains routines that are used to determine what the
8941 function prologue and epilogue code will do and write them out. */
9878760c 8942
a4f6c312
SS
8943/* Return the first fixed-point register that is required to be
8944 saved. 32 if none. */
9878760c
RK
8945
8946int
8947first_reg_to_save ()
8948{
8949 int first_reg;
8950
8951 /* Find lowest numbered live register. */
8952 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
8953 if (regs_ever_live[first_reg]
8954 && (! call_used_regs[first_reg]
1db02437 8955 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 8956 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 8957 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
8958 break;
8959
ee890fe2 8960#if TARGET_MACHO
93638d7a
AM
8961 if (flag_pic
8962 && current_function_uses_pic_offset_table
8963 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 8964 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
8965#endif
8966
9878760c
RK
8967 return first_reg;
8968}
8969
8970/* Similar, for FP regs. */
8971
8972int
8973first_fp_reg_to_save ()
8974{
8975 int first_reg;
8976
8977 /* Find lowest numbered live register. */
8978 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
8979 if (regs_ever_live[first_reg])
8980 break;
8981
8982 return first_reg;
8983}
00b960c7
AH
8984
8985/* Similar, for AltiVec regs. */
8986
8987static int
8988first_altivec_reg_to_save ()
8989{
8990 int i;
8991
8992 /* Stack frame remains as is unless we are in AltiVec ABI. */
8993 if (! TARGET_ALTIVEC_ABI)
8994 return LAST_ALTIVEC_REGNO + 1;
8995
8996 /* Find lowest numbered live register. */
8997 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
8998 if (regs_ever_live[i])
8999 break;
9000
9001 return i;
9002}
9003
9004/* Return a 32-bit mask of the AltiVec registers we need to set in
9005 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
9006 the 32-bit word is 0. */
9007
9008static unsigned int
9009compute_vrsave_mask ()
9010{
9011 unsigned int i, mask = 0;
9012
9013 /* First, find out if we use _any_ altivec registers. */
9014 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9015 if (regs_ever_live[i])
9016 mask |= ALTIVEC_REG_BIT (i);
9017
9018 if (mask == 0)
9019 return mask;
9020
9021 /* Next, add all registers that are call-clobbered. We do this
9022 because post-reload register optimizers such as regrename_optimize
9023 may choose to use them. They never change the register class
9024 chosen by reload, so cannot create new uses of altivec registers
9025 if there were none before, so the early exit above is safe. */
9026 /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow
9027 altivec registers not saved in the mask, which might well make the
9028 adjustments below more effective in eliding the save/restore of
9029 VRSAVE in small functions. */
9030 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9031 if (call_used_regs[i])
9032 mask |= ALTIVEC_REG_BIT (i);
9033
9034 /* Next, remove the argument registers from the set. These must
9035 be in the VRSAVE mask set by the caller, so we don't need to add
9036 them in again. More importantly, the mask we compute here is
9037 used to generate CLOBBERs in the set_vrsave insn, and we do not
9038 wish the argument registers to die. */
9039 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
9040 mask &= ~ALTIVEC_REG_BIT (i);
9041
9042 /* Similarly, remove the return value from the set. */
9043 {
9044 bool yes = false;
9045 diddle_return_value (is_altivec_return_reg, &yes);
9046 if (yes)
9047 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
9048 }
9049
9050 return mask;
9051}
9052
9053static void
9054is_altivec_return_reg (reg, xyes)
9055 rtx reg;
9056 void *xyes;
9057{
9058 bool *yes = (bool *) xyes;
9059 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
9060 *yes = true;
9061}
9062
4697a36c
MM
9063\f
9064/* Calculate the stack information for the current function. This is
9065 complicated by having two separate calling sequences, the AIX calling
9066 sequence and the V.4 calling sequence.
9067
592696dd 9068 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 9069 32-bit 64-bit
4697a36c 9070 SP----> +---------------------------------------+
a260abc9 9071 | back chain to caller | 0 0
4697a36c 9072 +---------------------------------------+
a260abc9 9073 | saved CR | 4 8 (8-11)
4697a36c 9074 +---------------------------------------+
a260abc9 9075 | saved LR | 8 16
4697a36c 9076 +---------------------------------------+
a260abc9 9077 | reserved for compilers | 12 24
4697a36c 9078 +---------------------------------------+
a260abc9 9079 | reserved for binders | 16 32
4697a36c 9080 +---------------------------------------+
a260abc9 9081 | saved TOC pointer | 20 40
4697a36c 9082 +---------------------------------------+
a260abc9 9083 | Parameter save area (P) | 24 48
4697a36c 9084 +---------------------------------------+
a260abc9 9085 | Alloca space (A) | 24+P etc.
802a0058 9086 +---------------------------------------+
a7df97e6 9087 | Local variable space (L) | 24+P+A
4697a36c 9088 +---------------------------------------+
a7df97e6 9089 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 9090 +---------------------------------------+
00b960c7
AH
9091 | Save area for AltiVec registers (W) | 24+P+A+L+X
9092 +---------------------------------------+
9093 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
9094 +---------------------------------------+
9095 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 9096 +---------------------------------------+
00b960c7
AH
9097 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
9098 +---------------------------------------+
9099 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
9100 +---------------------------------------+
9101 old SP->| back chain to caller's caller |
9102 +---------------------------------------+
9103
5376a30c
KR
9104 The required alignment for AIX configurations is two words (i.e., 8
9105 or 16 bytes).
9106
9107
4697a36c
MM
9108 V.4 stack frames look like:
9109
9110 SP----> +---------------------------------------+
9111 | back chain to caller | 0
9112 +---------------------------------------+
5eb387b8 9113 | caller's saved LR | 4
4697a36c
MM
9114 +---------------------------------------+
9115 | Parameter save area (P) | 8
9116 +---------------------------------------+
a7df97e6
MM
9117 | Alloca space (A) | 8+P
9118 +---------------------------------------+
9119 | Varargs save area (V) | 8+P+A
9120 +---------------------------------------+
9121 | Local variable space (L) | 8+P+A+V
9122 +---------------------------------------+
9123 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 9124 +---------------------------------------+
00b960c7
AH
9125 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
9126 +---------------------------------------+
9127 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
9128 +---------------------------------------+
9129 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
9130 +---------------------------------------+
a3170dc6
AH
9131 | SPE: area for 64-bit GP registers |
9132 +---------------------------------------+
9133 | SPE alignment padding |
9134 +---------------------------------------+
00b960c7 9135 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 9136 +---------------------------------------+
00b960c7 9137 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 9138 +---------------------------------------+
00b960c7 9139 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
9140 +---------------------------------------+
9141 old SP->| back chain to caller's caller |
9142 +---------------------------------------+
b6c9286a 9143
5376a30c
KR
9144 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
9145 given. (But note below and in sysv4.h that we require only 8 and
9146 may round up the size of our stack frame anyways. The historical
9147 reason is early versions of powerpc-linux which didn't properly
9148 align the stack at program startup. A happy side-effect is that
9149 -mno-eabi libraries can be used with -meabi programs.)
9150
5376a30c
KR
9151 The EABI configuration defaults to the V.4 layout, unless
9152 -mcall-aix is used, in which case the AIX layout is used. However,
9153 the stack alignment requirements may differ. If -mno-eabi is not
9154 given, the required stack alignment is 8 bytes; if -mno-eabi is
9155 given, the required alignment is 16 bytes. (But see V.4 comment
9156 above.) */
4697a36c 9157
61b2fbe7
MM
9158#ifndef ABI_STACK_BOUNDARY
9159#define ABI_STACK_BOUNDARY STACK_BOUNDARY
9160#endif
9161
4697a36c
MM
9162rs6000_stack_t *
9163rs6000_stack_info ()
9164{
9165 static rs6000_stack_t info, zero_info;
9166 rs6000_stack_t *info_ptr = &info;
9ebbca7d 9167 int reg_size = TARGET_POWERPC64 ? 8 : 4;
24d304eb 9168 enum rs6000_abi abi;
83720594 9169 int ehrd_size;
b6c9286a 9170 int total_raw_size;
4697a36c 9171
a4f6c312 9172 /* Zero all fields portably. */
4697a36c
MM
9173 info = zero_info;
9174
c19de7aa
AH
9175 if (TARGET_SPE)
9176 {
9177 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
9178 if (cfun->machine->insn_chain_scanned_p == 0)
9179 {
9180 cfun->machine->insn_chain_scanned_p = 1;
9181 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
9182 }
c19de7aa
AH
9183 }
9184
a4f6c312 9185 /* Select which calling sequence. */
b6c9286a 9186 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 9187
a4f6c312 9188 /* Calculate which registers need to be saved & save area size. */
4697a36c 9189 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 9190 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 9191 even if it currently looks like we won't. */
2bfcf297 9192 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
f607bc57
ZW
9193 || (flag_pic == 1 && abi == ABI_V4)
9194 || (flag_pic && abi == ABI_DARWIN))
1db02437
FS
9195 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
9196 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
9197 else
9198 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 9199
a3170dc6
AH
9200 /* For the SPE, we have an additional upper 32-bits on each GPR.
9201 Ideally we should save the entire 64-bits only when the upper
9202 half is used in SIMD instructions. Since we only record
9203 registers live (not the size they are used in), this proves
9204 difficult because we'd have to traverse the instruction chain at
9205 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
9206 so we opt to save the GPRs in 64-bits always if but one register
9207 gets used in 64-bits. Otherwise, all the registers in the frame
9208 get saved in 32-bits.
a3170dc6 9209
c19de7aa 9210 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 9211 traditional GP save area will be empty. */
c19de7aa 9212 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9213 info_ptr->gp_size = 0;
9214
4697a36c
MM
9215 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
9216 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
9217
00b960c7
AH
9218 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
9219 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
9220 - info_ptr->first_altivec_reg_save);
9221
592696dd 9222 /* Does this function call anything? */
71f123ca
FS
9223 info_ptr->calls_p = (! current_function_is_leaf
9224 || cfun->machine->ra_needs_full_frame);
b6c9286a 9225
a4f6c312 9226 /* Determine if we need to save the link register. */
71f123ca 9227 if (rs6000_ra_ever_killed ()
70f4f91c 9228 || (DEFAULT_ABI == ABI_AIX && current_function_profile)
4697a36c
MM
9229#ifdef TARGET_RELOCATABLE
9230 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
9231#endif
9232 || (info_ptr->first_fp_reg_save != 64
9233 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 9234 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
24d304eb 9235 || (abi == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
9236 || (DEFAULT_ABI == ABI_DARWIN
9237 && flag_pic
9238 && current_function_uses_pic_offset_table)
4697a36c
MM
9239 || info_ptr->calls_p)
9240 {
9241 info_ptr->lr_save_p = 1;
9ebbca7d 9242 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
9243 }
9244
9ebbca7d
GK
9245 /* Determine if we need to save the condition code registers. */
9246 if (regs_ever_live[CR2_REGNO]
9247 || regs_ever_live[CR3_REGNO]
9248 || regs_ever_live[CR4_REGNO])
4697a36c
MM
9249 {
9250 info_ptr->cr_save_p = 1;
f607bc57 9251 if (abi == ABI_V4)
4697a36c
MM
9252 info_ptr->cr_size = reg_size;
9253 }
9254
83720594
RH
9255 /* If the current function calls __builtin_eh_return, then we need
9256 to allocate stack space for registers that will hold data for
9257 the exception handler. */
9258 if (current_function_calls_eh_return)
9259 {
9260 unsigned int i;
9261 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
9262 continue;
a3170dc6
AH
9263
9264 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
9265 ehrd_size = i * (TARGET_SPE_ABI
9266 && info_ptr->spe_64bit_regs_used != 0
9267 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
9268 }
9269 else
9270 ehrd_size = 0;
9271
592696dd 9272 /* Determine various sizes. */
4697a36c
MM
9273 info_ptr->reg_size = reg_size;
9274 info_ptr->fixed_size = RS6000_SAVE_AREA;
9275 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 9276 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
9277 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
9278 8);
00b960c7 9279
c19de7aa 9280 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9281 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
9282 else
9283 info_ptr->spe_gp_size = 0;
9284
08b57fb3 9285 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE)
00b960c7
AH
9286 {
9287 info_ptr->vrsave_mask = compute_vrsave_mask ();
9288 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
9289 }
9290 else
9291 {
9292 info_ptr->vrsave_mask = 0;
9293 info_ptr->vrsave_size = 0;
9294 }
b6c9286a 9295
592696dd 9296 /* Calculate the offsets. */
24d304eb 9297 switch (abi)
4697a36c 9298 {
b6c9286a 9299 case ABI_NONE:
24d304eb 9300 default:
b6c9286a
MM
9301 abort ();
9302
9303 case ABI_AIX:
9304 case ABI_AIX_NODESC:
ee890fe2 9305 case ABI_DARWIN:
b6c9286a
MM
9306 info_ptr->fp_save_offset = - info_ptr->fp_size;
9307 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
9308
9309 if (TARGET_ALTIVEC_ABI)
9310 {
9311 info_ptr->vrsave_save_offset
9312 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
9313
9314 /* Align stack so vector save area is on a quadword boundary. */
9315 if (info_ptr->altivec_size != 0)
9316 info_ptr->altivec_padding_size
9317 = 16 - (-info_ptr->vrsave_save_offset % 16);
9318 else
9319 info_ptr->altivec_padding_size = 0;
9320
9321 info_ptr->altivec_save_offset
9322 = info_ptr->vrsave_save_offset
9323 - info_ptr->altivec_padding_size
9324 - info_ptr->altivec_size;
9325
9326 /* Adjust for AltiVec case. */
9327 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
9328 }
9329 else
9330 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
9331 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
9332 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
9333 break;
9334
9335 case ABI_V4:
b6c9286a
MM
9336 info_ptr->fp_save_offset = - info_ptr->fp_size;
9337 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 9338 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 9339
c19de7aa 9340 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9341 {
9342 /* Align stack so SPE GPR save area is aligned on a
9343 double-word boundary. */
9344 if (info_ptr->spe_gp_size != 0)
9345 info_ptr->spe_padding_size
9346 = 8 - (-info_ptr->cr_save_offset % 8);
9347 else
9348 info_ptr->spe_padding_size = 0;
9349
9350 info_ptr->spe_gp_save_offset
9351 = info_ptr->cr_save_offset
9352 - info_ptr->spe_padding_size
9353 - info_ptr->spe_gp_size;
9354
9355 /* Adjust for SPE case. */
9356 info_ptr->toc_save_offset
9357 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
9358 }
9359 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
9360 {
9361 info_ptr->vrsave_save_offset
9362 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
9363
9364 /* Align stack so vector save area is on a quadword boundary. */
9365 if (info_ptr->altivec_size != 0)
9366 info_ptr->altivec_padding_size
9367 = 16 - (-info_ptr->vrsave_save_offset % 16);
9368 else
9369 info_ptr->altivec_padding_size = 0;
9370
9371 info_ptr->altivec_save_offset
9372 = info_ptr->vrsave_save_offset
9373 - info_ptr->altivec_padding_size
9374 - info_ptr->altivec_size;
9375
9376 /* Adjust for AltiVec case. */
9377 info_ptr->toc_save_offset
9378 = info_ptr->altivec_save_offset - info_ptr->toc_size;
9379 }
9380 else
9381 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 9382 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
9383 info_ptr->lr_save_offset = reg_size;
9384 break;
4697a36c
MM
9385 }
9386
00b960c7
AH
9387 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
9388 + info_ptr->gp_size
9389 + info_ptr->altivec_size
9390 + info_ptr->altivec_padding_size
9391 + info_ptr->vrsave_size
a3170dc6
AH
9392 + info_ptr->spe_gp_size
9393 + info_ptr->spe_padding_size
00b960c7
AH
9394 + ehrd_size
9395 + info_ptr->cr_size
9396 + info_ptr->lr_size
9397 + info_ptr->vrsave_size
9398 + info_ptr->toc_size,
9399 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
9400 ? 16 : 8);
9401
ff381587
MM
9402 total_raw_size = (info_ptr->vars_size
9403 + info_ptr->parm_size
ff381587
MM
9404 + info_ptr->save_size
9405 + info_ptr->varargs_size
9406 + info_ptr->fixed_size);
9407
a4f6c312
SS
9408 info_ptr->total_size =
9409 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
9410
9411 /* Determine if we need to allocate any stack frame:
9412
a4f6c312
SS
9413 For AIX we need to push the stack if a frame pointer is needed
9414 (because the stack might be dynamically adjusted), if we are
9415 debugging, if we make calls, or if the sum of fp_save, gp_save,
9416 and local variables are more than the space needed to save all
9417 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
9418 + 18*8 = 288 (GPR13 reserved).
ff381587 9419
a4f6c312
SS
9420 For V.4 we don't have the stack cushion that AIX uses, but assume
9421 that the debugger can handle stackless frames. */
ff381587
MM
9422
9423 if (info_ptr->calls_p)
9424 info_ptr->push_p = 1;
9425
f607bc57 9426 else if (abi == ABI_V4)
e72247f4 9427 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587
MM
9428
9429 else
9430 info_ptr->push_p = (frame_pointer_needed
ee890fe2 9431 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
ff381587 9432 || ((total_raw_size - info_ptr->fixed_size)
bfc79d3b 9433 > (TARGET_32BIT ? 220 : 288)));
ff381587 9434
a4f6c312 9435 /* Zero offsets if we're not saving those registers. */
8dda1a21 9436 if (info_ptr->fp_size == 0)
4697a36c
MM
9437 info_ptr->fp_save_offset = 0;
9438
8dda1a21 9439 if (info_ptr->gp_size == 0)
4697a36c
MM
9440 info_ptr->gp_save_offset = 0;
9441
00b960c7
AH
9442 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
9443 info_ptr->altivec_save_offset = 0;
9444
9445 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
9446 info_ptr->vrsave_save_offset = 0;
9447
c19de7aa
AH
9448 if (! TARGET_SPE_ABI
9449 || info_ptr->spe_64bit_regs_used == 0
9450 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
9451 info_ptr->spe_gp_save_offset = 0;
9452
c81fc13e 9453 if (! info_ptr->lr_save_p)
4697a36c
MM
9454 info_ptr->lr_save_offset = 0;
9455
c81fc13e 9456 if (! info_ptr->cr_save_p)
4697a36c
MM
9457 info_ptr->cr_save_offset = 0;
9458
c81fc13e 9459 if (! info_ptr->toc_save_p)
b6c9286a
MM
9460 info_ptr->toc_save_offset = 0;
9461
4697a36c
MM
9462 return info_ptr;
9463}
9464
c19de7aa
AH
9465/* Return true if the current function uses any GPRs in 64-bit SIMD
9466 mode. */
9467
9468static bool
9469spe_func_has_64bit_regs_p ()
9470{
9471 rtx insns, insn;
9472
9473 /* Functions that save and restore all the call-saved registers will
9474 need to save/restore the registers in 64-bits. */
9475 if (current_function_calls_eh_return
9476 || current_function_calls_setjmp
9477 || current_function_has_nonlocal_goto)
9478 return true;
9479
9480 insns = get_insns ();
9481
9482 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
9483 {
9484 if (INSN_P (insn))
9485 {
9486 rtx i;
9487
9488 i = PATTERN (insn);
9489 if (GET_CODE (i) == SET
9490 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
9491 return true;
9492 }
9493 }
9494
9495 return false;
9496}
9497
4697a36c
MM
9498void
9499debug_stack_info (info)
9500 rs6000_stack_t *info;
9878760c 9501{
d330fd93 9502 const char *abi_string;
24d304eb 9503
c81fc13e 9504 if (! info)
4697a36c
MM
9505 info = rs6000_stack_info ();
9506
9507 fprintf (stderr, "\nStack information for function %s:\n",
9508 ((current_function_decl && DECL_NAME (current_function_decl))
9509 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
9510 : "<unknown>"));
9511
24d304eb
RK
9512 switch (info->abi)
9513 {
b6c9286a
MM
9514 default: abi_string = "Unknown"; break;
9515 case ABI_NONE: abi_string = "NONE"; break;
f607bc57 9516 case ABI_AIX:
b6c9286a 9517 case ABI_AIX_NODESC: abi_string = "AIX"; break;
ee890fe2 9518 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 9519 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
9520 }
9521
9522 fprintf (stderr, "\tABI = %5s\n", abi_string);
9523
00b960c7
AH
9524 if (TARGET_ALTIVEC_ABI)
9525 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
9526
a3170dc6
AH
9527 if (TARGET_SPE_ABI)
9528 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
9529
4697a36c
MM
9530 if (info->first_gp_reg_save != 32)
9531 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
9532
9533 if (info->first_fp_reg_save != 64)
9534 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 9535
00b960c7
AH
9536 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
9537 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
9538 info->first_altivec_reg_save);
9539
4697a36c
MM
9540 if (info->lr_save_p)
9541 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 9542
4697a36c
MM
9543 if (info->cr_save_p)
9544 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
9545
b6c9286a
MM
9546 if (info->toc_save_p)
9547 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
9548
00b960c7
AH
9549 if (info->vrsave_mask)
9550 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
9551
4697a36c
MM
9552 if (info->push_p)
9553 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
9554
9555 if (info->calls_p)
9556 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
9557
4697a36c
MM
9558 if (info->gp_save_offset)
9559 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
9560
9561 if (info->fp_save_offset)
9562 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
9563
00b960c7
AH
9564 if (info->altivec_save_offset)
9565 fprintf (stderr, "\taltivec_save_offset = %5d\n",
9566 info->altivec_save_offset);
9567
a3170dc6
AH
9568 if (info->spe_gp_save_offset)
9569 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
9570 info->spe_gp_save_offset);
9571
00b960c7
AH
9572 if (info->vrsave_save_offset)
9573 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
9574 info->vrsave_save_offset);
9575
4697a36c
MM
9576 if (info->lr_save_offset)
9577 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
9578
9579 if (info->cr_save_offset)
9580 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
9581
b6c9286a
MM
9582 if (info->toc_save_offset)
9583 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
9584
4697a36c
MM
9585 if (info->varargs_save_offset)
9586 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
9587
9588 if (info->total_size)
9589 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
9590
9591 if (info->varargs_size)
9592 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
9593
9594 if (info->vars_size)
9595 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
9596
9597 if (info->parm_size)
9598 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
9599
9600 if (info->fixed_size)
9601 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
9602
9603 if (info->gp_size)
9604 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
9605
a3170dc6
AH
9606 if (info->spe_gp_size)
9607 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
9608
4697a36c
MM
9609 if (info->fp_size)
9610 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
9611
00b960c7
AH
9612 if (info->altivec_size)
9613 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
9614
9615 if (info->vrsave_size)
9616 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
9617
9618 if (info->altivec_padding_size)
9619 fprintf (stderr, "\taltivec_padding_size= %5d\n",
9620 info->altivec_padding_size);
9621
a3170dc6
AH
9622 if (info->spe_padding_size)
9623 fprintf (stderr, "\tspe_padding_size = %5d\n",
9624 info->spe_padding_size);
9625
a4f6c312 9626 if (info->lr_size)
ed947a96 9627 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 9628
4697a36c
MM
9629 if (info->cr_size)
9630 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
9631
a4f6c312 9632 if (info->toc_size)
b6c9286a
MM
9633 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
9634
4697a36c
MM
9635 if (info->save_size)
9636 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
9637
9638 if (info->reg_size != 4)
9639 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
9640
9641 fprintf (stderr, "\n");
9878760c 9642}
71f123ca
FS
9643
9644rtx
9645rs6000_return_addr (count, frame)
9646 int count;
9647 rtx frame;
9648{
a4f6c312
SS
9649 /* Currently we don't optimize very well between prolog and body
9650 code and for PIC code the code can be actually quite bad, so
9651 don't try to be too clever here. */
f1384257 9652 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
9653 {
9654 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
9655
9656 return
9657 gen_rtx_MEM
9658 (Pmode,
9659 memory_address
9660 (Pmode,
9661 plus_constant (copy_to_reg
9662 (gen_rtx_MEM (Pmode,
9663 memory_address (Pmode, frame))),
9664 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
9665 }
9666
9e2f7ec7 9667 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
9668}
9669
5e1bf043
DJ
9670/* Say whether a function is a candidate for sibcall handling or not.
9671 We do not allow indirect calls to be optimized into sibling calls.
9672 Also, we can't do it if there are any vector parameters; there's
9673 nowhere to put the VRsave code so it works; note that functions with
9674 vector parameters are required to have a prototype, so the argument
9675 type info must be available here. (The tail recursion case can work
9676 with vector parameters, but there's no way to distinguish here.) */
4977bab6
ZW
9677static bool
9678rs6000_function_ok_for_sibcall (decl, exp)
9679 tree decl;
9680 tree exp ATTRIBUTE_UNUSED;
5e1bf043
DJ
9681{
9682 tree type;
4977bab6 9683 if (decl)
5e1bf043
DJ
9684 {
9685 if (TARGET_ALTIVEC_VRSAVE)
9686 {
4977bab6 9687 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
9688 type; type = TREE_CHAIN (type))
9689 {
c15b529f 9690 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 9691 return false;
5e1bf043
DJ
9692 }
9693 }
9694 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 9695 || (*targetm.binds_local_p) (decl))
2bcc50d0 9696 {
4977bab6 9697 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
9698
9699 if (!lookup_attribute ("longcall", attr_list)
9700 || lookup_attribute ("shortcall", attr_list))
4977bab6 9701 return true;
2bcc50d0 9702 }
5e1bf043 9703 }
4977bab6 9704 return false;
5e1bf043
DJ
9705}
9706
71f123ca
FS
9707static int
9708rs6000_ra_ever_killed ()
9709{
9710 rtx top;
5e1bf043
DJ
9711 rtx reg;
9712 rtx insn;
71f123ca 9713
3961e8fe
RH
9714 /* Irritatingly, there are two kinds of thunks -- those created with
9715 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
9716 through the regular part of the compiler. This is a very hacky
9717 way to tell them apart. */
9718 if (current_function_is_thunk && !no_new_pseudos)
71f123ca 9719 return 0;
eb0424da 9720
36f7e964
AH
9721 /* regs_ever_live has LR marked as used if any sibcalls are present,
9722 but this should not force saving and restoring in the
9723 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
9724 clobbers LR, so that is inappropriate. */
9725
5e1bf043
DJ
9726 /* Also, the prologue can generate a store into LR that
9727 doesn't really count, like this:
36f7e964 9728
5e1bf043
DJ
9729 move LR->R0
9730 bcl to set PIC register
9731 move LR->R31
9732 move R0->LR
36f7e964
AH
9733
9734 When we're called from the epilogue, we need to avoid counting
9735 this as a store. */
5e1bf043 9736
71f123ca
FS
9737 push_topmost_sequence ();
9738 top = get_insns ();
9739 pop_topmost_sequence ();
5e1bf043 9740 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 9741
5e1bf043
DJ
9742 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
9743 {
9744 if (INSN_P (insn))
9745 {
9746 if (FIND_REG_INC_NOTE (insn, reg))
9747 return 1;
9748 else if (GET_CODE (insn) == CALL_INSN
c15b529f 9749 && !SIBLING_CALL_P (insn))
5e1bf043 9750 return 1;
36f7e964
AH
9751 else if (set_of (reg, insn) != NULL_RTX
9752 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
9753 return 1;
9754 }
9755 }
9756 return 0;
71f123ca 9757}
4697a36c 9758\f
8cd8f856
GK
9759/* Add a REG_MAYBE_DEAD note to the insn. */
9760static void
9761rs6000_maybe_dead (insn)
9762 rtx insn;
9763{
9764 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
9765 const0_rtx,
9766 REG_NOTES (insn));
9767}
9768
9ebbca7d 9769/* Emit instructions needed to load the TOC register.
c7ca610e 9770 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 9771 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
9772
9773void
9ebbca7d
GK
9774rs6000_emit_load_toc_table (fromprolog)
9775 int fromprolog;
c7ca610e 9776{
9ebbca7d 9777 rtx dest;
1db02437 9778 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 9779
20b71b17
AM
9780 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
9781 {
9782 rtx temp = (fromprolog
9783 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9784 : gen_reg_rtx (Pmode));
9785 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
9786 rs6000_maybe_dead (emit_move_insn (dest, temp));
9787 }
9788 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
9789 {
9790 char buf[30];
9791 rtx tempLR = (fromprolog
9792 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9793 : gen_reg_rtx (Pmode));
9794 rtx temp0 = (fromprolog
9795 ? gen_rtx_REG (Pmode, 0)
9796 : gen_reg_rtx (Pmode));
9797 rtx symF;
9798
9799 /* possibly create the toc section */
9800 if (! toc_initialized)
38c1f2d7 9801 {
20b71b17
AM
9802 toc_section ();
9803 function_section (current_function_decl);
38c1f2d7 9804 }
9ebbca7d 9805
20b71b17
AM
9806 if (fromprolog)
9807 {
9808 rtx symL;
38c1f2d7 9809
20b71b17
AM
9810 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
9811 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 9812
20b71b17
AM
9813 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
9814 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9815
9816 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
9817 symF)));
9818 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9819 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
9820 symL,
9821 symF)));
9ebbca7d
GK
9822 }
9823 else
20b71b17
AM
9824 {
9825 rtx tocsym;
9826 static int reload_toc_labelno = 0;
9827
9828 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
9829
9830 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
9831 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9832
9833 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
9834 symF,
9835 tocsym)));
9836 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9837 rs6000_maybe_dead (emit_move_insn (temp0,
9838 gen_rtx_MEM (Pmode, dest)));
9839 }
9840 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
9ebbca7d 9841 }
20b71b17
AM
9842 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
9843 {
9844 /* This is for AIX code running in non-PIC ELF32. */
9845 char buf[30];
9846 rtx realsym;
9847 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
9848 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9849
9850 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
9851 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
9852 }
9853 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
9854 {
9855 if (TARGET_32BIT)
20b71b17 9856 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
9ebbca7d 9857 else
20b71b17 9858 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
9ebbca7d 9859 }
20b71b17
AM
9860 else
9861 abort ();
9ebbca7d
GK
9862}
9863
9864int
9865get_TOC_alias_set ()
9866{
9867 static int set = -1;
9868 if (set == -1)
9869 set = new_alias_set ();
9870 return set;
9871}
9872
9873/* This retuns nonzero if the current function uses the TOC. This is
9874 determined by the presence of (unspec ... 7), which is generated by
9875 the various load_toc_* patterns. */
a4f6c312 9876
9ebbca7d
GK
9877int
9878uses_TOC ()
9879{
9880 rtx insn;
38c1f2d7 9881
9ebbca7d 9882 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2c3c49de 9883 if (INSN_P (insn))
9ebbca7d
GK
9884 {
9885 rtx pat = PATTERN (insn);
9886 int i;
9887
8cd8f856 9888 if (GET_CODE (pat) == PARALLEL)
9ebbca7d
GK
9889 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
9890 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
9891 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
9892 return 1;
38c1f2d7 9893 }
9ebbca7d
GK
9894 return 0;
9895}
38c1f2d7 9896
9ebbca7d 9897rtx
a4f6c312 9898create_TOC_reference (symbol)
9ebbca7d
GK
9899 rtx symbol;
9900{
a8a05998
ZW
9901 return gen_rtx_PLUS (Pmode,
9902 gen_rtx_REG (Pmode, TOC_REGISTER),
9903 gen_rtx_CONST (Pmode,
9904 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 9905 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 9906}
38c1f2d7 9907
9ebbca7d
GK
9908#if TARGET_AIX
9909/* __throw will restore its own return address to be the same as the
9910 return address of the function that the throw is being made to.
9911 This is unfortunate, because we want to check the original
9912 return address to see if we need to restore the TOC.
9913 So we have to squirrel it away here.
9914 This is used only in compiling __throw and __rethrow.
c7ca610e 9915
9ebbca7d
GK
9916 Most of this code should be removed by CSE. */
9917static rtx insn_after_throw;
c7ca610e 9918
a4f6c312 9919/* This does the saving... */
9ebbca7d
GK
9920void
9921rs6000_aix_emit_builtin_unwind_init ()
9922{
9923 rtx mem;
9924 rtx stack_top = gen_reg_rtx (Pmode);
9925 rtx opcode_addr = gen_reg_rtx (Pmode);
9926
9927 insn_after_throw = gen_reg_rtx (SImode);
9928
9929 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
9930 emit_move_insn (stack_top, mem);
9931
9932 mem = gen_rtx_MEM (Pmode,
9933 gen_rtx_PLUS (Pmode, stack_top,
9934 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
9935 emit_move_insn (opcode_addr, mem);
9936 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
c7ca610e
RK
9937}
9938
a4f6c312
SS
9939/* Emit insns to _restore_ the TOC register, at runtime (specifically
9940 in _eh.o). Only used on AIX.
9ebbca7d
GK
9941
9942 The idea is that on AIX, function calls look like this:
9943 bl somefunction-trampoline
9944 lwz r2,20(sp)
9945
a4f6c312 9946 and later,
9ebbca7d
GK
9947 somefunction-trampoline:
9948 stw r2,20(sp)
9949 ... load function address in the count register ...
9950 bctr
9951 or like this, if the linker determines that this is not a cross-module call
9952 and so the TOC need not be restored:
9953 bl somefunction
9954 nop
9955 or like this, if the compiler could determine that this is not a
9956 cross-module call:
9957 bl somefunction
9958 now, the tricky bit here is that register 2 is saved and restored
9959 by the _linker_, so we can't readily generate debugging information
9960 for it. So we need to go back up the call chain looking at the
9961 insns at return addresses to see which calls saved the TOC register
9962 and so see where it gets restored from.
9963
9964 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
9965 just before the actual epilogue.
9966
9967 On the bright side, this incurs no space or time overhead unless an
9968 exception is thrown, except for the extra code in libgcc.a.
9969
9970 The parameter STACKSIZE is a register containing (at runtime)
9971 the amount to be popped off the stack in addition to the stack frame
9972 of this routine (which will be __throw or __rethrow, and so is
9973 guaranteed to have a stack frame). */
a4f6c312 9974
9ebbca7d
GK
9975void
9976rs6000_emit_eh_toc_restore (stacksize)
9977 rtx stacksize;
9978{
9979 rtx top_of_stack;
9980 rtx bottom_of_stack = gen_reg_rtx (Pmode);
9981 rtx tocompare = gen_reg_rtx (SImode);
9982 rtx opcode = gen_reg_rtx (SImode);
9983 rtx opcode_addr = gen_reg_rtx (Pmode);
9984 rtx mem;
9985 rtx loop_start = gen_label_rtx ();
9986 rtx no_toc_restore_needed = gen_label_rtx ();
9987 rtx loop_exit = gen_label_rtx ();
9988
9989 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
ba4828e0 9990 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
9991 emit_move_insn (bottom_of_stack, mem);
9992
9993 top_of_stack = expand_binop (Pmode, add_optab,
9994 bottom_of_stack, stacksize,
9995 NULL_RTX, 1, OPTAB_WIDEN);
9996
2496c7bd
LB
9997 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
9998 : 0xE8410028, SImode));
9ebbca7d
GK
9999
10000 if (insn_after_throw == NULL_RTX)
a4f6c312 10001 abort ();
9ebbca7d
GK
10002 emit_move_insn (opcode, insn_after_throw);
10003
6496a589 10004 emit_note (NULL, NOTE_INSN_LOOP_BEG);
9ebbca7d
GK
10005 emit_label (loop_start);
10006
10007 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
06f4e019 10008 SImode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
10009 no_toc_restore_needed);
10010
10011 mem = gen_rtx_MEM (Pmode,
10012 gen_rtx_PLUS (Pmode, bottom_of_stack,
10013 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
10014 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
10015
10016 emit_label (no_toc_restore_needed);
10017 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
06f4e019 10018 Pmode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
10019 loop_exit);
10020
10021 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
ba4828e0 10022 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10023 emit_move_insn (bottom_of_stack, mem);
10024
10025 mem = gen_rtx_MEM (Pmode,
10026 gen_rtx_PLUS (Pmode, bottom_of_stack,
10027 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
10028 emit_move_insn (opcode_addr, mem);
10029 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
10030
6496a589 10031 emit_note (NULL, NOTE_INSN_LOOP_CONT);
9ebbca7d 10032 emit_jump (loop_start);
6496a589 10033 emit_note (NULL, NOTE_INSN_LOOP_END);
9ebbca7d
GK
10034 emit_label (loop_exit);
10035}
10036#endif /* TARGET_AIX */
38c1f2d7 10037\f
ba4828e0
RK
10038/* This ties together stack memory (MEM with an alias set of
10039 rs6000_sr_alias_set) and the change to the stack pointer. */
10040
9ebbca7d
GK
10041static void
10042rs6000_emit_stack_tie ()
10043{
ba4828e0
RK
10044 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
10045
10046 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10047 emit_insn (gen_stack_tie (mem));
10048}
38c1f2d7 10049
9ebbca7d
GK
10050/* Emit the correct code for allocating stack space, as insns.
10051 If COPY_R12, make sure a copy of the old frame is left in r12.
10052 The generated code may use hard register 0 as a temporary. */
10053
10054static void
10055rs6000_emit_allocate_stack (size, copy_r12)
10056 HOST_WIDE_INT size;
38c1f2d7
MM
10057 int copy_r12;
10058{
9ebbca7d
GK
10059 rtx insn;
10060 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10061 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
10062 rtx todec = GEN_INT (-size);
a157febd
GK
10063
10064 if (current_function_limit_stack)
10065 {
10066 if (REG_P (stack_limit_rtx)
10067 && REGNO (stack_limit_rtx) > 1
10068 && REGNO (stack_limit_rtx) <= 31)
10069 {
5b71a4e7 10070 emit_insn (TARGET_32BIT
9ebbca7d
GK
10071 ? gen_addsi3 (tmp_reg,
10072 stack_limit_rtx,
10073 GEN_INT (size))
10074 : gen_adddi3 (tmp_reg,
10075 stack_limit_rtx,
10076 GEN_INT (size)));
5b71a4e7 10077
9ebbca7d
GK
10078 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10079 const0_rtx));
a157febd
GK
10080 }
10081 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 10082 && TARGET_32BIT
f607bc57 10083 && DEFAULT_ABI == ABI_V4)
a157febd 10084 {
9ebbca7d
GK
10085 rtx toload = gen_rtx_CONST (VOIDmode,
10086 gen_rtx_PLUS (Pmode,
10087 stack_limit_rtx,
10088 GEN_INT (size)));
5b71a4e7 10089
9ebbca7d
GK
10090 emit_insn (gen_elf_high (tmp_reg, toload));
10091 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
10092 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10093 const0_rtx));
a157febd
GK
10094 }
10095 else
10096 warning ("stack limit expression is not supported");
10097 }
10098
9ebbca7d
GK
10099 if (copy_r12 || ! TARGET_UPDATE)
10100 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
10101
38c1f2d7
MM
10102 if (TARGET_UPDATE)
10103 {
9ebbca7d 10104 if (size > 32767)
38c1f2d7 10105 {
9ebbca7d
GK
10106 /* Need a note here so that try_split doesn't get confused. */
10107 if (get_last_insn() == NULL_RTX)
10108 emit_note (0, NOTE_INSN_DELETED);
10109 insn = emit_move_insn (tmp_reg, todec);
10110 try_split (PATTERN (insn), insn, 0);
10111 todec = tmp_reg;
38c1f2d7 10112 }
5b71a4e7
DE
10113
10114 insn = emit_insn (TARGET_32BIT
10115 ? gen_movsi_update (stack_reg, stack_reg,
10116 todec, stack_reg)
10117 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 10118 todec, stack_reg));
38c1f2d7
MM
10119 }
10120 else
10121 {
5b71a4e7
DE
10122 insn = emit_insn (TARGET_32BIT
10123 ? gen_addsi3 (stack_reg, stack_reg, todec)
10124 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
10125 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
10126 gen_rtx_REG (Pmode, 12));
10127 }
5b71a4e7 10128
9ebbca7d
GK
10129 RTX_FRAME_RELATED_P (insn) = 1;
10130 REG_NOTES (insn) =
10131 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10132 gen_rtx_SET (VOIDmode, stack_reg,
10133 gen_rtx_PLUS (Pmode, stack_reg,
10134 GEN_INT (-size))),
10135 REG_NOTES (insn));
10136}
10137
a4f6c312
SS
10138/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
10139 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
10140 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
10141 deduce these equivalences by itself so it wasn't necessary to hold
10142 its hand so much. */
9ebbca7d
GK
10143
10144static void
10145rs6000_frame_related (insn, reg, val, reg2, rreg)
10146 rtx insn;
10147 rtx reg;
10148 HOST_WIDE_INT val;
10149 rtx reg2;
10150 rtx rreg;
10151{
10152 rtx real, temp;
10153
e56c4463
JL
10154 /* copy_rtx will not make unique copies of registers, so we need to
10155 ensure we don't have unwanted sharing here. */
10156 if (reg == reg2)
10157 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10158
10159 if (reg == rreg)
10160 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10161
9ebbca7d
GK
10162 real = copy_rtx (PATTERN (insn));
10163
89e7058f
AH
10164 if (reg2 != NULL_RTX)
10165 real = replace_rtx (real, reg2, rreg);
10166
9ebbca7d
GK
10167 real = replace_rtx (real, reg,
10168 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
10169 STACK_POINTER_REGNUM),
10170 GEN_INT (val)));
10171
10172 /* We expect that 'real' is either a SET or a PARALLEL containing
10173 SETs (and possibly other stuff). In a PARALLEL, all the SETs
10174 are important so they all have to be marked RTX_FRAME_RELATED_P. */
10175
10176 if (GET_CODE (real) == SET)
10177 {
10178 rtx set = real;
10179
10180 temp = simplify_rtx (SET_SRC (set));
10181 if (temp)
10182 SET_SRC (set) = temp;
10183 temp = simplify_rtx (SET_DEST (set));
10184 if (temp)
10185 SET_DEST (set) = temp;
10186 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 10187 {
9ebbca7d
GK
10188 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10189 if (temp)
10190 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 10191 }
38c1f2d7 10192 }
9ebbca7d
GK
10193 else if (GET_CODE (real) == PARALLEL)
10194 {
10195 int i;
10196 for (i = 0; i < XVECLEN (real, 0); i++)
10197 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
10198 {
10199 rtx set = XVECEXP (real, 0, i);
10200
10201 temp = simplify_rtx (SET_SRC (set));
10202 if (temp)
10203 SET_SRC (set) = temp;
10204 temp = simplify_rtx (SET_DEST (set));
10205 if (temp)
10206 SET_DEST (set) = temp;
10207 if (GET_CODE (SET_DEST (set)) == MEM)
10208 {
10209 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10210 if (temp)
10211 XEXP (SET_DEST (set), 0) = temp;
10212 }
10213 RTX_FRAME_RELATED_P (set) = 1;
10214 }
10215 }
10216 else
a4f6c312 10217 abort ();
c19de7aa
AH
10218
10219 if (TARGET_SPE)
10220 real = spe_synthesize_frame_save (real);
10221
9ebbca7d
GK
10222 RTX_FRAME_RELATED_P (insn) = 1;
10223 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10224 real,
10225 REG_NOTES (insn));
38c1f2d7
MM
10226}
10227
c19de7aa
AH
10228/* Given an SPE frame note, return a PARALLEL of SETs with the
10229 original note, plus a synthetic register save. */
10230
10231static rtx
10232spe_synthesize_frame_save (real)
10233 rtx real;
10234{
10235 rtx synth, offset, reg, real2;
10236
10237 if (GET_CODE (real) != SET
10238 || GET_MODE (SET_SRC (real)) != V2SImode)
10239 return real;
10240
10241 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
10242 frame related note. The parallel contains a set of the register
41f3a930 10243 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
10244 This is so we can differentiate between 64-bit and 32-bit saves.
10245 Words cannot describe this nastiness. */
10246
10247 if (GET_CODE (SET_DEST (real)) != MEM
10248 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
10249 || GET_CODE (SET_SRC (real)) != REG)
10250 abort ();
10251
10252 /* Transform:
10253 (set (mem (plus (reg x) (const y)))
10254 (reg z))
10255 into:
10256 (set (mem (plus (reg x) (const y+4)))
41f3a930 10257 (reg z+1200))
c19de7aa
AH
10258 */
10259
10260 real2 = copy_rtx (real);
10261 PUT_MODE (SET_DEST (real2), SImode);
10262 reg = SET_SRC (real2);
10263 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
10264 synth = copy_rtx (real2);
10265
10266 if (BYTES_BIG_ENDIAN)
10267 {
10268 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
10269 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
10270 }
10271
10272 reg = SET_SRC (synth);
41f3a930 10273
c19de7aa 10274 synth = replace_rtx (synth, reg,
41f3a930 10275 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
10276
10277 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
10278 synth = replace_rtx (synth, offset,
10279 GEN_INT (INTVAL (offset)
10280 + (BYTES_BIG_ENDIAN ? 0 : 4)));
10281
10282 RTX_FRAME_RELATED_P (synth) = 1;
10283 RTX_FRAME_RELATED_P (real2) = 1;
10284 if (BYTES_BIG_ENDIAN)
10285 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
10286 else
10287 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
10288
10289 return real;
10290}
10291
00b960c7
AH
10292/* Returns an insn that has a vrsave set operation with the
10293 appropriate CLOBBERs. */
10294
10295static rtx
9aa86737 10296generate_set_vrsave (reg, info, epiloguep)
00b960c7
AH
10297 rtx reg;
10298 rs6000_stack_t *info;
9aa86737 10299 int epiloguep;
00b960c7
AH
10300{
10301 int nclobs, i;
10302 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 10303 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 10304
a004eb82
AH
10305 clobs[0]
10306 = gen_rtx_SET (VOIDmode,
10307 vrsave,
10308 gen_rtx_UNSPEC_VOLATILE (SImode,
10309 gen_rtvec (2, reg, vrsave),
10310 30));
00b960c7
AH
10311
10312 nclobs = 1;
10313
9aa86737
AH
10314 /* We need to clobber the registers in the mask so the scheduler
10315 does not move sets to VRSAVE before sets of AltiVec registers.
10316
10317 However, if the function receives nonlocal gotos, reload will set
10318 all call saved registers live. We will end up with:
10319
10320 (set (reg 999) (mem))
10321 (parallel [ (set (reg vrsave) (unspec blah))
10322 (clobber (reg 999))])
10323
10324 The clobber will cause the store into reg 999 to be dead, and
10325 flow will attempt to delete an epilogue insn. In this case, we
10326 need an unspec use/set of the register. */
00b960c7
AH
10327
10328 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10329 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
10330 {
10331 if (!epiloguep || call_used_regs [i])
10332 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
10333 gen_rtx_REG (V4SImode, i));
10334 else
10335 {
10336 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
10337
10338 clobs[nclobs++]
a004eb82
AH
10339 = gen_rtx_SET (VOIDmode,
10340 reg,
10341 gen_rtx_UNSPEC (V4SImode,
10342 gen_rtvec (1, reg), 27));
9aa86737
AH
10343 }
10344 }
00b960c7
AH
10345
10346 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
10347
10348 for (i = 0; i < nclobs; ++i)
10349 XVECEXP (insn, 0, i) = clobs[i];
10350
10351 return insn;
10352}
10353
89e7058f
AH
10354/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
10355 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
10356
10357static void
10358emit_frame_save (frame_reg, frame_ptr, mode, regno, offset, total_size)
10359 rtx frame_reg;
10360 rtx frame_ptr;
10361 enum machine_mode mode;
10362 unsigned int regno;
10363 int offset;
10364 int total_size;
10365{
10366 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
10367 rtx replacea, replaceb;
10368
10369 int_rtx = GEN_INT (offset);
10370
10371 /* Some cases that need register indexed addressing. */
10372 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
10373 || (TARGET_SPE_ABI
10374 && SPE_VECTOR_MODE (mode)
10375 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
10376 {
10377 /* Whomever calls us must make sure r11 is available in the
10378 flow path of instructions in the prologue. */
10379 offset_rtx = gen_rtx_REG (Pmode, 11);
10380 emit_move_insn (offset_rtx, int_rtx);
10381
10382 replacea = offset_rtx;
10383 replaceb = int_rtx;
10384 }
10385 else
10386 {
10387 offset_rtx = int_rtx;
10388 replacea = NULL_RTX;
10389 replaceb = NULL_RTX;
10390 }
10391
10392 reg = gen_rtx_REG (mode, regno);
10393 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
10394 mem = gen_rtx_MEM (mode, addr);
10395 set_mem_alias_set (mem, rs6000_sr_alias_set);
10396
10397 insn = emit_move_insn (mem, reg);
10398
10399 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
10400}
10401
a3170dc6
AH
10402/* Emit an offset memory reference suitable for a frame store, while
10403 converting to a valid addressing mode. */
10404
10405static rtx
10406gen_frame_mem_offset (mode, reg, offset)
10407 enum machine_mode mode;
10408 rtx reg;
10409 int offset;
10410{
10411 rtx int_rtx, offset_rtx;
10412
10413 int_rtx = GEN_INT (offset);
10414
10415 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
10416 {
10417 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10418 emit_move_insn (offset_rtx, int_rtx);
10419 }
10420 else
10421 offset_rtx = int_rtx;
10422
10423 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
10424}
10425
9ebbca7d
GK
10426/* Emit function prologue as insns. */
10427
9878760c 10428void
83720594 10429rs6000_emit_prologue ()
9878760c 10430{
4697a36c 10431 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
10432 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10433 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10434 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10435 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
10436 rtx frame_reg_rtx = sp_reg_rtx;
10437 rtx cr_save_rtx = NULL;
10438 rtx insn;
10439 int saving_FPRs_inline;
10440 int using_store_multiple;
10441 HOST_WIDE_INT sp_offset = 0;
10442
c19de7aa 10443 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10444 {
10445 reg_mode = V2SImode;
10446 reg_size = 8;
10447 }
10448
9ebbca7d 10449 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
10450 && (!TARGET_SPE_ABI
10451 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
10452 && info->first_gp_reg_save < 31);
10453 saving_FPRs_inline = (info->first_fp_reg_save == 64
10454 || FP_SAVE_INLINE (info->first_fp_reg_save));
10455
10456 /* For V.4, update stack before we do any saving and set back pointer. */
f607bc57 10457 if (info->push_p && DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10458 {
10459 if (info->total_size < 32767)
10460 sp_offset = info->total_size;
10461 else
10462 frame_reg_rtx = frame_ptr_rtx;
10463 rs6000_emit_allocate_stack (info->total_size,
10464 (frame_reg_rtx != sp_reg_rtx
10465 && (info->cr_save_p
10466 || info->lr_save_p
10467 || info->first_fp_reg_save < 64
10468 || info->first_gp_reg_save < 32
10469 )));
10470 if (frame_reg_rtx != sp_reg_rtx)
10471 rs6000_emit_stack_tie ();
10472 }
10473
9aa86737
AH
10474 /* Save AltiVec registers if needed. */
10475 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10476 {
10477 int i;
10478
10479 /* There should be a non inline version of this, for when we
10480 are saving lots of vector registers. */
10481 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10482 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10483 {
10484 rtx areg, savereg, mem;
10485 int offset;
10486
10487 offset = info->altivec_save_offset + sp_offset
10488 + 16 * (i - info->first_altivec_reg_save);
10489
10490 savereg = gen_rtx_REG (V4SImode, i);
10491
10492 areg = gen_rtx_REG (Pmode, 0);
10493 emit_move_insn (areg, GEN_INT (offset));
10494
10495 /* AltiVec addressing mode is [reg+reg]. */
10496 mem = gen_rtx_MEM (V4SImode,
10497 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
10498
10499 set_mem_alias_set (mem, rs6000_sr_alias_set);
10500
10501 insn = emit_move_insn (mem, savereg);
10502
5c242421
SB
10503 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10504 areg, GEN_INT (offset));
9aa86737
AH
10505 }
10506 }
10507
10508 /* VRSAVE is a bit vector representing which AltiVec registers
10509 are used. The OS uses this to determine which vector
10510 registers to save on a context switch. We need to save
10511 VRSAVE on the stack frame, add whatever AltiVec registers we
10512 used in this function, and do the corresponding magic in the
10513 epilogue. */
10514
10515 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
10516 {
a004eb82 10517 rtx reg, mem, vrsave;
9aa86737
AH
10518 int offset;
10519
10520 /* Get VRSAVE onto a GPR. */
10521 reg = gen_rtx_REG (SImode, 12);
a004eb82 10522 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
10523 if (TARGET_MACHO)
10524 emit_insn (gen_get_vrsave_internal (reg));
10525 else
10526 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
10527
10528 /* Save VRSAVE. */
10529 offset = info->vrsave_save_offset + sp_offset;
10530 mem
10531 = gen_rtx_MEM (SImode,
10532 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
10533 set_mem_alias_set (mem, rs6000_sr_alias_set);
10534 insn = emit_move_insn (mem, reg);
10535
10536 /* Include the registers in the mask. */
10537 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
10538
10539 insn = emit_insn (generate_set_vrsave (reg, info, 0));
10540 }
10541
9ebbca7d
GK
10542 /* If we use the link register, get it into r0. */
10543 if (info->lr_save_p)
71f123ca 10544 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
10545 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10546
10547 /* If we need to save CR, put it into r12. */
10548 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
10549 {
10550 cr_save_rtx = gen_rtx_REG (SImode, 12);
10551 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10552 }
10553
a4f6c312
SS
10554 /* Do any required saving of fpr's. If only one or two to save, do
10555 it ourselves. Otherwise, call function. */
9ebbca7d
GK
10556 if (saving_FPRs_inline)
10557 {
10558 int i;
10559 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10560 if ((regs_ever_live[info->first_fp_reg_save+i]
10561 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
10562 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
10563 info->first_fp_reg_save + i,
10564 info->fp_save_offset + sp_offset + 8 * i,
10565 info->total_size);
9ebbca7d
GK
10566 }
10567 else if (info->first_fp_reg_save != 64)
10568 {
10569 int i;
10570 char rname[30];
520a57c8 10571 const char *alloc_rname;
9ebbca7d
GK
10572 rtvec p;
10573 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
10574
10575 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
10576 gen_rtx_REG (Pmode,
10577 LINK_REGISTER_REGNUM));
10578 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
10579 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 10580 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
10581 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
10582 gen_rtx_SYMBOL_REF (Pmode,
10583 alloc_rname));
10584 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10585 {
10586 rtx addr, reg, mem;
10587 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
10588 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10589 GEN_INT (info->fp_save_offset
10590 + sp_offset + 8*i));
10591 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 10592 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10593
10594 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
10595 }
10596 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10597 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10598 NULL_RTX, NULL_RTX);
10599 }
b6c9286a 10600
9ebbca7d
GK
10601 /* Save GPRs. This is done as a PARALLEL if we are using
10602 the store-multiple instructions. */
10603 if (using_store_multiple)
b6c9286a 10604 {
308c142a 10605 rtvec p;
9ebbca7d
GK
10606 int i;
10607 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
10608 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10609 {
10610 rtx addr, reg, mem;
10611 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10612 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10613 GEN_INT (info->gp_save_offset
10614 + sp_offset
10615 + reg_size * i));
10616 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 10617 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10618
10619 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
10620 }
10621 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10622 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10623 NULL_RTX, NULL_RTX);
b6c9286a
MM
10624 }
10625 else
10626 {
9ebbca7d
GK
10627 int i;
10628 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10629 if ((regs_ever_live[info->first_gp_reg_save+i]
10630 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 10631 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10632 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10633 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
10634 {
10635 rtx addr, reg, mem;
10636 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10637
c19de7aa 10638 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10639 {
10640 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
10641 rtx b;
10642
10643 if (!SPE_CONST_OFFSET_OK (offset))
10644 {
10645 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10646 emit_move_insn (b, GEN_INT (offset));
10647 }
10648 else
10649 b = GEN_INT (offset);
10650
10651 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
10652 mem = gen_rtx_MEM (V2SImode, addr);
10653 set_mem_alias_set (mem, rs6000_sr_alias_set);
10654 insn = emit_move_insn (mem, reg);
10655
10656 if (GET_CODE (b) == CONST_INT)
10657 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10658 NULL_RTX, NULL_RTX);
10659 else
10660 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10661 b, GEN_INT (offset));
10662 }
10663 else
10664 {
10665 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10666 GEN_INT (info->gp_save_offset
10667 + sp_offset
10668 + reg_size * i));
10669 mem = gen_rtx_MEM (reg_mode, addr);
10670 set_mem_alias_set (mem, rs6000_sr_alias_set);
10671
10672 insn = emit_move_insn (mem, reg);
10673 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10674 NULL_RTX, NULL_RTX);
10675 }
10676 }
9ebbca7d
GK
10677 }
10678
83720594
RH
10679 /* ??? There's no need to emit actual instructions here, but it's the
10680 easiest way to get the frame unwind information emitted. */
10681 if (current_function_calls_eh_return)
10682 {
78e1b90d
DE
10683 unsigned int i, regno;
10684
83720594
RH
10685 for (i = 0; ; ++i)
10686 {
83720594
RH
10687 regno = EH_RETURN_DATA_REGNO (i);
10688 if (regno == INVALID_REGNUM)
10689 break;
10690
89e7058f
AH
10691 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
10692 info->ehrd_offset + sp_offset
10693 + reg_size * (int) i,
10694 info->total_size);
83720594
RH
10695 }
10696 }
10697
9ebbca7d
GK
10698 /* Save lr if we used it. */
10699 if (info->lr_save_p)
10700 {
10701 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10702 GEN_INT (info->lr_save_offset + sp_offset));
10703 rtx reg = gen_rtx_REG (Pmode, 0);
10704 rtx mem = gen_rtx_MEM (Pmode, addr);
10705 /* This should not be of rs6000_sr_alias_set, because of
10706 __builtin_return_address. */
10707
10708 insn = emit_move_insn (mem, reg);
10709 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10710 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10711 }
10712
10713 /* Save CR if we use any that must be preserved. */
10714 if (info->cr_save_p)
10715 {
10716 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10717 GEN_INT (info->cr_save_offset + sp_offset));
10718 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10719
10720 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10721
10722 /* If r12 was used to hold the original sp, copy cr into r0 now
10723 that it's free. */
10724 if (REGNO (frame_reg_rtx) == 12)
10725 {
10726 cr_save_rtx = gen_rtx_REG (SImode, 0);
10727 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10728 }
10729 insn = emit_move_insn (mem, cr_save_rtx);
10730
10731 /* Now, there's no way that dwarf2out_frame_debug_expr is going
10732 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
10733 OK. All we have to do is specify that _one_ condition code
10734 register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
10735 will then restore all the call-saved registers.
10736 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 10737 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 10738 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
10739 }
10740
10741 /* Update stack and set back pointer unless this is V.4,
10742 for which it was done previously. */
f607bc57 10743 if (info->push_p && DEFAULT_ABI != ABI_V4)
9ebbca7d
GK
10744 rs6000_emit_allocate_stack (info->total_size, FALSE);
10745
10746 /* Set frame pointer, if needed. */
10747 if (frame_pointer_needed)
10748 {
a3170dc6 10749 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
10750 sp_reg_rtx);
10751 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 10752 }
9878760c 10753
1db02437 10754 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 10755 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 10756 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 10757 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
10758 {
10759 /* If emit_load_toc_table will use the link register, we need to save
10760 it. We use R11 for this purpose because emit_load_toc_table
10761 can use register 0. This allows us to use a plain 'blr' to return
10762 from the procedure more often. */
f1384257
AM
10763 int save_LR_around_toc_setup = (TARGET_ELF
10764 && DEFAULT_ABI != ABI_AIX
10765 && flag_pic
d5fa86ba
GK
10766 && ! info->lr_save_p
10767 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d
GK
10768 if (save_LR_around_toc_setup)
10769 emit_move_insn (gen_rtx_REG (Pmode, 11),
10770 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10771
10772 rs6000_emit_load_toc_table (TRUE);
10773
10774 if (save_LR_around_toc_setup)
10775 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
10776 gen_rtx_REG (Pmode, 11));
10777 }
ee890fe2 10778
fcce224d 10779#if TARGET_MACHO
ee890fe2
SS
10780 if (DEFAULT_ABI == ABI_DARWIN
10781 && flag_pic && current_function_uses_pic_offset_table)
10782 {
10783 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 10784 const char *picbase = machopic_function_base_name ();
f51eee6a 10785 rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
ee890fe2 10786
f51eee6a 10787 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
10788
10789 rs6000_maybe_dead (
1db02437 10790 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
10791 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
10792 }
fcce224d 10793#endif
9ebbca7d
GK
10794}
10795
9ebbca7d 10796/* Write function prologue. */
a4f6c312 10797
08c148a8
NB
10798static void
10799rs6000_output_function_prologue (file, size)
9ebbca7d 10800 FILE *file;
08c148a8 10801 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9ebbca7d
GK
10802{
10803 rs6000_stack_t *info = rs6000_stack_info ();
10804
4697a36c
MM
10805 if (TARGET_DEBUG_STACK)
10806 debug_stack_info (info);
9878760c 10807
a4f6c312
SS
10808 /* Write .extern for any function we will call to save and restore
10809 fp values. */
10810 if (info->first_fp_reg_save < 64
10811 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 10812 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 10813 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
10814 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
10815 RESTORE_FP_SUFFIX);
9878760c 10816
c764f757
RK
10817 /* Write .extern for AIX common mode routines, if needed. */
10818 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
10819 {
f6709c70
JW
10820 fputs ("\t.extern __mulh\n", file);
10821 fputs ("\t.extern __mull\n", file);
10822 fputs ("\t.extern __divss\n", file);
10823 fputs ("\t.extern __divus\n", file);
10824 fputs ("\t.extern __quoss\n", file);
10825 fputs ("\t.extern __quous\n", file);
c764f757
RK
10826 common_mode_defined = 1;
10827 }
9878760c 10828
9ebbca7d 10829 if (! HAVE_prologue)
979721f8 10830 {
9ebbca7d 10831 start_sequence ();
9dda4cc8 10832
a4f6c312
SS
10833 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
10834 the "toplevel" insn chain. */
9ebbca7d
GK
10835 emit_note (0, NOTE_INSN_DELETED);
10836 rs6000_emit_prologue ();
10837 emit_note (0, NOTE_INSN_DELETED);
178c3eff
DJ
10838
10839 /* Expand INSN_ADDRESSES so final() doesn't crash. */
10840 {
10841 rtx insn;
10842 unsigned addr = 0;
10843 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
10844 {
10845 INSN_ADDRESSES_NEW (insn, addr);
10846 addr += 4;
10847 }
10848 }
9dda4cc8 10849
9ebbca7d 10850 if (TARGET_DEBUG_STACK)
a4f6c312
SS
10851 debug_rtx_list (get_insns (), 100);
10852 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 10853 end_sequence ();
979721f8
MM
10854 }
10855
9ebbca7d
GK
10856 rs6000_pic_labelno++;
10857}
10858
10859/* Emit function epilogue as insns.
9878760c 10860
9ebbca7d
GK
10861 At present, dwarf2out_frame_debug_expr doesn't understand
10862 register restores, so we don't bother setting RTX_FRAME_RELATED_P
10863 anywhere in the epilogue. Most of the insns below would in any case
10864 need special notes to explain where r11 is in relation to the stack. */
9878760c 10865
9ebbca7d 10866void
83720594 10867rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
10868 int sibcall;
10869{
10870 rs6000_stack_t *info;
10871 int restoring_FPRs_inline;
10872 int using_load_multiple;
10873 int using_mfcr_multiple;
10874 int use_backchain_to_restore_sp;
10875 int sp_offset = 0;
10876 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
10877 rtx frame_reg_rtx = sp_reg_rtx;
10878 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10879 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10880 int i;
10881
c19de7aa
AH
10882 info = rs6000_stack_info ();
10883
10884 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10885 {
10886 reg_mode = V2SImode;
10887 reg_size = 8;
10888 }
10889
9ebbca7d 10890 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
10891 && (!TARGET_SPE_ABI
10892 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
10893 && info->first_gp_reg_save < 31);
10894 restoring_FPRs_inline = (sibcall
83720594 10895 || current_function_calls_eh_return
9ebbca7d
GK
10896 || info->first_fp_reg_save == 64
10897 || FP_SAVE_INLINE (info->first_fp_reg_save));
10898 use_backchain_to_restore_sp = (frame_pointer_needed
10899 || current_function_calls_alloca
10900 || info->total_size > 32767);
10901 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
10902 || rs6000_cpu == PROCESSOR_PPC603
10903 || rs6000_cpu == PROCESSOR_PPC750
10904 || optimize_size);
10905
10906 /* If we have a frame pointer, a call to alloca, or a large stack
10907 frame, restore the old stack pointer using the backchain. Otherwise,
10908 we know what size to update it with. */
10909 if (use_backchain_to_restore_sp)
bacbde18 10910 {
9ebbca7d
GK
10911 /* Under V.4, don't reset the stack pointer until after we're done
10912 loading the saved registers. */
f607bc57 10913 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 10914 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 10915
9ebbca7d
GK
10916 emit_move_insn (frame_reg_rtx,
10917 gen_rtx_MEM (Pmode, sp_reg_rtx));
10918
bacbde18 10919 }
9ebbca7d 10920 else if (info->push_p)
85638c0d 10921 {
f607bc57 10922 if (DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10923 sp_offset = info->total_size;
10924 else
10925 {
10926 emit_insn (TARGET_32BIT
10927 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
10928 GEN_INT (info->total_size))
10929 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
10930 GEN_INT (info->total_size)));
10931 }
85638c0d 10932 }
9ebbca7d 10933
9aa86737
AH
10934 /* Restore AltiVec registers if needed. */
10935 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10936 {
10937 int i;
10938
10939 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10940 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10941 {
10942 rtx addr, areg, mem;
10943
10944 areg = gen_rtx_REG (Pmode, 0);
10945 emit_move_insn
10946 (areg, GEN_INT (info->altivec_save_offset
10947 + sp_offset
10948 + 16 * (i - info->first_altivec_reg_save)));
10949
10950 /* AltiVec addressing mode is [reg+reg]. */
10951 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
10952 mem = gen_rtx_MEM (V4SImode, addr);
10953 set_mem_alias_set (mem, rs6000_sr_alias_set);
10954
10955 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
10956 }
10957 }
10958
10959 /* Restore VRSAVE if needed. */
10960 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
10961 {
10962 rtx addr, mem, reg;
10963
10964 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10965 GEN_INT (info->vrsave_save_offset + sp_offset));
10966 mem = gen_rtx_MEM (SImode, addr);
10967 set_mem_alias_set (mem, rs6000_sr_alias_set);
10968 reg = gen_rtx_REG (SImode, 12);
10969 emit_move_insn (reg, mem);
10970
10971 emit_insn (generate_set_vrsave (reg, info, 1));
10972 }
10973
9ebbca7d
GK
10974 /* Get the old lr if we saved it. */
10975 if (info->lr_save_p)
b6c9286a 10976 {
a3170dc6
AH
10977 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
10978 info->lr_save_offset + sp_offset);
ba4828e0
RK
10979
10980 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10981
9ebbca7d 10982 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 10983 }
9ebbca7d
GK
10984
10985 /* Get the old cr if we saved it. */
10986 if (info->cr_save_p)
10987 {
10988 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10989 GEN_INT (info->cr_save_offset + sp_offset));
10990 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10991
10992 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10993
9ebbca7d
GK
10994 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
10995 }
10996
10997 /* Set LR here to try to overlap restores below. */
4697a36c 10998 if (info->lr_save_p)
9ebbca7d
GK
10999 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
11000 gen_rtx_REG (Pmode, 0));
11001
83720594
RH
11002 /* Load exception handler data registers, if needed. */
11003 if (current_function_calls_eh_return)
11004 {
78e1b90d
DE
11005 unsigned int i, regno;
11006
83720594
RH
11007 for (i = 0; ; ++i)
11008 {
a3170dc6 11009 rtx mem;
83720594
RH
11010
11011 regno = EH_RETURN_DATA_REGNO (i);
11012 if (regno == INVALID_REGNUM)
11013 break;
11014
a3170dc6
AH
11015 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
11016 info->ehrd_offset + sp_offset
11017 + reg_size * (int) i);
ba4828e0 11018 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
11019
11020 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
11021 }
11022 }
9ebbca7d
GK
11023
11024 /* Restore GPRs. This is done as a PARALLEL if we are using
11025 the load-multiple instructions. */
11026 if (using_load_multiple)
979721f8 11027 {
9ebbca7d
GK
11028 rtvec p;
11029 p = rtvec_alloc (32 - info->first_gp_reg_save);
11030 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 11031 {
9ebbca7d
GK
11032 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11033 GEN_INT (info->gp_save_offset
11034 + sp_offset
11035 + reg_size * i));
11036 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
11037
11038 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11039
11040 RTVEC_ELT (p, i) =
11041 gen_rtx_SET (VOIDmode,
11042 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
11043 mem);
979721f8 11044 }
9ebbca7d 11045 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 11046 }
9ebbca7d
GK
11047 else
11048 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11049 if ((regs_ever_live[info->first_gp_reg_save+i]
11050 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11051 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11052 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11053 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
11054 {
11055 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11056 GEN_INT (info->gp_save_offset
11057 + sp_offset
11058 + reg_size * i));
11059 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11060
a3170dc6 11061 /* Restore 64-bit quantities for SPE. */
c19de7aa 11062 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11063 {
11064 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11065 rtx b;
11066
11067 if (!SPE_CONST_OFFSET_OK (offset))
11068 {
11069 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11070 emit_move_insn (b, GEN_INT (offset));
11071 }
11072 else
11073 b = GEN_INT (offset);
11074
11075 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11076 mem = gen_rtx_MEM (V2SImode, addr);
11077 }
11078
ba4828e0 11079 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11080
11081 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 11082 info->first_gp_reg_save + i), mem);
9ebbca7d 11083 }
9878760c 11084
9ebbca7d
GK
11085 /* Restore fpr's if we need to do it without calling a function. */
11086 if (restoring_FPRs_inline)
11087 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11088 if ((regs_ever_live[info->first_fp_reg_save+i]
11089 && ! call_used_regs[info->first_fp_reg_save+i]))
11090 {
11091 rtx addr, mem;
11092 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11093 GEN_INT (info->fp_save_offset
11094 + sp_offset
a4f6c312 11095 + 8 * i));
9ebbca7d 11096 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11097 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11098
11099 emit_move_insn (gen_rtx_REG (DFmode,
11100 info->first_fp_reg_save + i),
11101 mem);
11102 }
8d30c4ee 11103
9ebbca7d
GK
11104 /* If we saved cr, restore it here. Just those that were used. */
11105 if (info->cr_save_p)
979721f8 11106 {
9ebbca7d 11107 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 11108 int count = 0;
9ebbca7d
GK
11109
11110 if (using_mfcr_multiple)
979721f8 11111 {
9ebbca7d
GK
11112 for (i = 0; i < 8; i++)
11113 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 11114 count++;
9ebbca7d 11115 if (count == 0)
e35b9579
GK
11116 abort ();
11117 }
11118
11119 if (using_mfcr_multiple && count > 1)
11120 {
11121 rtvec p;
11122 int ndx;
9ebbca7d 11123
e35b9579 11124 p = rtvec_alloc (count);
9ebbca7d 11125
e35b9579 11126 ndx = 0;
9ebbca7d
GK
11127 for (i = 0; i < 8; i++)
11128 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
11129 {
11130 rtvec r = rtvec_alloc (2);
11131 RTVEC_ELT (r, 0) = r12_rtx;
11132 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 11133 RTVEC_ELT (p, ndx) =
9ebbca7d
GK
11134 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
11135 gen_rtx_UNSPEC (CCmode, r, 20));
e35b9579 11136 ndx++;
9ebbca7d
GK
11137 }
11138 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
11139 if (ndx != count)
11140 abort ();
979721f8
MM
11141 }
11142 else
9ebbca7d
GK
11143 for (i = 0; i < 8; i++)
11144 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 11145 {
9ebbca7d
GK
11146 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
11147 CR0_REGNO+i),
11148 r12_rtx));
979721f8 11149 }
979721f8
MM
11150 }
11151
9ebbca7d
GK
11152 /* If this is V.4, unwind the stack pointer after all of the loads
11153 have been done. We need to emit a block here so that sched
11154 doesn't decide to move the sp change before the register restores
11155 (which may not have any obvious dependency on the stack). This
11156 doesn't hurt performance, because there is no scheduling that can
11157 be done after this point. */
f607bc57 11158 if (DEFAULT_ABI == ABI_V4)
b6c9286a 11159 {
9ebbca7d
GK
11160 if (frame_reg_rtx != sp_reg_rtx)
11161 rs6000_emit_stack_tie ();
b6c9286a 11162
9ebbca7d 11163 if (use_backchain_to_restore_sp)
b6c9286a 11164 {
9ebbca7d 11165 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 11166 }
9ebbca7d 11167 else if (sp_offset != 0)
13f1623b 11168 {
5b71a4e7 11169 emit_insn (TARGET_32BIT
9ebbca7d
GK
11170 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11171 GEN_INT (sp_offset))
11172 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11173 GEN_INT (sp_offset)));
13f1623b 11174 }
9ebbca7d 11175 }
b6c9286a 11176
83720594
RH
11177 if (current_function_calls_eh_return)
11178 {
11179 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 11180 emit_insn (TARGET_32BIT
83720594
RH
11181 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
11182 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
11183 }
11184
9ebbca7d
GK
11185 if (!sibcall)
11186 {
11187 rtvec p;
11188 if (! restoring_FPRs_inline)
11189 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
11190 else
11191 p = rtvec_alloc (2);
b6c9286a 11192
e35b9579
GK
11193 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
11194 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
11195 gen_rtx_REG (Pmode,
11196 LINK_REGISTER_REGNUM));
9ebbca7d
GK
11197
11198 /* If we have to restore more than two FP registers, branch to the
11199 restore function. It will return to our caller. */
11200 if (! restoring_FPRs_inline)
11201 {
11202 int i;
11203 char rname[30];
520a57c8 11204 const char *alloc_rname;
979721f8 11205
9ebbca7d
GK
11206 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
11207 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 11208 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11209 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
11210 gen_rtx_SYMBOL_REF (Pmode,
11211 alloc_rname));
b6c9286a 11212
9ebbca7d
GK
11213 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11214 {
11215 rtx addr, mem;
11216 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
11217 GEN_INT (info->fp_save_offset + 8*i));
11218 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11219 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11220
11221 RTVEC_ELT (p, i+3) =
11222 gen_rtx_SET (VOIDmode,
11223 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
11224 mem);
b6c9286a
MM
11225 }
11226 }
9ebbca7d
GK
11227
11228 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 11229 }
9878760c
RK
11230}
11231
11232/* Write function epilogue. */
11233
08c148a8
NB
11234static void
11235rs6000_output_function_epilogue (file, size)
9878760c 11236 FILE *file;
08c148a8 11237 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9878760c 11238{
4697a36c 11239 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 11240
9ebbca7d 11241 if (! HAVE_epilogue)
9878760c 11242 {
9ebbca7d
GK
11243 rtx insn = get_last_insn ();
11244 /* If the last insn was a BARRIER, we don't have to write anything except
11245 the trace table. */
11246 if (GET_CODE (insn) == NOTE)
11247 insn = prev_nonnote_insn (insn);
11248 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 11249 {
9ebbca7d
GK
11250 /* This is slightly ugly, but at least we don't have two
11251 copies of the epilogue-emitting code. */
11252 start_sequence ();
11253
11254 /* A NOTE_INSN_DELETED is supposed to be at the start
11255 and end of the "toplevel" insn chain. */
11256 emit_note (0, NOTE_INSN_DELETED);
11257 rs6000_emit_epilogue (FALSE);
11258 emit_note (0, NOTE_INSN_DELETED);
11259
178c3eff
DJ
11260 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11261 {
11262 rtx insn;
11263 unsigned addr = 0;
11264 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11265 {
11266 INSN_ADDRESSES_NEW (insn, addr);
11267 addr += 4;
11268 }
11269 }
11270
9ebbca7d 11271 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11272 debug_rtx_list (get_insns (), 100);
11273 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11274 end_sequence ();
4697a36c 11275 }
9878760c 11276 }
b4ac57ab 11277
9b30bae2 11278 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
11279 on its format.
11280
11281 We don't output a traceback table if -finhibit-size-directive was
11282 used. The documentation for -finhibit-size-directive reads
11283 ``don't output a @code{.size} assembler directive, or anything
11284 else that would cause trouble if the function is split in the
11285 middle, and the two halves are placed at locations far apart in
11286 memory.'' The traceback table has this property, since it
11287 includes the offset from the start of the function to the
4d30c363
MM
11288 traceback table itself.
11289
11290 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 11291 different traceback table. */
57ac7be9
AM
11292 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
11293 && rs6000_traceback != traceback_none)
9b30bae2 11294 {
69c75916 11295 const char *fname = NULL;
3ac88239 11296 const char *language_string = lang_hooks.name;
6041bf2f 11297 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 11298 int i;
57ac7be9
AM
11299 int optional_tbtab;
11300
11301 if (rs6000_traceback == traceback_full)
11302 optional_tbtab = 1;
11303 else if (rs6000_traceback == traceback_part)
11304 optional_tbtab = 0;
11305 else
11306 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 11307
69c75916
AM
11308 if (optional_tbtab)
11309 {
11310 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11311 while (*fname == '.') /* V.4 encodes . in the name */
11312 fname++;
11313
11314 /* Need label immediately before tbtab, so we can compute
11315 its offset from the function start. */
11316 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
11317 ASM_OUTPUT_LABEL (file, fname);
11318 }
314fc5a9
ILT
11319
11320 /* The .tbtab pseudo-op can only be used for the first eight
11321 expressions, since it can't handle the possibly variable
11322 length fields that follow. However, if you omit the optional
11323 fields, the assembler outputs zeros for all optional fields
11324 anyways, giving each variable length field is minimum length
11325 (as defined in sys/debug.h). Thus we can not use the .tbtab
11326 pseudo-op at all. */
11327
11328 /* An all-zero word flags the start of the tbtab, for debuggers
11329 that have to find it by searching forward from the entry
11330 point or from the current pc. */
19d2d16f 11331 fputs ("\t.long 0\n", file);
314fc5a9
ILT
11332
11333 /* Tbtab format type. Use format type 0. */
19d2d16f 11334 fputs ("\t.byte 0,", file);
314fc5a9
ILT
11335
11336 /* Language type. Unfortunately, there doesn't seem to be any
11337 official way to get this info, so we use language_string. C
11338 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 11339 value for C for now. There is no official value for Java,
6f573ff9 11340 although IBM appears to be using 13. There is no official value
f710504c 11341 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 11342 if (! strcmp (language_string, "GNU C")
e2c953b6 11343 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
11344 i = 0;
11345 else if (! strcmp (language_string, "GNU F77"))
11346 i = 1;
11347 else if (! strcmp (language_string, "GNU Ada"))
11348 i = 3;
8b83775b 11349 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
11350 i = 2;
11351 else if (! strcmp (language_string, "GNU C++"))
11352 i = 9;
9517ead8
AG
11353 else if (! strcmp (language_string, "GNU Java"))
11354 i = 13;
6f573ff9
JL
11355 else if (! strcmp (language_string, "GNU CHILL"))
11356 i = 44;
314fc5a9
ILT
11357 else
11358 abort ();
11359 fprintf (file, "%d,", i);
11360
11361 /* 8 single bit fields: global linkage (not set for C extern linkage,
11362 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
11363 from start of procedure stored in tbtab, internal function, function
11364 has controlled storage, function has no toc, function uses fp,
11365 function logs/aborts fp operations. */
11366 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
11367 fprintf (file, "%d,",
11368 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
11369
11370 /* 6 bitfields: function is interrupt handler, name present in
11371 proc table, function calls alloca, on condition directives
11372 (controls stack walks, 3 bits), saves condition reg, saves
11373 link reg. */
11374 /* The `function calls alloca' bit seems to be set whenever reg 31 is
11375 set up as a frame pointer, even when there is no alloca call. */
11376 fprintf (file, "%d,",
6041bf2f
DE
11377 ((optional_tbtab << 6)
11378 | ((optional_tbtab & frame_pointer_needed) << 5)
11379 | (info->cr_save_p << 1)
11380 | (info->lr_save_p)));
314fc5a9 11381
6041bf2f 11382 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
11383 (6 bits). */
11384 fprintf (file, "%d,",
4697a36c 11385 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
11386
11387 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
11388 fprintf (file, "%d,", (32 - first_reg_to_save ()));
11389
6041bf2f
DE
11390 if (optional_tbtab)
11391 {
11392 /* Compute the parameter info from the function decl argument
11393 list. */
11394 tree decl;
11395 int next_parm_info_bit = 31;
314fc5a9 11396
6041bf2f
DE
11397 for (decl = DECL_ARGUMENTS (current_function_decl);
11398 decl; decl = TREE_CHAIN (decl))
11399 {
11400 rtx parameter = DECL_INCOMING_RTL (decl);
11401 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 11402
6041bf2f
DE
11403 if (GET_CODE (parameter) == REG)
11404 {
11405 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
11406 {
11407 int bits;
11408
11409 float_parms++;
11410
11411 if (mode == SFmode)
11412 bits = 0x2;
fcce224d 11413 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
11414 bits = 0x3;
11415 else
11416 abort ();
11417
11418 /* If only one bit will fit, don't or in this entry. */
11419 if (next_parm_info_bit > 0)
11420 parm_info |= (bits << (next_parm_info_bit - 1));
11421 next_parm_info_bit -= 2;
11422 }
11423 else
11424 {
11425 fixed_parms += ((GET_MODE_SIZE (mode)
11426 + (UNITS_PER_WORD - 1))
11427 / UNITS_PER_WORD);
11428 next_parm_info_bit -= 1;
11429 }
11430 }
11431 }
11432 }
314fc5a9
ILT
11433
11434 /* Number of fixed point parameters. */
11435 /* This is actually the number of words of fixed point parameters; thus
11436 an 8 byte struct counts as 2; and thus the maximum value is 8. */
11437 fprintf (file, "%d,", fixed_parms);
11438
11439 /* 2 bitfields: number of floating point parameters (7 bits), parameters
11440 all on stack. */
11441 /* This is actually the number of fp registers that hold parameters;
11442 and thus the maximum value is 13. */
11443 /* Set parameters on stack bit if parameters are not in their original
11444 registers, regardless of whether they are on the stack? Xlc
11445 seems to set the bit when not optimizing. */
11446 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
11447
6041bf2f
DE
11448 if (! optional_tbtab)
11449 return;
11450
314fc5a9
ILT
11451 /* Optional fields follow. Some are variable length. */
11452
11453 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
11454 11 double float. */
11455 /* There is an entry for each parameter in a register, in the order that
11456 they occur in the parameter list. Any intervening arguments on the
11457 stack are ignored. If the list overflows a long (max possible length
11458 34 bits) then completely leave off all elements that don't fit. */
11459 /* Only emit this long if there was at least one parameter. */
11460 if (fixed_parms || float_parms)
11461 fprintf (file, "\t.long %d\n", parm_info);
11462
11463 /* Offset from start of code to tb table. */
19d2d16f 11464 fputs ("\t.long ", file);
314fc5a9 11465 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
11466#if TARGET_AIX
11467 RS6000_OUTPUT_BASENAME (file, fname);
11468#else
9ebbca7d 11469 assemble_name (file, fname);
54ee9799 11470#endif
19d2d16f 11471 fputs ("-.", file);
54ee9799
DE
11472#if TARGET_AIX
11473 RS6000_OUTPUT_BASENAME (file, fname);
11474#else
9ebbca7d 11475 assemble_name (file, fname);
54ee9799 11476#endif
19d2d16f 11477 putc ('\n', file);
314fc5a9
ILT
11478
11479 /* Interrupt handler mask. */
11480 /* Omit this long, since we never set the interrupt handler bit
11481 above. */
11482
11483 /* Number of CTL (controlled storage) anchors. */
11484 /* Omit this long, since the has_ctl bit is never set above. */
11485
11486 /* Displacement into stack of each CTL anchor. */
11487 /* Omit this list of longs, because there are no CTL anchors. */
11488
11489 /* Length of function name. */
69c75916
AM
11490 if (*fname == '*')
11491 ++fname;
296b8152 11492 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
11493
11494 /* Function name. */
11495 assemble_string (fname, strlen (fname));
11496
11497 /* Register for alloca automatic storage; this is always reg 31.
11498 Only emit this if the alloca bit was set above. */
11499 if (frame_pointer_needed)
19d2d16f 11500 fputs ("\t.byte 31\n", file);
b1765bde
DE
11501
11502 fputs ("\t.align 2\n", file);
9b30bae2 11503 }
9878760c 11504}
17167fd8 11505\f
a4f6c312
SS
11506/* A C compound statement that outputs the assembler code for a thunk
11507 function, used to implement C++ virtual function calls with
11508 multiple inheritance. The thunk acts as a wrapper around a virtual
11509 function, adjusting the implicit object parameter before handing
11510 control off to the real function.
11511
11512 First, emit code to add the integer DELTA to the location that
11513 contains the incoming first argument. Assume that this argument
11514 contains a pointer, and is the one used to pass the `this' pointer
11515 in C++. This is the incoming argument *before* the function
11516 prologue, e.g. `%o0' on a sparc. The addition must preserve the
11517 values of all other incoming arguments.
17167fd8
MM
11518
11519 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
11520 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
11521 not touch the return address. Hence returning from FUNCTION will
11522 return to whoever called the current `thunk'.
17167fd8 11523
a4f6c312
SS
11524 The effect must be as if FUNCTION had been called directly with the
11525 adjusted first argument. This macro is responsible for emitting
11526 all of the code for a thunk function; output_function_prologue()
11527 and output_function_epilogue() are not invoked.
17167fd8 11528
a4f6c312
SS
11529 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
11530 been extracted from it.) It might possibly be useful on some
11531 targets, but probably not.
17167fd8 11532
a4f6c312
SS
11533 If you do not define this macro, the target-independent code in the
11534 C++ frontend will generate a less efficient heavyweight thunk that
11535 calls FUNCTION instead of jumping to it. The generic approach does
11536 not support varargs. */
17167fd8 11537
3961e8fe
RH
11538static void
11539rs6000_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
17167fd8 11540 FILE *file;
d330fd93 11541 tree thunk_fndecl ATTRIBUTE_UNUSED;
eb0424da 11542 HOST_WIDE_INT delta;
5b71a4e7 11543 HOST_WIDE_INT vcall_offset;
17167fd8
MM
11544 tree function;
11545{
5b71a4e7 11546 rtx this, insn, funexp;
17167fd8 11547
5b71a4e7
DE
11548 reload_completed = 1;
11549 no_new_pseudos = 1;
56a7189a 11550
5b71a4e7
DE
11551 /* Mark the end of the (empty) prologue. */
11552 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
17167fd8 11553
5b71a4e7
DE
11554 /* Find the "this" pointer. If the function returns a structure,
11555 the structure return pointer is in r3. */
11556 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
11557 this = gen_rtx_REG (Pmode, 4);
56a7189a 11558 else
5b71a4e7 11559 this = gen_rtx_REG (Pmode, 3);
17167fd8 11560
5b71a4e7
DE
11561 /* Apply the constant offset, if required. */
11562 if (delta)
11563 {
11564 rtx delta_rtx = GEN_INT (delta);
11565 emit_insn (TARGET_32BIT
11566 ? gen_addsi3 (this, this, delta_rtx)
11567 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
11568 }
11569
5b71a4e7
DE
11570 /* Apply the offset from the vtable, if required. */
11571 if (vcall_offset)
17167fd8 11572 {
5b71a4e7
DE
11573 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
11574 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 11575
5b71a4e7
DE
11576 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
11577 emit_insn (TARGET_32BIT
11578 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
11579 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
11580 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
11581 emit_insn (TARGET_32BIT
11582 ? gen_addsi3 (this, this, tmp)
11583 : gen_adddi3 (this, this, tmp));
17167fd8
MM
11584 }
11585
5b71a4e7
DE
11586 /* Generate a tail call to the target function. */
11587 if (!TREE_USED (function))
11588 {
11589 assemble_external (function);
11590 TREE_USED (function) = 1;
11591 }
11592 funexp = XEXP (DECL_RTL (function), 0);
42820a49 11593
5b71a4e7
DE
11594 SYMBOL_REF_FLAG (funexp) = 0;
11595 if (current_file_function_operand (funexp, VOIDmode)
a5c76ee6
ZW
11596 && (! lookup_attribute ("longcall",
11597 TYPE_ATTRIBUTES (TREE_TYPE (function)))
11598 || lookup_attribute ("shortcall",
11599 TYPE_ATTRIBUTES (TREE_TYPE (function)))))
5b71a4e7 11600 SYMBOL_REF_FLAG (funexp) = 1;
17167fd8 11601
5b71a4e7 11602 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
11603
11604#if TARGET_MACHO
ab82a49f 11605 if (MACHOPIC_INDIRECT)
5b71a4e7 11606 funexp = machopic_indirect_call_target (funexp);
ee890fe2 11607#endif
5b71a4e7
DE
11608
11609 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
11610 generate sibcall RTL explicitly to avoid constraint abort. */
11611 insn = emit_call_insn (
11612 gen_rtx_PARALLEL (VOIDmode,
11613 gen_rtvec (4,
11614 gen_rtx_CALL (VOIDmode,
11615 funexp, const0_rtx),
11616 gen_rtx_USE (VOIDmode, const0_rtx),
11617 gen_rtx_USE (VOIDmode,
11618 gen_rtx_REG (SImode,
11619 LINK_REGISTER_REGNUM)),
11620 gen_rtx_RETURN (VOIDmode))));
11621 SIBLING_CALL_P (insn) = 1;
11622 emit_barrier ();
11623
11624 /* Run just enough of rest_of_compilation to get the insns emitted.
11625 There's not really enough bulk here to make other passes such as
11626 instruction scheduling worth while. Note that use_thunk calls
11627 assemble_start_function and assemble_end_function. */
11628 insn = get_insns ();
11629 shorten_branches (insn);
11630 final_start_function (insn, file, 1);
11631 final (insn, file, 1, 0);
11632 final_end_function ();
11633
11634 reload_completed = 0;
11635 no_new_pseudos = 0;
9ebbca7d 11636}
9ebbca7d
GK
11637\f
11638/* A quick summary of the various types of 'constant-pool tables'
11639 under PowerPC:
11640
11641 Target Flags Name One table per
11642 AIX (none) AIX TOC object file
11643 AIX -mfull-toc AIX TOC object file
11644 AIX -mminimal-toc AIX minimal TOC translation unit
11645 SVR4/EABI (none) SVR4 SDATA object file
11646 SVR4/EABI -fpic SVR4 pic object file
11647 SVR4/EABI -fPIC SVR4 PIC translation unit
11648 SVR4/EABI -mrelocatable EABI TOC function
11649 SVR4/EABI -maix AIX TOC object file
11650 SVR4/EABI -maix -mminimal-toc
11651 AIX minimal TOC translation unit
11652
11653 Name Reg. Set by entries contains:
11654 made by addrs? fp? sum?
11655
11656 AIX TOC 2 crt0 as Y option option
11657 AIX minimal TOC 30 prolog gcc Y Y option
11658 SVR4 SDATA 13 crt0 gcc N Y N
11659 SVR4 pic 30 prolog ld Y not yet N
11660 SVR4 PIC 30 prolog gcc Y option option
11661 EABI TOC 30 prolog gcc Y option option
11662
11663*/
11664
9ebbca7d
GK
11665/* Hash functions for the hash table. */
11666
11667static unsigned
11668rs6000_hash_constant (k)
11669 rtx k;
11670{
46b33600
RH
11671 enum rtx_code code = GET_CODE (k);
11672 enum machine_mode mode = GET_MODE (k);
11673 unsigned result = (code << 3) ^ mode;
11674 const char *format;
11675 int flen, fidx;
9ebbca7d 11676
46b33600
RH
11677 format = GET_RTX_FORMAT (code);
11678 flen = strlen (format);
11679 fidx = 0;
9ebbca7d 11680
46b33600
RH
11681 switch (code)
11682 {
11683 case LABEL_REF:
11684 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
11685
11686 case CONST_DOUBLE:
11687 if (mode != VOIDmode)
11688 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
11689 flen = 2;
11690 break;
11691
11692 case CODE_LABEL:
11693 fidx = 3;
11694 break;
11695
11696 default:
11697 break;
11698 }
9ebbca7d
GK
11699
11700 for (; fidx < flen; fidx++)
11701 switch (format[fidx])
11702 {
11703 case 's':
11704 {
11705 unsigned i, len;
11706 const char *str = XSTR (k, fidx);
11707 len = strlen (str);
11708 result = result * 613 + len;
11709 for (i = 0; i < len; i++)
11710 result = result * 613 + (unsigned) str[i];
17167fd8
MM
11711 break;
11712 }
9ebbca7d
GK
11713 case 'u':
11714 case 'e':
11715 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
11716 break;
11717 case 'i':
11718 case 'n':
11719 result = result * 613 + (unsigned) XINT (k, fidx);
11720 break;
11721 case 'w':
11722 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
11723 result = result * 613 + (unsigned) XWINT (k, fidx);
11724 else
11725 {
11726 size_t i;
11727 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
11728 result = result * 613 + (unsigned) (XWINT (k, fidx)
11729 >> CHAR_BIT * i);
11730 }
11731 break;
11732 default:
a4f6c312 11733 abort ();
9ebbca7d 11734 }
46b33600 11735
9ebbca7d
GK
11736 return result;
11737}
11738
11739static unsigned
11740toc_hash_function (hash_entry)
11741 const void * hash_entry;
11742{
a9098fd0
GK
11743 const struct toc_hash_struct *thc =
11744 (const struct toc_hash_struct *) hash_entry;
11745 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
11746}
11747
11748/* Compare H1 and H2 for equivalence. */
11749
11750static int
11751toc_hash_eq (h1, h2)
11752 const void * h1;
11753 const void * h2;
11754{
11755 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
11756 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
11757
a9098fd0
GK
11758 if (((const struct toc_hash_struct *) h1)->key_mode
11759 != ((const struct toc_hash_struct *) h2)->key_mode)
11760 return 0;
11761
5692c7bc 11762 return rtx_equal_p (r1, r2);
9ebbca7d
GK
11763}
11764
28e510bd
MM
11765/* These are the names given by the C++ front-end to vtables, and
11766 vtable-like objects. Ideally, this logic should not be here;
11767 instead, there should be some programmatic way of inquiring as
11768 to whether or not an object is a vtable. */
11769
11770#define VTABLE_NAME_P(NAME) \
11771 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
11772 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
11773 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
11774 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
11775
11776void
11777rs6000_output_symbol_ref (file, x)
11778 FILE *file;
11779 rtx x;
11780{
11781 /* Currently C++ toc references to vtables can be emitted before it
11782 is decided whether the vtable is public or private. If this is
11783 the case, then the linker will eventually complain that there is
11784 a reference to an unknown section. Thus, for vtables only,
11785 we emit the TOC reference to reference the symbol and not the
11786 section. */
11787 const char *name = XSTR (x, 0);
54ee9799
DE
11788
11789 if (VTABLE_NAME_P (name))
11790 {
11791 RS6000_OUTPUT_BASENAME (file, name);
11792 }
11793 else
11794 assemble_name (file, name);
28e510bd
MM
11795}
11796
a4f6c312
SS
11797/* Output a TOC entry. We derive the entry name from what is being
11798 written. */
9878760c
RK
11799
11800void
a9098fd0 11801output_toc (file, x, labelno, mode)
9878760c
RK
11802 FILE *file;
11803 rtx x;
11804 int labelno;
a9098fd0 11805 enum machine_mode mode;
9878760c
RK
11806{
11807 char buf[256];
3cce094d 11808 const char *name = buf;
ec940faa 11809 const char *real_name;
9878760c
RK
11810 rtx base = x;
11811 int offset = 0;
11812
4697a36c
MM
11813 if (TARGET_NO_TOC)
11814 abort ();
11815
9ebbca7d
GK
11816 /* When the linker won't eliminate them, don't output duplicate
11817 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
11818 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
11819 CODE_LABELs. */
11820 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
11821 {
11822 struct toc_hash_struct *h;
11823 void * * found;
11824
17211ab5
GK
11825 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
11826 time because GGC is not initialised at that point. */
11827 if (toc_hash_table == NULL)
11828 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
11829 toc_hash_eq, NULL);
11830
9ebbca7d
GK
11831 h = ggc_alloc (sizeof (*h));
11832 h->key = x;
a9098fd0 11833 h->key_mode = mode;
9ebbca7d
GK
11834 h->labelno = labelno;
11835
11836 found = htab_find_slot (toc_hash_table, h, 1);
11837 if (*found == NULL)
11838 *found = h;
11839 else /* This is indeed a duplicate.
11840 Set this label equal to that label. */
11841 {
11842 fputs ("\t.set ", file);
11843 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11844 fprintf (file, "%d,", labelno);
11845 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11846 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
11847 found)->labelno));
11848 return;
11849 }
11850 }
11851
11852 /* If we're going to put a double constant in the TOC, make sure it's
11853 aligned properly when strict alignment is on. */
ff1720ed
RK
11854 if (GET_CODE (x) == CONST_DOUBLE
11855 && STRICT_ALIGNMENT
a9098fd0 11856 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
11857 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
11858 ASM_OUTPUT_ALIGN (file, 3);
11859 }
11860
4977bab6 11861 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 11862
37c37a57
RK
11863 /* Handle FP constants specially. Note that if we have a minimal
11864 TOC, things we put here aren't actually in the TOC, so we can allow
11865 FP constants. */
fcce224d
DE
11866 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
11867 {
11868 REAL_VALUE_TYPE rv;
11869 long k[4];
11870
11871 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11872 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
11873
11874 if (TARGET_64BIT)
11875 {
11876 if (TARGET_MINIMAL_TOC)
11877 fputs (DOUBLE_INT_ASM_OP, file);
11878 else
11879 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11880 k[0] & 0xffffffff, k[1] & 0xffffffff,
11881 k[2] & 0xffffffff, k[3] & 0xffffffff);
11882 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
11883 k[0] & 0xffffffff, k[1] & 0xffffffff,
11884 k[2] & 0xffffffff, k[3] & 0xffffffff);
11885 return;
11886 }
11887 else
11888 {
11889 if (TARGET_MINIMAL_TOC)
11890 fputs ("\t.long ", file);
11891 else
11892 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11893 k[0] & 0xffffffff, k[1] & 0xffffffff,
11894 k[2] & 0xffffffff, k[3] & 0xffffffff);
11895 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
11896 k[0] & 0xffffffff, k[1] & 0xffffffff,
11897 k[2] & 0xffffffff, k[3] & 0xffffffff);
11898 return;
11899 }
11900 }
11901 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 11902 {
042259f2
DE
11903 REAL_VALUE_TYPE rv;
11904 long k[2];
0adc764e 11905
042259f2
DE
11906 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11907 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 11908
13ded975
DE
11909 if (TARGET_64BIT)
11910 {
11911 if (TARGET_MINIMAL_TOC)
2bfcf297 11912 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 11913 else
2f0552b6
AM
11914 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11915 k[0] & 0xffffffff, k[1] & 0xffffffff);
11916 fprintf (file, "0x%lx%08lx\n",
11917 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11918 return;
11919 }
1875cc88 11920 else
13ded975
DE
11921 {
11922 if (TARGET_MINIMAL_TOC)
2bfcf297 11923 fputs ("\t.long ", file);
13ded975 11924 else
2f0552b6
AM
11925 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11926 k[0] & 0xffffffff, k[1] & 0xffffffff);
11927 fprintf (file, "0x%lx,0x%lx\n",
11928 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11929 return;
11930 }
9878760c 11931 }
a9098fd0 11932 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 11933 {
042259f2
DE
11934 REAL_VALUE_TYPE rv;
11935 long l;
9878760c 11936
042259f2
DE
11937 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11938 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
11939
31bfaa0b
DE
11940 if (TARGET_64BIT)
11941 {
11942 if (TARGET_MINIMAL_TOC)
2bfcf297 11943 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 11944 else
2f0552b6
AM
11945 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11946 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
11947 return;
11948 }
042259f2 11949 else
31bfaa0b
DE
11950 {
11951 if (TARGET_MINIMAL_TOC)
2bfcf297 11952 fputs ("\t.long ", file);
31bfaa0b 11953 else
2f0552b6
AM
11954 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11955 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
11956 return;
11957 }
042259f2 11958 }
f176e826 11959 else if (GET_MODE (x) == VOIDmode
a9098fd0 11960 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 11961 {
e2c953b6 11962 unsigned HOST_WIDE_INT low;
042259f2
DE
11963 HOST_WIDE_INT high;
11964
11965 if (GET_CODE (x) == CONST_DOUBLE)
11966 {
11967 low = CONST_DOUBLE_LOW (x);
11968 high = CONST_DOUBLE_HIGH (x);
11969 }
11970 else
11971#if HOST_BITS_PER_WIDE_INT == 32
11972 {
11973 low = INTVAL (x);
0858c623 11974 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
11975 }
11976#else
11977 {
0858c623 11978 low = INTVAL (x) & 0xffffffff;
042259f2
DE
11979 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
11980 }
11981#endif
9878760c 11982
a9098fd0
GK
11983 /* TOC entries are always Pmode-sized, but since this
11984 is a bigendian machine then if we're putting smaller
11985 integer constants in the TOC we have to pad them.
11986 (This is still a win over putting the constants in
11987 a separate constant pool, because then we'd have
02a4ec28
FS
11988 to have both a TOC entry _and_ the actual constant.)
11989
11990 For a 32-bit target, CONST_INT values are loaded and shifted
11991 entirely within `low' and can be stored in one TOC entry. */
11992
11993 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 11994 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
11995
11996 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
11997 {
11998#if HOST_BITS_PER_WIDE_INT == 32
11999 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
12000 POINTER_SIZE, &low, &high, 0);
12001#else
12002 low |= high << 32;
12003 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
12004 high = (HOST_WIDE_INT) low >> 32;
12005 low &= 0xffffffff;
12006#endif
12007 }
a9098fd0 12008
13ded975
DE
12009 if (TARGET_64BIT)
12010 {
12011 if (TARGET_MINIMAL_TOC)
2bfcf297 12012 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12013 else
2f0552b6
AM
12014 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
12015 (long) high & 0xffffffff, (long) low & 0xffffffff);
12016 fprintf (file, "0x%lx%08lx\n",
12017 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
12018 return;
12019 }
1875cc88 12020 else
13ded975 12021 {
02a4ec28
FS
12022 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
12023 {
12024 if (TARGET_MINIMAL_TOC)
2bfcf297 12025 fputs ("\t.long ", file);
02a4ec28 12026 else
2bfcf297 12027 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
12028 (long) high & 0xffffffff, (long) low & 0xffffffff);
12029 fprintf (file, "0x%lx,0x%lx\n",
12030 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 12031 }
13ded975 12032 else
02a4ec28
FS
12033 {
12034 if (TARGET_MINIMAL_TOC)
2bfcf297 12035 fputs ("\t.long ", file);
02a4ec28 12036 else
2f0552b6
AM
12037 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
12038 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 12039 }
13ded975
DE
12040 return;
12041 }
9878760c
RK
12042 }
12043
12044 if (GET_CODE (x) == CONST)
12045 {
2bfcf297
DB
12046 if (GET_CODE (XEXP (x, 0)) != PLUS)
12047 abort ();
12048
9878760c
RK
12049 base = XEXP (XEXP (x, 0), 0);
12050 offset = INTVAL (XEXP (XEXP (x, 0), 1));
12051 }
12052
12053 if (GET_CODE (base) == SYMBOL_REF)
12054 name = XSTR (base, 0);
12055 else if (GET_CODE (base) == LABEL_REF)
12056 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
12057 else if (GET_CODE (base) == CODE_LABEL)
12058 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
12059 else
12060 abort ();
12061
772c5265 12062 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 12063 if (TARGET_MINIMAL_TOC)
2bfcf297 12064 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
12065 else
12066 {
b6c9286a 12067 fprintf (file, "\t.tc %s", real_name);
9878760c 12068
1875cc88
JW
12069 if (offset < 0)
12070 fprintf (file, ".N%d", - offset);
12071 else if (offset)
12072 fprintf (file, ".P%d", offset);
9878760c 12073
19d2d16f 12074 fputs ("[TC],", file);
1875cc88 12075 }
581bc4de
MM
12076
12077 /* Currently C++ toc references to vtables can be emitted before it
12078 is decided whether the vtable is public or private. If this is
12079 the case, then the linker will eventually complain that there is
12080 a TOC reference to an unknown section. Thus, for vtables only,
12081 we emit the TOC reference to reference the symbol and not the
12082 section. */
28e510bd 12083 if (VTABLE_NAME_P (name))
581bc4de 12084 {
54ee9799 12085 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
12086 if (offset < 0)
12087 fprintf (file, "%d", offset);
12088 else if (offset > 0)
12089 fprintf (file, "+%d", offset);
12090 }
12091 else
12092 output_addr_const (file, x);
19d2d16f 12093 putc ('\n', file);
9878760c
RK
12094}
12095\f
12096/* Output an assembler pseudo-op to write an ASCII string of N characters
12097 starting at P to FILE.
12098
12099 On the RS/6000, we have to do this using the .byte operation and
12100 write out special characters outside the quoted string.
12101 Also, the assembler is broken; very long strings are truncated,
a4f6c312 12102 so we must artificially break them up early. */
9878760c
RK
12103
12104void
12105output_ascii (file, p, n)
12106 FILE *file;
d330fd93 12107 const char *p;
9878760c
RK
12108 int n;
12109{
12110 char c;
12111 int i, count_string;
d330fd93
KG
12112 const char *for_string = "\t.byte \"";
12113 const char *for_decimal = "\t.byte ";
12114 const char *to_close = NULL;
9878760c
RK
12115
12116 count_string = 0;
12117 for (i = 0; i < n; i++)
12118 {
12119 c = *p++;
12120 if (c >= ' ' && c < 0177)
12121 {
12122 if (for_string)
12123 fputs (for_string, file);
12124 putc (c, file);
12125
12126 /* Write two quotes to get one. */
12127 if (c == '"')
12128 {
12129 putc (c, file);
12130 ++count_string;
12131 }
12132
12133 for_string = NULL;
12134 for_decimal = "\"\n\t.byte ";
12135 to_close = "\"\n";
12136 ++count_string;
12137
12138 if (count_string >= 512)
12139 {
12140 fputs (to_close, file);
12141
12142 for_string = "\t.byte \"";
12143 for_decimal = "\t.byte ";
12144 to_close = NULL;
12145 count_string = 0;
12146 }
12147 }
12148 else
12149 {
12150 if (for_decimal)
12151 fputs (for_decimal, file);
12152 fprintf (file, "%d", c);
12153
12154 for_string = "\n\t.byte \"";
12155 for_decimal = ", ";
12156 to_close = "\n";
12157 count_string = 0;
12158 }
12159 }
12160
12161 /* Now close the string if we have written one. Then end the line. */
12162 if (to_close)
9ebbca7d 12163 fputs (to_close, file);
9878760c
RK
12164}
12165\f
12166/* Generate a unique section name for FILENAME for a section type
12167 represented by SECTION_DESC. Output goes into BUF.
12168
12169 SECTION_DESC can be any string, as long as it is different for each
12170 possible section type.
12171
12172 We name the section in the same manner as xlc. The name begins with an
12173 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
12174 names) with the last period replaced by the string SECTION_DESC. If
12175 FILENAME does not contain a period, SECTION_DESC is appended to the end of
12176 the name. */
9878760c
RK
12177
12178void
12179rs6000_gen_section_name (buf, filename, section_desc)
12180 char **buf;
9ebbca7d
GK
12181 const char *filename;
12182 const char *section_desc;
9878760c 12183{
9ebbca7d 12184 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
12185 char *p;
12186 int len;
9878760c
RK
12187
12188 after_last_slash = filename;
12189 for (q = filename; *q; q++)
11e5fe42
RK
12190 {
12191 if (*q == '/')
12192 after_last_slash = q + 1;
12193 else if (*q == '.')
12194 last_period = q;
12195 }
9878760c 12196
11e5fe42 12197 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 12198 *buf = (char *) xmalloc (len);
9878760c
RK
12199
12200 p = *buf;
12201 *p++ = '_';
12202
12203 for (q = after_last_slash; *q; q++)
12204 {
11e5fe42 12205 if (q == last_period)
9878760c
RK
12206 {
12207 strcpy (p, section_desc);
12208 p += strlen (section_desc);
e3981aab 12209 break;
9878760c
RK
12210 }
12211
e9a780ec 12212 else if (ISALNUM (*q))
9878760c
RK
12213 *p++ = *q;
12214 }
12215
11e5fe42 12216 if (last_period == 0)
9878760c
RK
12217 strcpy (p, section_desc);
12218 else
12219 *p = '\0';
12220}
e165f3f0 12221\f
a4f6c312 12222/* Emit profile function. */
411707f4 12223
411707f4
CC
12224void
12225output_profile_hook (labelno)
57ac7be9 12226 int labelno ATTRIBUTE_UNUSED;
411707f4 12227{
8480e480
CC
12228 if (DEFAULT_ABI == ABI_AIX)
12229 {
57ac7be9
AM
12230#ifdef NO_PROFILE_COUNTERS
12231 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
12232#else
8480e480 12233 char buf[30];
40501e5f 12234 const char *label_name;
8480e480 12235 rtx fun;
411707f4 12236
8480e480 12237 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
772c5265 12238 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
8480e480 12239 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 12240
8480e480
CC
12241 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
12242 fun, Pmode);
57ac7be9 12243#endif
8480e480 12244 }
ee890fe2
SS
12245 else if (DEFAULT_ABI == ABI_DARWIN)
12246 {
d5fa86ba 12247 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
12248 int caller_addr_regno = LINK_REGISTER_REGNUM;
12249
12250 /* Be conservative and always set this, at least for now. */
12251 current_function_uses_pic_offset_table = 1;
12252
12253#if TARGET_MACHO
12254 /* For PIC code, set up a stub and collect the caller's address
12255 from r0, which is where the prologue puts it. */
ab82a49f 12256 if (MACHOPIC_INDIRECT)
ee890fe2
SS
12257 {
12258 mcount_name = machopic_stub_name (mcount_name);
12259 if (current_function_uses_pic_offset_table)
12260 caller_addr_regno = 0;
12261 }
12262#endif
12263 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
12264 0, VOIDmode, 1,
12265 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
12266 }
411707f4
CC
12267}
12268
a4f6c312 12269/* Write function profiler code. */
e165f3f0
RK
12270
12271void
12272output_function_profiler (file, labelno)
12273 FILE *file;
12274 int labelno;
12275{
3daf36a4 12276 char buf[100];
09eeeacb 12277 int save_lr = 8;
e165f3f0 12278
3daf36a4 12279 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 12280 switch (DEFAULT_ABI)
3daf36a4 12281 {
38c1f2d7
MM
12282 default:
12283 abort ();
12284
12285 case ABI_V4:
09eeeacb
AM
12286 save_lr = 4;
12287 /* Fall through. */
12288
38c1f2d7 12289 case ABI_AIX_NODESC:
09eeeacb
AM
12290 if (!TARGET_32BIT)
12291 {
12292 warning ("no profiling of 64-bit code for this ABI");
12293 return;
12294 }
38c1f2d7
MM
12295 fprintf (file, "\tmflr %s\n", reg_names[0]);
12296 if (flag_pic == 1)
12297 {
dfdfa60f 12298 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
12299 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12300 reg_names[0], save_lr, reg_names[1]);
17167fd8 12301 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 12302 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 12303 assemble_name (file, buf);
17167fd8 12304 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 12305 }
9ebbca7d 12306 else if (flag_pic > 1)
38c1f2d7 12307 {
09eeeacb
AM
12308 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12309 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
12310 /* Now, we need to get the address of the label. */
12311 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 12312 assemble_name (file, buf);
9ebbca7d
GK
12313 fputs ("-.\n1:", file);
12314 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
12315 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
12316 reg_names[0], reg_names[11]);
12317 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
12318 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 12319 }
38c1f2d7
MM
12320 else
12321 {
17167fd8 12322 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 12323 assemble_name (file, buf);
dfdfa60f 12324 fputs ("@ha\n", file);
09eeeacb
AM
12325 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12326 reg_names[0], save_lr, reg_names[1]);
a260abc9 12327 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 12328 assemble_name (file, buf);
17167fd8 12329 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
12330 }
12331
09eeeacb
AM
12332 if (current_function_needs_context && DEFAULT_ABI == ABI_AIX_NODESC)
12333 {
12334 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12335 reg_names[STATIC_CHAIN_REGNUM],
12336 12, reg_names[1]);
12337 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
12338 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n",
12339 reg_names[STATIC_CHAIN_REGNUM],
12340 12, reg_names[1]);
12341 }
12342 else
12343 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
12344 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
12345 break;
12346
12347 case ABI_AIX:
ee890fe2 12348 case ABI_DARWIN:
a4f6c312 12349 /* Don't do anything, done in output_profile_hook (). */
38c1f2d7
MM
12350 break;
12351 }
e165f3f0 12352}
a251ffd0 12353
b54cf83a
DE
12354\f
12355static int
12356rs6000_use_dfa_pipeline_interface ()
12357{
12358 return 1;
12359}
12360
b54cf83a
DE
12361/* Power4 load update and store update instructions are cracked into a
12362 load or store and an integer insn which are executed in the same cycle.
12363 Branches have their own dispatch slot which does not count against the
12364 GCC issue rate, but it changes the program flow so there are no other
12365 instructions to issue in this cycle. */
12366
12367static int
12368rs6000_variable_issue (stream, verbose, insn, more)
12369 FILE *stream ATTRIBUTE_UNUSED;
12370 int verbose ATTRIBUTE_UNUSED;
12371 rtx insn;
12372 int more;
12373{
12374 if (GET_CODE (PATTERN (insn)) == USE
12375 || GET_CODE (PATTERN (insn)) == CLOBBER)
12376 return more;
12377
12378 if (rs6000_cpu == PROCESSOR_POWER4)
12379 {
12380 enum attr_type type = get_attr_type (insn);
12381 if (type == TYPE_LOAD_EXT_U || type == TYPE_LOAD_EXT_UX
12382 || type == TYPE_LOAD_UX || type == TYPE_STORE_UX
12383 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX)
12384 return 0;
12385 else if (type == TYPE_LOAD_U || type == TYPE_STORE_U
12386 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
12387 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR)
3317bab1 12388 return more > 2 ? more - 2 : 0;
b54cf83a 12389 }
165b263e
DE
12390
12391 return more - 1;
b54cf83a
DE
12392}
12393
a251ffd0
TG
12394/* Adjust the cost of a scheduling dependency. Return the new cost of
12395 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
12396
c237e94a 12397static int
a06faf84 12398rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
12399 rtx insn;
12400 rtx link;
296b8152 12401 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
12402 int cost;
12403{
12404 if (! recog_memoized (insn))
12405 return 0;
12406
12407 if (REG_NOTE_KIND (link) != 0)
12408 return 0;
12409
12410 if (REG_NOTE_KIND (link) == 0)
12411 {
ed947a96
DJ
12412 /* Data dependency; DEP_INSN writes a register that INSN reads
12413 some cycles later. */
12414 switch (get_attr_type (insn))
12415 {
12416 case TYPE_JMPREG:
309323c2 12417 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
12418 a mtctr and bctr (and mtlr and br/blr). The first
12419 scheduling pass will not know about this latency since
12420 the mtctr instruction, which has the latency associated
12421 to it, will be generated by reload. */
309323c2 12422 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
12423 case TYPE_BRANCH:
12424 /* Leave some extra cycles between a compare and its
12425 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
12426 if ((rs6000_cpu_attr == CPU_PPC603
12427 || rs6000_cpu_attr == CPU_PPC604
12428 || rs6000_cpu_attr == CPU_PPC604E
12429 || rs6000_cpu_attr == CPU_PPC620
12430 || rs6000_cpu_attr == CPU_PPC630
12431 || rs6000_cpu_attr == CPU_PPC750
12432 || rs6000_cpu_attr == CPU_PPC7400
12433 || rs6000_cpu_attr == CPU_PPC7450
12434 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
12435 && recog_memoized (dep_insn)
12436 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
12437 && (get_attr_type (dep_insn) == TYPE_CMP
12438 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96
DJ
12439 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
12440 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
12441 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
12442 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
12443 return cost + 2;
12444 default:
12445 break;
12446 }
a251ffd0
TG
12447 /* Fall out to return default cost. */
12448 }
12449
12450 return cost;
12451}
b6c9286a 12452
a4f6c312
SS
12453/* A C statement (sans semicolon) to update the integer scheduling
12454 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
12455 INSN earlier, increase the priority to execute INSN later. Do not
12456 define this macro if you do not need to adjust the scheduling
12457 priorities of insns. */
bef84347 12458
c237e94a 12459static int
bef84347 12460rs6000_adjust_priority (insn, priority)
d330fd93 12461 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
12462 int priority;
12463{
a4f6c312
SS
12464 /* On machines (like the 750) which have asymmetric integer units,
12465 where one integer unit can do multiply and divides and the other
12466 can't, reduce the priority of multiply/divide so it is scheduled
12467 before other integer operations. */
bef84347
VM
12468
12469#if 0
2c3c49de 12470 if (! INSN_P (insn))
bef84347
VM
12471 return priority;
12472
12473 if (GET_CODE (PATTERN (insn)) == USE)
12474 return priority;
12475
12476 switch (rs6000_cpu_attr) {
12477 case CPU_PPC750:
12478 switch (get_attr_type (insn))
12479 {
12480 default:
12481 break;
12482
12483 case TYPE_IMUL:
12484 case TYPE_IDIV:
3cb999d8
DE
12485 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
12486 priority, priority);
bef84347
VM
12487 if (priority >= 0 && priority < 0x01000000)
12488 priority >>= 3;
12489 break;
12490 }
12491 }
12492#endif
12493
12494 return priority;
12495}
12496
a4f6c312
SS
12497/* Return how many instructions the machine can issue per cycle. */
12498
c237e94a
ZW
12499static int
12500rs6000_issue_rate ()
b6c9286a 12501{
3317bab1
DE
12502 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
12503 if (!reload_completed)
12504 return 1;
12505
b6c9286a 12506 switch (rs6000_cpu_attr) {
3cb999d8
DE
12507 case CPU_RIOS1: /* ? */
12508 case CPU_RS64A:
12509 case CPU_PPC601: /* ? */
ed947a96 12510 case CPU_PPC7450:
3cb999d8 12511 return 3;
b54cf83a 12512 case CPU_PPC440:
b6c9286a 12513 case CPU_PPC603:
bef84347 12514 case CPU_PPC750:
ed947a96 12515 case CPU_PPC7400:
bef84347 12516 return 2;
3cb999d8 12517 case CPU_RIOS2:
b6c9286a 12518 case CPU_PPC604:
19684119 12519 case CPU_PPC604E:
b6c9286a 12520 case CPU_PPC620:
3cb999d8 12521 case CPU_PPC630:
309323c2 12522 case CPU_POWER4:
b6c9286a
MM
12523 return 4;
12524 default:
12525 return 1;
12526 }
12527}
12528
b6c9286a 12529\f
b6c9286a
MM
12530/* Length in units of the trampoline for entering a nested function. */
12531
12532int
12533rs6000_trampoline_size ()
12534{
12535 int ret = 0;
12536
12537 switch (DEFAULT_ABI)
12538 {
12539 default:
12540 abort ();
12541
12542 case ABI_AIX:
8f802bfb 12543 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
12544 break;
12545
4dabc42d 12546 case ABI_DARWIN:
b6c9286a
MM
12547 case ABI_V4:
12548 case ABI_AIX_NODESC:
03a7e1a5 12549 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 12550 break;
b6c9286a
MM
12551 }
12552
12553 return ret;
12554}
12555
12556/* Emit RTL insns to initialize the variable parts of a trampoline.
12557 FNADDR is an RTX for the address of the function's pure code.
12558 CXT is an RTX for the static chain value for the function. */
12559
12560void
12561rs6000_initialize_trampoline (addr, fnaddr, cxt)
12562 rtx addr;
12563 rtx fnaddr;
12564 rtx cxt;
12565{
ac2a93a1 12566 enum machine_mode pmode = Pmode;
8bd04c56
MM
12567 int regsize = (TARGET_32BIT) ? 4 : 8;
12568 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
12569
12570 switch (DEFAULT_ABI)
12571 {
12572 default:
12573 abort ();
12574
8bd04c56 12575/* Macros to shorten the code expansions below. */
39403d82 12576#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
12577#define MEM_PLUS(addr,offset) \
12578 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 12579
b6c9286a
MM
12580 /* Under AIX, just build the 3 word function descriptor */
12581 case ABI_AIX:
8bd04c56
MM
12582 {
12583 rtx fn_reg = gen_reg_rtx (pmode);
12584 rtx toc_reg = gen_reg_rtx (pmode);
12585 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 12586 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
12587 emit_move_insn (MEM_DEREF (addr), fn_reg);
12588 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
12589 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
12590 }
b6c9286a
MM
12591 break;
12592
4dabc42d
TC
12593 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
12594 case ABI_DARWIN:
b6c9286a
MM
12595 case ABI_V4:
12596 case ABI_AIX_NODESC:
39403d82 12597 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
12598 FALSE, VOIDmode, 4,
12599 addr, pmode,
12600 GEN_INT (rs6000_trampoline_size ()), SImode,
12601 fnaddr, pmode,
12602 ctx_reg, pmode);
b6c9286a 12603 break;
b6c9286a
MM
12604 }
12605
12606 return;
12607}
7509c759
MM
12608
12609\f
91d231cb 12610/* Table of valid machine attributes. */
a4f6c312 12611
91d231cb 12612const struct attribute_spec rs6000_attribute_table[] =
7509c759 12613{
91d231cb 12614 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
12615 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12616 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12617 { NULL, 0, 0, false, false, false, NULL }
91d231cb 12618};
7509c759 12619
a5c76ee6
ZW
12620/* Handle a "longcall" or "shortcall" attribute; arguments as in
12621 struct attribute_spec.handler. */
a4f6c312 12622
91d231cb
JM
12623static tree
12624rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs)
12625 tree *node;
12626 tree name;
12627 tree args ATTRIBUTE_UNUSED;
12628 int flags ATTRIBUTE_UNUSED;
12629 bool *no_add_attrs;
12630{
12631 if (TREE_CODE (*node) != FUNCTION_TYPE
12632 && TREE_CODE (*node) != FIELD_DECL
12633 && TREE_CODE (*node) != TYPE_DECL)
12634 {
12635 warning ("`%s' attribute only applies to functions",
12636 IDENTIFIER_POINTER (name));
12637 *no_add_attrs = true;
12638 }
6a4cee5f 12639
91d231cb 12640 return NULL_TREE;
7509c759
MM
12641}
12642
a5c76ee6
ZW
12643/* Set longcall attributes on all functions declared when
12644 rs6000_default_long_calls is true. */
12645static void
12646rs6000_set_default_type_attributes (type)
12647 tree type;
12648{
12649 if (rs6000_default_long_calls
12650 && (TREE_CODE (type) == FUNCTION_TYPE
12651 || TREE_CODE (type) == METHOD_TYPE))
12652 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
12653 NULL_TREE,
12654 TYPE_ATTRIBUTES (type));
12655}
12656
3cb999d8
DE
12657/* Return a reference suitable for calling a function with the
12658 longcall attribute. */
a4f6c312 12659
6a4cee5f
MM
12660struct rtx_def *
12661rs6000_longcall_ref (call_ref)
12662 rtx call_ref;
12663{
d330fd93 12664 const char *call_name;
6a4cee5f
MM
12665 tree node;
12666
12667 if (GET_CODE (call_ref) != SYMBOL_REF)
12668 return call_ref;
12669
12670 /* System V adds '.' to the internal name, so skip them. */
12671 call_name = XSTR (call_ref, 0);
12672 if (*call_name == '.')
12673 {
12674 while (*call_name == '.')
12675 call_name++;
12676
12677 node = get_identifier (call_name);
39403d82 12678 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
12679 }
12680
12681 return force_reg (Pmode, call_ref);
12682}
12683
7509c759 12684\f
b64a1b53
RH
12685#ifdef USING_ELFOS_H
12686
7509c759
MM
12687/* A C statement or statements to switch to the appropriate section
12688 for output of RTX in mode MODE. You can assume that RTX is some
12689 kind of constant in RTL. The argument MODE is redundant except in
12690 the case of a `const_int' rtx. Select the section by calling
12691 `text_section' or one of the alternatives for other sections.
12692
12693 Do not define this macro if you put all constants in the read-only
12694 data section. */
12695
b64a1b53
RH
12696static void
12697rs6000_elf_select_rtx_section (mode, x, align)
a9098fd0 12698 enum machine_mode mode;
7509c759 12699 rtx x;
b64a1b53 12700 unsigned HOST_WIDE_INT align;
7509c759 12701{
a9098fd0 12702 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 12703 toc_section ();
7509c759 12704 else
b64a1b53 12705 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
12706}
12707
12708/* A C statement or statements to switch to the appropriate
12709 section for output of DECL. DECL is either a `VAR_DECL' node
12710 or a constant of some sort. RELOC indicates whether forming
12711 the initial value of DECL requires link-time relocations. */
12712
ae46c4e0
RH
12713static void
12714rs6000_elf_select_section (decl, reloc, align)
7509c759
MM
12715 tree decl;
12716 int reloc;
0e5dbd9b 12717 unsigned HOST_WIDE_INT align;
7509c759 12718{
f1384257
AM
12719 /* Pretend that we're always building for a shared library when
12720 ABI_AIX, because otherwise we end up with dynamic relocations
12721 in read-only sections. This happens for function pointers,
12722 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
12723 default_elf_select_section_1 (decl, reloc, align,
12724 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
12725}
12726
12727/* A C statement to build up a unique section name, expressed as a
12728 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
12729 RELOC indicates whether the initial value of EXP requires
12730 link-time relocations. If you do not define this macro, GCC will use
12731 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 12732 macro can now be called for uninitialized data items as well as
4912a07c 12733 initialized data and functions. */
63019373 12734
ae46c4e0
RH
12735static void
12736rs6000_elf_unique_section (decl, reloc)
63019373
GK
12737 tree decl;
12738 int reloc;
12739{
f1384257
AM
12740 /* As above, pretend that we're always building for a shared library
12741 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
12742 default_unique_section_1 (decl, reloc,
12743 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 12744}
d9407988 12745\f
d9407988
MM
12746/* If we are referencing a function that is static or is known to be
12747 in this file, make the SYMBOL_REF special. We can use this to indicate
12748 that we can branch to this function without emitting a no-op after the
9ebbca7d 12749 call. For real AIX calling sequences, we also replace the
d9407988
MM
12750 function name with the real name (1 or 2 leading .'s), rather than
12751 the function descriptor name. This saves a lot of overriding code
a260abc9 12752 to read the prefixes. */
d9407988 12753
fb49053f
RH
12754static void
12755rs6000_elf_encode_section_info (decl, first)
d9407988 12756 tree decl;
b2003250 12757 int first;
d9407988 12758{
b2003250
RH
12759 if (!first)
12760 return;
12761
d9407988
MM
12762 if (TREE_CODE (decl) == FUNCTION_DECL)
12763 {
12764 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
b629ba0c 12765 if ((*targetm.binds_local_p) (decl))
d9407988
MM
12766 SYMBOL_REF_FLAG (sym_ref) = 1;
12767
f1384257 12768 if (!TARGET_AIX && DEFAULT_ABI == ABI_AIX)
d9407988 12769 {
ff669a6c
RH
12770 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
12771 size_t len2 = strlen (XSTR (sym_ref, 0));
520a57c8 12772 char *str = alloca (len1 + len2 + 1);
ff669a6c
RH
12773 str[0] = '.';
12774 str[1] = '.';
12775 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
12776
520a57c8 12777 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
d9407988
MM
12778 }
12779 }
12780 else if (rs6000_sdata != SDATA_NONE
f607bc57 12781 && DEFAULT_ABI == ABI_V4
d9407988
MM
12782 && TREE_CODE (decl) == VAR_DECL)
12783 {
c40e5172 12784 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
d9407988
MM
12785 int size = int_size_in_bytes (TREE_TYPE (decl));
12786 tree section_name = DECL_SECTION_NAME (decl);
d330fd93 12787 const char *name = (char *)0;
d9407988
MM
12788 int len = 0;
12789
c40e5172
JS
12790 if ((*targetm.binds_local_p) (decl))
12791 SYMBOL_REF_FLAG (sym_ref) = 1;
12792
d9407988
MM
12793 if (section_name)
12794 {
12795 if (TREE_CODE (section_name) == STRING_CST)
12796 {
12797 name = TREE_STRING_POINTER (section_name);
12798 len = TREE_STRING_LENGTH (section_name);
12799 }
12800 else
12801 abort ();
12802 }
12803
2792d578
DE
12804 if (name
12805 ? ((len == sizeof (".sdata") - 1
12806 && strcmp (name, ".sdata") == 0)
12807 || (len == sizeof (".sdata2") - 1
12808 && strcmp (name, ".sdata2") == 0)
12809 || (len == sizeof (".sbss") - 1
12810 && strcmp (name, ".sbss") == 0)
12811 || (len == sizeof (".sbss2") - 1
12812 && strcmp (name, ".sbss2") == 0)
12813 || (len == sizeof (".PPC.EMB.sdata0") - 1
12814 && strcmp (name, ".PPC.EMB.sdata0") == 0)
12815 || (len == sizeof (".PPC.EMB.sbss0") - 1
12816 && strcmp (name, ".PPC.EMB.sbss0") == 0))
12817 : (size > 0 && size <= g_switch_value))
d9407988 12818 {
ff669a6c 12819 size_t len = strlen (XSTR (sym_ref, 0));
88c1e412 12820 char *str = alloca (len + 2);
ff669a6c 12821
ff669a6c
RH
12822 str[0] = '@';
12823 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
88c1e412 12824 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988
MM
12825 }
12826 }
12827}
12828
772c5265
RH
12829static const char *
12830rs6000_elf_strip_name_encoding (str)
12831 const char *str;
12832{
12833 while (*str == '*' || *str == '@')
12834 str++;
12835 return str;
12836}
12837
0e5dbd9b
DE
12838static bool
12839rs6000_elf_in_small_data_p (decl)
12840 tree decl;
12841{
12842 if (rs6000_sdata == SDATA_NONE)
12843 return false;
12844
12845 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
12846 {
12847 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
12848 if (strcmp (section, ".sdata") == 0
12849 || strcmp (section, ".sdata2") == 0
12850 || strcmp (section, ".sbss") == 0)
12851 return true;
12852 }
12853 else
12854 {
12855 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
12856
12857 if (size > 0
12858 && size <= g_switch_value
12859 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
12860 return true;
12861 }
12862
12863 return false;
12864}
12865
b91da81f 12866#endif /* USING_ELFOS_H */
000034eb 12867
a6c2a102 12868\f
000034eb 12869/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
12870 ADDR can be effectively incremented by incrementing REG.
12871
12872 r0 is special and we must not select it as an address
12873 register by this routine since our caller will try to
12874 increment the returned register via an "la" instruction. */
000034eb
DE
12875
12876struct rtx_def *
12877find_addr_reg (addr)
12878 rtx addr;
12879{
12880 while (GET_CODE (addr) == PLUS)
12881 {
02441cd6
JL
12882 if (GET_CODE (XEXP (addr, 0)) == REG
12883 && REGNO (XEXP (addr, 0)) != 0)
000034eb 12884 addr = XEXP (addr, 0);
02441cd6
JL
12885 else if (GET_CODE (XEXP (addr, 1)) == REG
12886 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
12887 addr = XEXP (addr, 1);
12888 else if (CONSTANT_P (XEXP (addr, 0)))
12889 addr = XEXP (addr, 1);
12890 else if (CONSTANT_P (XEXP (addr, 1)))
12891 addr = XEXP (addr, 0);
12892 else
12893 abort ();
12894 }
02441cd6 12895 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
12896 return addr;
12897 abort ();
12898}
12899
a6c2a102
DE
12900void
12901rs6000_fatal_bad_address (op)
12902 rtx op;
12903{
12904 fatal_insn ("bad address", op);
12905}
c8023011 12906
ee890fe2
SS
12907#if TARGET_MACHO
12908
12909#if 0
12910/* Returns 1 if OP is either a symbol reference or a sum of a symbol
12911 reference and a constant. */
12912
12913int
12914symbolic_operand (op)
592696dd 12915 rtx op;
ee890fe2
SS
12916{
12917 switch (GET_CODE (op))
12918 {
12919 case SYMBOL_REF:
12920 case LABEL_REF:
12921 return 1;
12922 case CONST:
12923 op = XEXP (op, 0);
12924 return (GET_CODE (op) == SYMBOL_REF ||
12925 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
12926 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
12927 && GET_CODE (XEXP (op, 1)) == CONST_INT);
12928 default:
12929 return 0;
12930 }
c8023011 12931}
ee890fe2
SS
12932#endif
12933
12934#ifdef RS6000_LONG_BRANCH
12935
12936static tree stub_list = 0;
12937
12938/* ADD_COMPILER_STUB adds the compiler generated stub for handling
12939 procedure calls to the linked list. */
12940
12941void
12942add_compiler_stub (label_name, function_name, line_number)
12943 tree label_name;
12944 tree function_name;
12945 int line_number;
12946{
12947 tree stub = build_tree_list (function_name, label_name);
12948 TREE_TYPE (stub) = build_int_2 (line_number, 0);
12949 TREE_CHAIN (stub) = stub_list;
12950 stub_list = stub;
12951}
12952
12953#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
12954#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
12955#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
12956
a4f6c312
SS
12957/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
12958 handling procedure calls from the linked list and initializes the
12959 linked list. */
ee890fe2 12960
a4f6c312
SS
12961void
12962output_compiler_stub ()
ee890fe2
SS
12963{
12964 char tmp_buf[256];
12965 char label_buf[256];
308c142a 12966 tree stub;
ee890fe2
SS
12967
12968 if (!flag_pic)
12969 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
12970 {
12971 fprintf (asm_out_file,
12972 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
12973
12974#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12975 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12976 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
12977#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
12978
12979 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
12980 strcpy (label_buf,
12981 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
12982 else
12983 {
12984 label_buf[0] = '_';
12985 strcpy (label_buf+1,
12986 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
12987 }
12988
12989 strcpy (tmp_buf, "lis r12,hi16(");
12990 strcat (tmp_buf, label_buf);
12991 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
12992 strcat (tmp_buf, label_buf);
12993 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
12994 output_asm_insn (tmp_buf, 0);
12995
12996#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12997 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12998 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
12999#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
13000 }
13001
13002 stub_list = 0;
13003}
13004
13005/* NO_PREVIOUS_DEF checks in the link list whether the function name is
13006 already there or not. */
13007
a4f6c312
SS
13008int
13009no_previous_def (function_name)
ee890fe2
SS
13010 tree function_name;
13011{
13012 tree stub;
13013 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13014 if (function_name == STUB_FUNCTION_NAME (stub))
13015 return 0;
13016 return 1;
13017}
13018
13019/* GET_PREV_LABEL gets the label name from the previous definition of
13020 the function. */
13021
a4f6c312
SS
13022tree
13023get_prev_label (function_name)
ee890fe2
SS
13024 tree function_name;
13025{
13026 tree stub;
13027 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13028 if (function_name == STUB_FUNCTION_NAME (stub))
13029 return STUB_LABEL_NAME (stub);
13030 return 0;
13031}
13032
13033/* INSN is either a function call or a millicode call. It may have an
13034 unconditional jump in its delay slot.
13035
13036 CALL_DEST is the routine we are calling. */
13037
13038char *
13039output_call (insn, call_dest, operand_number)
13040 rtx insn;
13041 rtx call_dest;
13042 int operand_number;
13043{
13044 static char buf[256];
13045 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
13046 {
13047 tree labelname;
13048 tree funname = get_identifier (XSTR (call_dest, 0));
13049
13050 if (no_previous_def (funname))
13051 {
308c142a 13052 int line_number = 0;
ee890fe2
SS
13053 rtx label_rtx = gen_label_rtx ();
13054 char *label_buf, temp_buf[256];
13055 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
13056 CODE_LABEL_NUMBER (label_rtx));
13057 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
13058 labelname = get_identifier (label_buf);
13059 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
13060 if (insn)
13061 line_number = NOTE_LINE_NUMBER (insn);
13062 add_compiler_stub (labelname, funname, line_number);
13063 }
13064 else
13065 labelname = get_prev_label (funname);
13066
13067 sprintf (buf, "jbsr %%z%d,%.246s",
13068 operand_number, IDENTIFIER_POINTER (labelname));
13069 return buf;
13070 }
13071 else
13072 {
13073 sprintf (buf, "bl %%z%d", operand_number);
13074 return buf;
13075 }
13076}
13077
13078#endif /* RS6000_LONG_BRANCH */
13079
13080#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
13081 do { \
83182544 13082 const char *const symbol_ = (SYMBOL); \
ee890fe2
SS
13083 char *buffer_ = (BUF); \
13084 if (symbol_[0] == '"') \
13085 { \
13086 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
13087 } \
13088 else if (name_needs_quotes(symbol_)) \
13089 { \
13090 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
13091 } \
13092 else \
13093 { \
13094 sprintf(buffer_, "L%d$%s", (N), symbol_); \
13095 } \
13096 } while (0)
13097
13098
13099/* Generate PIC and indirect symbol stubs. */
13100
13101void
13102machopic_output_stub (file, symb, stub)
13103 FILE *file;
13104 const char *symb, *stub;
13105{
13106 unsigned int length;
a4f6c312
SS
13107 char *symbol_name, *lazy_ptr_name;
13108 char *local_label_0;
ee890fe2
SS
13109 static int label = 0;
13110
df56a27f 13111 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 13112 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 13113
ee890fe2
SS
13114 label += 1;
13115
ee890fe2
SS
13116 length = strlen (symb);
13117 symbol_name = alloca (length + 32);
13118 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
13119
13120 lazy_ptr_name = alloca (length + 32);
13121 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
13122
13123 local_label_0 = alloca (length + 32);
13124 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
13125
ee890fe2 13126 if (flag_pic == 2)
d3c300d2 13127 machopic_picsymbol_stub1_section ();
ee890fe2 13128 else
d3c300d2
DJ
13129 machopic_symbol_stub1_section ();
13130 fprintf (file, "\t.align 2\n");
ee890fe2
SS
13131
13132 fprintf (file, "%s:\n", stub);
13133 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13134
13135 if (flag_pic == 2)
13136 {
13137 fprintf (file, "\tmflr r0\n");
13138 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
13139 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
13140 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
13141 lazy_ptr_name, local_label_0);
13142 fprintf (file, "\tmtlr r0\n");
d3c300d2 13143 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
13144 lazy_ptr_name, local_label_0);
13145 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
13146 fprintf (file, "\tbctr\n");
13147 }
13148 else
ab82a49f
AP
13149 {
13150 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
13151 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
13152 fprintf (file, "\tmtctr r12\n");
13153 fprintf (file, "\tbctr\n");
13154 }
ee890fe2
SS
13155
13156 machopic_lazy_symbol_ptr_section ();
13157 fprintf (file, "%s:\n", lazy_ptr_name);
13158 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13159 fprintf (file, "\t.long dyld_stub_binding_helper\n");
13160}
13161
13162/* Legitimize PIC addresses. If the address is already
13163 position-independent, we return ORIG. Newly generated
13164 position-independent addresses go into a reg. This is REG if non
13165 zero, otherwise we allocate register(s) as necessary. */
13166
c859cda6 13167#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
13168
13169rtx
13170rs6000_machopic_legitimize_pic_address (orig, mode, reg)
13171 rtx orig;
13172 enum machine_mode mode;
13173 rtx reg;
13174{
13175 rtx base, offset;
13176
13177 if (reg == NULL && ! reload_in_progress && ! reload_completed)
13178 reg = gen_reg_rtx (Pmode);
13179
13180 if (GET_CODE (orig) == CONST)
13181 {
13182 if (GET_CODE (XEXP (orig, 0)) == PLUS
13183 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
13184 return orig;
13185
13186 if (GET_CODE (XEXP (orig, 0)) == PLUS)
13187 {
a4f6c312
SS
13188 base =
13189 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
13190 Pmode, reg);
13191 offset =
13192 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
13193 Pmode, reg);
ee890fe2
SS
13194 }
13195 else
13196 abort ();
13197
13198 if (GET_CODE (offset) == CONST_INT)
13199 {
13200 if (SMALL_INT (offset))
ed8908e7 13201 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
13202 else if (! reload_in_progress && ! reload_completed)
13203 offset = force_reg (Pmode, offset);
13204 else
c859cda6
DJ
13205 {
13206 rtx mem = force_const_mem (Pmode, orig);
13207 return machopic_legitimize_pic_address (mem, Pmode, reg);
13208 }
ee890fe2
SS
13209 }
13210 return gen_rtx (PLUS, Pmode, base, offset);
13211 }
13212
13213 /* Fall back on generic machopic code. */
13214 return machopic_legitimize_pic_address (orig, mode, reg);
13215}
13216
13217/* This is just a placeholder to make linking work without having to
13218 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
13219 ever needed for Darwin (not too likely!) this would have to get a
13220 real definition. */
13221
13222void
13223toc_section ()
13224{
13225}
13226
13227#endif /* TARGET_MACHO */
7c262518
RH
13228
13229#if TARGET_ELF
13230static unsigned int
13231rs6000_elf_section_type_flags (decl, name, reloc)
13232 tree decl;
13233 const char *name;
13234 int reloc;
13235{
5add3202
DE
13236 unsigned int flags
13237 = default_section_type_flags_1 (decl, name, reloc,
13238 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 13239
270fc29b
RH
13240 if (TARGET_RELOCATABLE)
13241 flags |= SECTION_WRITE;
7c262518 13242
d0101753 13243 return flags;
7c262518 13244}
d9f6800d
RH
13245
13246/* Record an element in the table of global constructors. SYMBOL is
13247 a SYMBOL_REF of the function to be called; PRIORITY is a number
13248 between 0 and MAX_INIT_PRIORITY.
13249
13250 This differs from default_named_section_asm_out_constructor in
13251 that we have special handling for -mrelocatable. */
13252
13253static void
13254rs6000_elf_asm_out_constructor (symbol, priority)
13255 rtx symbol;
13256 int priority;
13257{
13258 const char *section = ".ctors";
13259 char buf[16];
13260
13261 if (priority != DEFAULT_INIT_PRIORITY)
13262 {
13263 sprintf (buf, ".ctors.%.5u",
13264 /* Invert the numbering so the linker puts us in the proper
13265 order; constructors are run from right to left, and the
13266 linker sorts in increasing order. */
13267 MAX_INIT_PRIORITY - priority);
13268 section = buf;
13269 }
13270
715bdd29
RH
13271 named_section_flags (section, SECTION_WRITE);
13272 assemble_align (POINTER_SIZE);
d9f6800d
RH
13273
13274 if (TARGET_RELOCATABLE)
13275 {
13276 fputs ("\t.long (", asm_out_file);
13277 output_addr_const (asm_out_file, symbol);
13278 fputs (")@fixup\n", asm_out_file);
13279 }
13280 else
c8af3574 13281 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
13282}
13283
13284static void
13285rs6000_elf_asm_out_destructor (symbol, priority)
13286 rtx symbol;
13287 int priority;
13288{
13289 const char *section = ".dtors";
13290 char buf[16];
13291
13292 if (priority != DEFAULT_INIT_PRIORITY)
13293 {
13294 sprintf (buf, ".dtors.%.5u",
13295 /* Invert the numbering so the linker puts us in the proper
13296 order; constructors are run from right to left, and the
13297 linker sorts in increasing order. */
13298 MAX_INIT_PRIORITY - priority);
13299 section = buf;
13300 }
13301
715bdd29
RH
13302 named_section_flags (section, SECTION_WRITE);
13303 assemble_align (POINTER_SIZE);
d9f6800d
RH
13304
13305 if (TARGET_RELOCATABLE)
13306 {
13307 fputs ("\t.long (", asm_out_file);
13308 output_addr_const (asm_out_file, symbol);
13309 fputs (")@fixup\n", asm_out_file);
13310 }
13311 else
c8af3574 13312 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 13313}
7c262518
RH
13314#endif
13315
cbaaba19 13316#if TARGET_XCOFF
7c262518 13317static void
b275d088
DE
13318rs6000_xcoff_asm_globalize_label (stream, name)
13319 FILE *stream;
13320 const char *name;
13321{
13322 fputs (GLOBAL_ASM_OP, stream);
13323 RS6000_OUTPUT_BASENAME (stream, name);
13324 putc ('\n', stream);
13325}
13326
13327static void
13328rs6000_xcoff_asm_named_section (name, flags)
7c262518 13329 const char *name;
0e5dbd9b 13330 unsigned int flags;
7c262518 13331{
0e5dbd9b
DE
13332 int smclass;
13333 static const char * const suffix[3] = { "PR", "RO", "RW" };
13334
13335 if (flags & SECTION_CODE)
13336 smclass = 0;
13337 else if (flags & SECTION_WRITE)
13338 smclass = 2;
13339 else
13340 smclass = 1;
13341
5b5198f7 13342 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 13343 (flags & SECTION_CODE) ? "." : "",
5b5198f7 13344 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 13345}
ae46c4e0
RH
13346
13347static void
0e5dbd9b
DE
13348rs6000_xcoff_select_section (decl, reloc, align)
13349 tree decl;
ae46c4e0
RH
13350 int reloc;
13351 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13352{
5add3202 13353 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 13354 {
0e5dbd9b 13355 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13356 read_only_data_section ();
13357 else
13358 read_only_private_data_section ();
13359 }
13360 else
13361 {
0e5dbd9b 13362 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13363 data_section ();
13364 else
13365 private_data_section ();
13366 }
13367}
13368
13369static void
13370rs6000_xcoff_unique_section (decl, reloc)
13371 tree decl;
772c5265 13372 int reloc ATTRIBUTE_UNUSED;
ae46c4e0
RH
13373{
13374 const char *name;
ae46c4e0 13375
5b5198f7
DE
13376 /* Use select_section for private and uninitialized data. */
13377 if (!TREE_PUBLIC (decl)
13378 || DECL_COMMON (decl)
0e5dbd9b
DE
13379 || DECL_INITIAL (decl) == NULL_TREE
13380 || DECL_INITIAL (decl) == error_mark_node
13381 || (flag_zero_initialized_in_bss
13382 && initializer_zerop (DECL_INITIAL (decl))))
13383 return;
13384
13385 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
13386 name = (*targetm.strip_name_encoding) (name);
13387 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 13388}
b64a1b53 13389
fb49053f
RH
13390/* Select section for constant in constant pool.
13391
13392 On RS/6000, all constants are in the private read-only data area.
13393 However, if this is being placed in the TOC it must be output as a
13394 toc entry. */
13395
b64a1b53
RH
13396static void
13397rs6000_xcoff_select_rtx_section (mode, x, align)
13398 enum machine_mode mode;
13399 rtx x;
13400 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13401{
13402 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
13403 toc_section ();
13404 else
13405 read_only_private_data_section ();
13406}
772c5265
RH
13407
13408/* Remove any trailing [DS] or the like from the symbol name. */
13409
13410static const char *
13411rs6000_xcoff_strip_name_encoding (name)
13412 const char *name;
13413{
13414 size_t len;
13415 if (*name == '*')
13416 name++;
13417 len = strlen (name);
13418 if (name[len - 1] == ']')
13419 return ggc_alloc_string (name, len - 4);
13420 else
13421 return name;
13422}
13423
5add3202
DE
13424/* Section attributes. AIX is always PIC. */
13425
13426static unsigned int
13427rs6000_xcoff_section_type_flags (decl, name, reloc)
13428 tree decl;
13429 const char *name;
13430 int reloc;
13431{
5b5198f7
DE
13432 unsigned int align;
13433 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
13434
13435 /* Align to at least UNIT size. */
13436 if (flags & SECTION_CODE)
13437 align = MIN_UNITS_PER_WORD;
13438 else
13439 /* Increase alignment of large objects if not already stricter. */
13440 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
13441 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
13442 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
13443
13444 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202
DE
13445}
13446
fb49053f
RH
13447static void
13448rs6000_xcoff_encode_section_info (decl, first)
13449 tree decl;
13450 int first ATTRIBUTE_UNUSED;
13451{
13452 if (TREE_CODE (decl) == FUNCTION_DECL
b629ba0c 13453 && (*targetm.binds_local_p) (decl))
fb49053f
RH
13454 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
13455}
f1384257 13456#endif /* TARGET_XCOFF */
0e5dbd9b 13457
f1384257
AM
13458#if TARGET_MACHO
13459/* Cross-module name binding. Darwin does not support overriding
7f3d8013 13460 functions at dynamic-link time. */
0e5dbd9b 13461
2bcc50d0 13462static bool
0e5dbd9b
DE
13463rs6000_binds_local_p (decl)
13464 tree decl;
13465{
f1384257 13466 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 13467}
f1384257 13468#endif
34bb030a 13469
3c50106f
RH
13470/* Compute a (partial) cost for rtx X. Return true if the complete
13471 cost has been computed, and false if subexpressions should be
13472 scanned. In either case, *TOTAL contains the cost result. */
13473
13474static bool
13475rs6000_rtx_costs (x, code, outer_code, total)
13476 rtx x;
13477 int code, outer_code ATTRIBUTE_UNUSED;
13478 int *total;
13479{
13480 switch (code)
13481 {
13482 /* On the RS/6000, if it is valid in the insn, it is free.
13483 So this always returns 0. */
13484 case CONST_INT:
13485 case CONST:
13486 case LABEL_REF:
13487 case SYMBOL_REF:
13488 case CONST_DOUBLE:
13489 case HIGH:
13490 *total = 0;
13491 return true;
13492
13493 case PLUS:
13494 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13495 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
13496 + 0x8000) >= 0x10000)
13497 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13498 ? COSTS_N_INSNS (2)
13499 : COSTS_N_INSNS (1));
13500 return true;
13501
13502 case AND:
13503 case IOR:
13504 case XOR:
13505 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13506 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
13507 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13508 ? COSTS_N_INSNS (2)
13509 : COSTS_N_INSNS (1));
13510 return true;
13511
13512 case MULT:
13513 if (optimize_size)
13514 {
13515 *total = COSTS_N_INSNS (2);
13516 return true;
13517 }
13518 switch (rs6000_cpu)
13519 {
13520 case PROCESSOR_RIOS1:
13521 case PROCESSOR_PPC405:
13522 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13523 ? COSTS_N_INSNS (5)
13524 : (INTVAL (XEXP (x, 1)) >= -256
13525 && INTVAL (XEXP (x, 1)) <= 255)
13526 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13527 return true;
13528
13529 case PROCESSOR_RS64A:
13530 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13531 ? GET_MODE (XEXP (x, 1)) != DImode
13532 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
13533 : (INTVAL (XEXP (x, 1)) >= -256
13534 && INTVAL (XEXP (x, 1)) <= 255)
13535 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
13536 return true;
13537
13538 case PROCESSOR_RIOS2:
13539 case PROCESSOR_MPCCORE:
13540 case PROCESSOR_PPC604e:
13541 *total = COSTS_N_INSNS (2);
13542 return true;
13543
13544 case PROCESSOR_PPC601:
13545 *total = COSTS_N_INSNS (5);
13546 return true;
13547
13548 case PROCESSOR_PPC603:
13549 case PROCESSOR_PPC7400:
13550 case PROCESSOR_PPC750:
13551 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13552 ? COSTS_N_INSNS (5)
13553 : (INTVAL (XEXP (x, 1)) >= -256
13554 && INTVAL (XEXP (x, 1)) <= 255)
13555 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
13556 return true;
13557
13558 case PROCESSOR_PPC7450:
13559 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13560 ? COSTS_N_INSNS (4)
13561 : COSTS_N_INSNS (3));
13562 return true;
13563
13564 case PROCESSOR_PPC403:
13565 case PROCESSOR_PPC604:
13566 case PROCESSOR_PPC8540:
13567 *total = COSTS_N_INSNS (4);
13568 return true;
13569
13570 case PROCESSOR_PPC620:
13571 case PROCESSOR_PPC630:
13572 case PROCESSOR_POWER4:
13573 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13574 ? GET_MODE (XEXP (x, 1)) != DImode
13575 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
13576 : (INTVAL (XEXP (x, 1)) >= -256
13577 && INTVAL (XEXP (x, 1)) <= 255)
13578 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13579 return true;
13580
13581 default:
13582 abort ();
13583 }
13584
13585 case DIV:
13586 case MOD:
13587 if (GET_CODE (XEXP (x, 1)) == CONST_INT
13588 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
13589 {
13590 *total = COSTS_N_INSNS (2);
13591 return true;
13592 }
13593 /* FALLTHRU */
13594
13595 case UDIV:
13596 case UMOD:
13597 switch (rs6000_cpu)
13598 {
13599 case PROCESSOR_RIOS1:
13600 *total = COSTS_N_INSNS (19);
13601 return true;
13602
13603 case PROCESSOR_RIOS2:
13604 *total = COSTS_N_INSNS (13);
13605 return true;
13606
13607 case PROCESSOR_RS64A:
13608 *total = (GET_MODE (XEXP (x, 1)) != DImode
13609 ? COSTS_N_INSNS (65)
13610 : COSTS_N_INSNS (67));
13611 return true;
13612
13613 case PROCESSOR_MPCCORE:
13614 *total = COSTS_N_INSNS (6);
13615 return true;
13616
13617 case PROCESSOR_PPC403:
13618 *total = COSTS_N_INSNS (33);
13619 return true;
13620
13621 case PROCESSOR_PPC405:
13622 *total = COSTS_N_INSNS (35);
13623 return true;
13624
13625 case PROCESSOR_PPC601:
13626 *total = COSTS_N_INSNS (36);
13627 return true;
13628
13629 case PROCESSOR_PPC603:
13630 *total = COSTS_N_INSNS (37);
13631 return true;
13632
13633 case PROCESSOR_PPC604:
13634 case PROCESSOR_PPC604e:
13635 *total = COSTS_N_INSNS (20);
13636 return true;
13637
13638 case PROCESSOR_PPC620:
13639 case PROCESSOR_PPC630:
13640 case PROCESSOR_POWER4:
13641 *total = (GET_MODE (XEXP (x, 1)) != DImode
13642 ? COSTS_N_INSNS (21)
13643 : COSTS_N_INSNS (37));
13644 return true;
13645
13646 case PROCESSOR_PPC750:
13647 case PROCESSOR_PPC8540:
13648 case PROCESSOR_PPC7400:
13649 *total = COSTS_N_INSNS (19);
13650 return true;
13651
13652 case PROCESSOR_PPC7450:
13653 *total = COSTS_N_INSNS (23);
13654 return true;
13655
13656 default:
13657 abort ();
13658 }
13659
13660 case FFS:
13661 *total = COSTS_N_INSNS (4);
13662 return true;
13663
13664 case MEM:
13665 /* MEM should be slightly more expensive than (plus (reg) (const)) */
13666 *total = 5;
13667 return true;
13668
13669 default:
13670 return false;
13671 }
13672}
13673
34bb030a
DE
13674/* A C expression returning the cost of moving data from a register of class
13675 CLASS1 to one of CLASS2. */
13676
13677int
13678rs6000_register_move_cost (mode, from, to)
13679 enum machine_mode mode;
13680 enum reg_class from, to;
13681{
13682 /* Moves from/to GENERAL_REGS. */
13683 if (reg_classes_intersect_p (to, GENERAL_REGS)
13684 || reg_classes_intersect_p (from, GENERAL_REGS))
13685 {
13686 if (! reg_classes_intersect_p (to, GENERAL_REGS))
13687 from = to;
13688
13689 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
13690 return (rs6000_memory_move_cost (mode, from, 0)
13691 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
13692
13693/* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/
13694 else if (from == CR_REGS)
13695 return 4;
13696
13697 else
13698/* A move will cost one instruction per GPR moved. */
13699 return 2 * HARD_REGNO_NREGS (0, mode);
13700 }
13701
13702/* Moving between two similar registers is just one instruction. */
13703 else if (reg_classes_intersect_p (to, from))
13704 return mode == TFmode ? 4 : 2;
13705
13706/* Everything else has to go through GENERAL_REGS. */
13707 else
13708 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
13709 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
13710}
13711
13712/* A C expressions returning the cost of moving data of MODE from a register to
13713 or from memory. */
13714
13715int
13716rs6000_memory_move_cost (mode, class, in)
13717 enum machine_mode mode;
13718 enum reg_class class;
13719 int in ATTRIBUTE_UNUSED;
13720{
13721 if (reg_classes_intersect_p (class, GENERAL_REGS))
13722 return 4 * HARD_REGNO_NREGS (0, mode);
13723 else if (reg_classes_intersect_p (class, FLOAT_REGS))
13724 return 4 * HARD_REGNO_NREGS (32, mode);
13725 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
13726 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
13727 else
13728 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
13729}
13730
62e1dfcf
NC
13731/* Return true if TYPE is of type __ev64_opaque__. */
13732
c8e4f0e9 13733static bool
62e1dfcf
NC
13734is_ev64_opaque_type (type)
13735 tree type;
13736{
c8e4f0e9
AH
13737 return (TARGET_SPE
13738 && TREE_CODE (type) == VECTOR_TYPE
13739 && TYPE_NAME (type)
62e1dfcf
NC
13740 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13741 && DECL_NAME (TYPE_NAME (type))
13742 && strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
13743 "__ev64_opaque__") == 0);
13744}
13745
96714395
AH
13746static rtx
13747rs6000_dwarf_register_span (reg)
13748 rtx reg;
13749{
13750 unsigned regno;
13751
13752 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
13753 return NULL_RTX;
13754
13755 regno = REGNO (reg);
13756
13757 /* The duality of the SPE register size wreaks all kinds of havoc.
13758 This is a way of distinguishing r0 in 32-bits from r0 in
13759 64-bits. */
13760 return
13761 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
13762 BYTES_BIG_ENDIAN
13763 ? gen_rtvec (2,
13764 gen_rtx_REG (SImode, regno + 1200),
13765 gen_rtx_REG (SImode, regno))
13766 : gen_rtvec (2,
13767 gen_rtx_REG (SImode, regno),
13768 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
13769}
13770
17211ab5 13771#include "gt-rs6000.h"