]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): Extended checking before enabling gnu model.
[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,
63b6e069 3 2000, 2001 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"
9878760c
RK
25#include "rtl.h"
26#include "regs.h"
27#include "hard-reg-set.h"
28#include "real.h"
29#include "insn-config.h"
30#include "conditions.h"
9878760c
RK
31#include "insn-attr.h"
32#include "flags.h"
33#include "recog.h"
9878760c 34#include "obstack.h"
9b30bae2 35#include "tree.h"
dfafc897 36#include "expr.h"
2fc1c679 37#include "optabs.h"
2a430ec1 38#include "except.h"
a7df97e6 39#include "function.h"
296b8152 40#include "output.h"
d5fa86ba 41#include "basic-block.h"
d0101753 42#include "integrate.h"
296b8152 43#include "toplev.h"
c8023011 44#include "ggc.h"
9ebbca7d
GK
45#include "hashtab.h"
46#include "tm_p.h"
672a6f42
NB
47#include "target.h"
48#include "target-def.h"
3ac88239 49#include "langhooks.h"
9b30bae2 50
7509c759
MM
51#ifndef TARGET_NO_PROTOTYPE
52#define TARGET_NO_PROTOTYPE 0
53#endif
54
9878760c
RK
55#define min(A,B) ((A) < (B) ? (A) : (B))
56#define max(A,B) ((A) > (B) ? (A) : (B))
57
5248c961
RK
58/* Target cpu type */
59
60enum processor_type rs6000_cpu;
8e3f41e7
MM
61struct rs6000_cpu_select rs6000_select[3] =
62{
815cdc52
MM
63 /* switch name, tune arch */
64 { (const char *)0, "--with-cpu=", 1, 1 },
65 { (const char *)0, "-mcpu=", 1, 1 },
66 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 67};
5248c961 68
6fa3f289
ZW
69/* Size of long double */
70const char *rs6000_long_double_size_string;
71int rs6000_long_double_type_size;
72
73/* Whether -mabi=altivec has appeared */
74int rs6000_altivec_abi;
75
c764f757
RK
76/* Set to non-zero once AIX common-mode calls have been defined. */
77static int common_mode_defined;
c81bebd7 78
9878760c
RK
79/* Save information from a "cmpxx" operation until the branch or scc is
80 emitted. */
9878760c
RK
81rtx rs6000_compare_op0, rs6000_compare_op1;
82int rs6000_compare_fp_p;
874a0744 83
874a0744
MM
84/* Label number of label created for -mrelocatable, to call to so we can
85 get the address of the GOT section */
86int rs6000_pic_labelno;
c81bebd7 87
b91da81f 88#ifdef USING_ELFOS_H
c81bebd7 89/* Which abi to adhere to */
815cdc52 90const char *rs6000_abi_name = RS6000_ABI_NAME;
d9407988
MM
91
92/* Semantics of the small data area */
93enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
94
95/* Which small data model to use */
815cdc52 96const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
97
98/* Counter for labels which are to be placed in .fixup. */
99int fixuplabelno = 0;
874a0744 100#endif
4697a36c 101
b6c9286a
MM
102/* ABI enumeration available for subtarget to use. */
103enum rs6000_abi rs6000_current_abi;
104
0ac081f6
AH
105/* ABI string from -mabi= option. */
106const char *rs6000_abi_string;
107
38c1f2d7 108/* Debug flags */
815cdc52 109const char *rs6000_debug_name;
38c1f2d7
MM
110int rs6000_debug_stack; /* debug stack applications */
111int rs6000_debug_arg; /* debug argument handling */
112
113/* Flag to say the TOC is initialized */
114int toc_initialized;
9ebbca7d 115char toc_label_name[10];
38c1f2d7 116
9ebbca7d
GK
117/* Alias set for saves and restores from the rs6000 stack. */
118static int rs6000_sr_alias_set;
c8023011 119
9ebbca7d
GK
120static void rs6000_add_gc_roots PARAMS ((void));
121static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
122static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx));
39a10a29
GK
123static void validate_condition_mode
124 PARAMS ((enum rtx_code, enum machine_mode));
125static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
e50f5f3d 126static void rs6000_maybe_dead PARAMS ((rtx));
9ebbca7d
GK
127static void rs6000_emit_stack_tie PARAMS ((void));
128static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
129static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
130static unsigned rs6000_hash_constant PARAMS ((rtx));
131static unsigned toc_hash_function PARAMS ((const void *));
132static int toc_hash_eq PARAMS ((const void *, const void *));
2eba1afa 133static int toc_hash_mark_entry PARAMS ((void **, void *));
9ebbca7d
GK
134static void toc_hash_mark_table PARAMS ((void *));
135static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
6fee9e99
NC
136static void rs6000_free_machine_status PARAMS ((struct function *));
137static void rs6000_init_machine_status PARAMS ((struct function *));
301d03af 138static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
71f123ca 139static int rs6000_ra_ever_killed PARAMS ((void));
91d231cb
JM
140static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
141const struct attribute_spec rs6000_attribute_table[];
08c148a8
NB
142static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
143static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
2bfcf297
DB
144static rtx rs6000_emit_set_long_const PARAMS ((rtx,
145 HOST_WIDE_INT, HOST_WIDE_INT));
7c262518
RH
146#if TARGET_ELF
147static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
148 int));
d9f6800d
RH
149static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
150static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
7c262518
RH
151#endif
152#ifdef OBJECT_FORMAT_COFF
715bdd29 153static void xcoff_asm_named_section PARAMS ((const char *, unsigned int));
7c262518 154#endif
c237e94a
ZW
155static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
156static int rs6000_adjust_priority PARAMS ((rtx, int));
157static int rs6000_issue_rate PARAMS ((void));
158
6fa3f289 159static void rs6000_init_builtins PARAMS ((void));
0ac081f6
AH
160static void altivec_init_builtins PARAMS ((void));
161static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
00b960c7 162static rtx altivec_expand_builtin PARAMS ((tree, rtx));
2212663f 163static rtx altivec_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 164static rtx altivec_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
2212663f 165static rtx altivec_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 166static void rs6000_parse_abi_options PARAMS ((void));
00b960c7
AH
167static int first_altivec_reg_to_save PARAMS ((void));
168static unsigned int compute_vrsave_mask PARAMS ((void));
169static void is_altivec_return_reg PARAMS ((rtx, void *));
170int vrsave_operation PARAMS ((rtx, enum machine_mode));
9aa86737
AH
171static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
172static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
c81bebd7
MM
173\f
174/* Default register names. */
175char rs6000_reg_names[][8] =
176{
802a0058
MM
177 "0", "1", "2", "3", "4", "5", "6", "7",
178 "8", "9", "10", "11", "12", "13", "14", "15",
179 "16", "17", "18", "19", "20", "21", "22", "23",
180 "24", "25", "26", "27", "28", "29", "30", "31",
181 "0", "1", "2", "3", "4", "5", "6", "7",
182 "8", "9", "10", "11", "12", "13", "14", "15",
183 "16", "17", "18", "19", "20", "21", "22", "23",
184 "24", "25", "26", "27", "28", "29", "30", "31",
185 "mq", "lr", "ctr","ap",
186 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
187 "xer",
188 /* AltiVec registers. */
0cd5e3a1
AH
189 "0", "1", "2", "3", "4", "5", "6", "7",
190 "8", "9", "10", "11", "12", "13", "14", "15",
191 "16", "17", "18", "19", "20", "21", "22", "23",
192 "24", "25", "26", "27", "28", "29", "30", "31",
0ac081f6 193 "vrsave"
c81bebd7
MM
194};
195
196#ifdef TARGET_REGNAMES
8b60264b 197static const char alt_reg_names[][8] =
c81bebd7 198{
802a0058
MM
199 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
200 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
201 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
202 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
203 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
204 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
205 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
206 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
207 "mq", "lr", "ctr", "ap",
208 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6
AH
209 "xer",
210 /* AltiVec registers. */
211 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
212 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
213 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
214 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
215 "%vrsave"
c81bebd7
MM
216};
217#endif
9878760c 218\f
daf11973
MM
219#ifndef MASK_STRICT_ALIGN
220#define MASK_STRICT_ALIGN 0
221#endif
672a6f42
NB
222\f
223/* Initialize the GCC target structure. */
91d231cb
JM
224#undef TARGET_ATTRIBUTE_TABLE
225#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
daf11973 226
301d03af
RS
227#undef TARGET_ASM_ALIGNED_DI_OP
228#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
229
230/* Default unaligned ops are only provided for ELF. Find the ops needed
231 for non-ELF systems. */
232#ifndef OBJECT_FORMAT_ELF
233#ifdef OBJECT_FORMAT_COFF
234/* For ECOFF. rs6000_assemble_integer will handle unaligned DIs on
235 64-bit targets. */
236#undef TARGET_ASM_UNALIGNED_HI_OP
237#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
238#undef TARGET_ASM_UNALIGNED_SI_OP
239#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
240#undef TARGET_ASM_UNALIGNED_DI_OP
241#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
242#else
243/* For Darwin. */
244#undef TARGET_ASM_UNALIGNED_HI_OP
245#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
246#undef TARGET_ASM_UNALIGNED_SI_OP
247#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
248#endif
249#endif
250
251/* This hook deals with fixups for relocatable code and DI-mode objects
252 in 64-bit code. */
253#undef TARGET_ASM_INTEGER
254#define TARGET_ASM_INTEGER rs6000_assemble_integer
255
08c148a8
NB
256#undef TARGET_ASM_FUNCTION_PROLOGUE
257#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
258#undef TARGET_ASM_FUNCTION_EPILOGUE
259#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
260
7c262518
RH
261#if TARGET_ELF
262#undef TARGET_SECTION_TYPE_FLAGS
263#define TARGET_SECTION_TYPE_FLAGS rs6000_elf_section_type_flags
264#endif
265
c237e94a
ZW
266#undef TARGET_SCHED_ISSUE_RATE
267#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
268#undef TARGET_SCHED_ADJUST_COST
269#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
270#undef TARGET_SCHED_ADJUST_PRIORITY
271#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
272
0ac081f6
AH
273#undef TARGET_INIT_BUILTINS
274#define TARGET_INIT_BUILTINS rs6000_init_builtins
275
276#undef TARGET_EXPAND_BUILTIN
277#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
278
00b960c7
AH
279/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
280#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
281
f6897b10 282struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 283\f
5248c961
RK
284/* Override command line options. Mostly we process the processor
285 type and sometimes adjust other TARGET_ options. */
286
287void
8e3f41e7 288rs6000_override_options (default_cpu)
d330fd93 289 const char *default_cpu;
5248c961 290{
c4d38ccb 291 size_t i, j;
8e3f41e7 292 struct rs6000_cpu_select *ptr;
5248c961 293
85638c0d
RK
294 /* Simplify the entries below by making a mask for any POWER
295 variant and any PowerPC variant. */
296
938937d8 297#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
298#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
299 | MASK_PPC_GFXOPT | MASK_POWERPC64)
300#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 301
5248c961
RK
302 static struct ptt
303 {
8b60264b
KG
304 const char *const name; /* Canonical processor name. */
305 const enum processor_type processor; /* Processor type enum value. */
306 const int target_enable; /* Target flags to enable. */
307 const int target_disable; /* Target flags to disable. */
308 } const processor_target_table[]
cf27b467
MM
309 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
310 POWER_MASKS | POWERPC_MASKS},
db7f1e43 311 {"power", PROCESSOR_POWER,
938937d8 312 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 313 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
314 {"power2", PROCESSOR_POWER,
315 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
316 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
317 {"power3", PROCESSOR_PPC630,
318 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
319 POWER_MASKS | MASK_PPC_GPOPT},
db7f1e43
RK
320 {"powerpc", PROCESSOR_POWERPC,
321 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 322 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
323 {"powerpc64", PROCESSOR_POWERPC64,
324 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
325 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 326 {"rios", PROCESSOR_RIOS1,
938937d8 327 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
328 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
329 {"rios1", PROCESSOR_RIOS1,
938937d8 330 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
331 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
332 {"rsc", PROCESSOR_PPC601,
938937d8 333 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
334 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
335 {"rsc1", PROCESSOR_PPC601,
938937d8 336 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
337 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
338 {"rios2", PROCESSOR_RIOS2,
938937d8 339 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 340 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
341 {"rs64a", PROCESSOR_RS64A,
342 MASK_POWERPC | MASK_NEW_MNEMONICS,
343 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
344 {"401", PROCESSOR_PPC403,
345 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
346 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 347 {"403", PROCESSOR_PPC403,
daf11973 348 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 349 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
350 {"405", PROCESSOR_PPC405,
351 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
352 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
353 {"505", PROCESSOR_MPCCORE,
354 MASK_POWERPC | MASK_NEW_MNEMONICS,
355 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 356 {"601", PROCESSOR_PPC601,
938937d8 357 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 358 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 359 {"602", PROCESSOR_PPC603,
cf27b467
MM
360 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
361 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 362 {"603", PROCESSOR_PPC603,
68c49ffa
RK
363 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
364 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
365 {"603e", PROCESSOR_PPC603,
366 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
367 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 368 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
369 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
370 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 371 {"604", PROCESSOR_PPC604,
b6c9286a
MM
372 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
373 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 374 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
375 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
376 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 377 {"620", PROCESSOR_PPC620,
68c49ffa 378 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a260abc9 379 POWER_MASKS | MASK_PPC_GPOPT},
3cb999d8
DE
380 {"630", PROCESSOR_PPC630,
381 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
382 POWER_MASKS | MASK_PPC_GPOPT},
bef84347
VM
383 {"740", PROCESSOR_PPC750,
384 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
385 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
386 {"750", PROCESSOR_PPC750,
387 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
388 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
389 {"7400", PROCESSOR_PPC7400,
390 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
391 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
392 {"7450", PROCESSOR_PPC7450,
393 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
394 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
395 {"801", PROCESSOR_MPCCORE,
396 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
397 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
398 {"821", PROCESSOR_MPCCORE,
399 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
400 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
401 {"823", PROCESSOR_MPCCORE,
402 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
403 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
404 {"860", PROCESSOR_MPCCORE,
405 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
406 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 407
c4d38ccb 408 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
5248c961 409
a4f6c312
SS
410 /* Save current -mmultiple/-mno-multiple status. */
411 int multiple = TARGET_MULTIPLE;
412 /* Save current -mstring/-mno-string status. */
413 int string = TARGET_STRING;
8a61d227 414
a4f6c312 415 /* Identify the processor type. */
8e3f41e7 416 rs6000_select[0].string = default_cpu;
3cb999d8 417 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 418
b6a1cbae 419 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 420 {
8e3f41e7
MM
421 ptr = &rs6000_select[i];
422 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 423 {
8e3f41e7
MM
424 for (j = 0; j < ptt_size; j++)
425 if (! strcmp (ptr->string, processor_target_table[j].name))
426 {
427 if (ptr->set_tune_p)
428 rs6000_cpu = processor_target_table[j].processor;
429
430 if (ptr->set_arch_p)
431 {
432 target_flags |= processor_target_table[j].target_enable;
433 target_flags &= ~processor_target_table[j].target_disable;
434 }
435 break;
436 }
437
4406229e 438 if (j == ptt_size)
8e3f41e7 439 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
440 }
441 }
8a61d227 442
a4f6c312
SS
443 /* If we are optimizing big endian systems for space, use the store
444 multiple instructions. */
ef792183
MM
445 if (BYTES_BIG_ENDIAN && optimize_size)
446 target_flags |= MASK_MULTIPLE;
447
8a61d227
MM
448 /* If -mmultiple or -mno-multiple was explicitly used, don't
449 override with the processor default */
450 if (TARGET_MULTIPLE_SET)
451 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 452
a4f6c312
SS
453 /* If -mstring or -mno-string was explicitly used, don't override
454 with the processor default. */
938937d8 455 if (TARGET_STRING_SET)
1f5515bf 456 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 457
a4f6c312
SS
458 /* Don't allow -mmultiple or -mstring on little endian systems
459 unless the cpu is a 750, because the hardware doesn't support the
460 instructions used in little endian mode, and causes an alignment
461 trap. The 750 does not cause an alignment trap (except when the
462 target is unaligned). */
bef84347 463
bfc79d3b 464 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
465 {
466 if (TARGET_MULTIPLE)
467 {
468 target_flags &= ~MASK_MULTIPLE;
469 if (TARGET_MULTIPLE_SET)
470 warning ("-mmultiple is not supported on little endian systems");
471 }
472
473 if (TARGET_STRING)
474 {
475 target_flags &= ~MASK_STRING;
938937d8
MM
476 if (TARGET_STRING_SET)
477 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
478 }
479 }
3933e0e1 480
2bfcf297 481 if (flag_pic && DEFAULT_ABI == ABI_AIX)
a260abc9 482 {
2bfcf297 483 warning ("-f%s ignored (all code is position independent)",
a260abc9
DE
484 (flag_pic > 1) ? "PIC" : "pic");
485 flag_pic = 0;
486 }
487
2bfcf297 488#ifdef XCOFF_DEBUGGING_INFO
9861b0c9 489 if (flag_function_sections && (write_symbols != NO_DEBUG)
2bfcf297 490 && DEFAULT_ABI == ABI_AIX)
9861b0c9
DE
491 {
492 warning ("-ffunction-sections disabled on AIX when debugging");
493 flag_function_sections = 0;
494 }
495
496 if (flag_data_sections && (DEFAULT_ABI == ABI_AIX))
497 {
498 warning ("-fdata-sections not supported on AIX");
499 flag_data_sections = 0;
500 }
2bfcf297 501#endif
9861b0c9 502
38c1f2d7
MM
503 /* Set debug flags */
504 if (rs6000_debug_name)
505 {
bfc79d3b 506 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 507 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 508 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 509 rs6000_debug_stack = 1;
bfc79d3b 510 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
511 rs6000_debug_arg = 1;
512 else
c725bd79 513 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
514 }
515
6fa3f289
ZW
516 /* Set size of long double */
517 rs6000_long_double_type_size = 64;
518 if (rs6000_long_double_size_string)
519 {
520 char *tail;
521 int size = strtol (rs6000_long_double_size_string, &tail, 10);
522 if (*tail != '\0' || (size != 64 && size != 128))
523 error ("Unknown switch -mlong-double-%s",
524 rs6000_long_double_size_string);
525 else
526 rs6000_long_double_type_size = size;
527 }
528
0ac081f6
AH
529 /* Handle -mabi= options. */
530 rs6000_parse_abi_options ();
531
c81bebd7 532#ifdef TARGET_REGNAMES
a4f6c312
SS
533 /* If the user desires alternate register names, copy in the
534 alternate names now. */
c81bebd7 535 if (TARGET_REGNAMES)
4e135bdd 536 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
537#endif
538
3933e0e1
MM
539#ifdef SUBTARGET_OVERRIDE_OPTIONS
540 SUBTARGET_OVERRIDE_OPTIONS;
541#endif
10baca6b
AH
542#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
543 SUBSUBTARGET_OVERRIDE_OPTIONS;
544#endif
c8023011 545
6fa3f289
ZW
546 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
547 If -maix-struct-return or -msvr4-struct-return was explicitly
548 used, don't override with the ABI default. */
549 if (!(target_flags & MASK_AIX_STRUCT_RET_SET))
550 {
551 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
552 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
553 else
554 target_flags |= MASK_AIX_STRUCT_RET;
555 }
556
c8023011
MM
557 /* Register global variables with the garbage collector. */
558 rs6000_add_gc_roots ();
9ebbca7d
GK
559
560 /* Allocate an alias set for register saves & restores from stack. */
561 rs6000_sr_alias_set = new_alias_set ();
562
563 if (TARGET_TOC)
564 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 565
301d03af
RS
566 /* We can only guarantee the availability of DI pseudo-ops when
567 assembling for 64-bit targets. */
568 if (!TARGET_POWERPC64)
569 {
570 targetm.asm_out.aligned_op.di = NULL;
571 targetm.asm_out.unaligned_op.di = NULL;
572 }
573
71f123ca
FS
574 /* Arrange to save and restore machine status around nested functions. */
575 init_machine_status = rs6000_init_machine_status;
71f123ca 576 free_machine_status = rs6000_free_machine_status;
5248c961 577}
5accd822 578
0ac081f6 579/* Handle -mabi= options. */
00b960c7
AH
580static void
581rs6000_parse_abi_options ()
0ac081f6
AH
582{
583 if (rs6000_abi_string == 0)
584 return;
585 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 586 rs6000_altivec_abi = 1;
0ac081f6 587 else
c725bd79 588 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
589}
590
5accd822
DE
591void
592optimization_options (level, size)
e2c953b6 593 int level ATTRIBUTE_UNUSED;
5accd822
DE
594 int size ATTRIBUTE_UNUSED;
595{
5accd822 596}
3cfa4909
MM
597\f
598/* Do anything needed at the start of the asm file. */
599
600void
601rs6000_file_start (file, default_cpu)
602 FILE *file;
d330fd93 603 const char *default_cpu;
3cfa4909 604{
c4d38ccb 605 size_t i;
3cfa4909 606 char buffer[80];
d330fd93 607 const char *start = buffer;
3cfa4909
MM
608 struct rs6000_cpu_select *ptr;
609
610 if (flag_verbose_asm)
611 {
612 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
613 rs6000_select[0].string = default_cpu;
614
b6a1cbae 615 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
616 {
617 ptr = &rs6000_select[i];
618 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
619 {
620 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
621 start = "";
622 }
623 }
624
b91da81f 625#ifdef USING_ELFOS_H
3cfa4909
MM
626 switch (rs6000_sdata)
627 {
628 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
629 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
630 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
631 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
632 }
633
634 if (rs6000_sdata && g_switch_value)
635 {
636 fprintf (file, "%s -G %d", start, g_switch_value);
637 start = "";
638 }
639#endif
640
641 if (*start == '\0')
949ea356 642 putc ('\n', file);
3cfa4909
MM
643 }
644}
645
24d304eb
RK
646\f
647/* Create a CONST_DOUBLE from a string. */
648
649struct rtx_def *
650rs6000_float_const (string, mode)
d330fd93 651 const char *string;
24d304eb
RK
652 enum machine_mode mode;
653{
ca5adc63
GK
654 REAL_VALUE_TYPE value;
655 value = REAL_VALUE_ATOF (string, mode);
24d304eb
RK
656 return immed_real_const_1 (value, mode);
657}
5248c961 658\f
9878760c
RK
659/* Return non-zero if this function is known to have a null epilogue. */
660
661int
662direct_return ()
663{
4697a36c
MM
664 if (reload_completed)
665 {
666 rs6000_stack_t *info = rs6000_stack_info ();
667
668 if (info->first_gp_reg_save == 32
669 && info->first_fp_reg_save == 64
00b960c7 670 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
671 && ! info->lr_save_p
672 && ! info->cr_save_p
00b960c7 673 && info->vrsave_mask == 0
c81fc13e 674 && ! info->push_p)
4697a36c
MM
675 return 1;
676 }
677
678 return 0;
9878760c
RK
679}
680
681/* Returns 1 always. */
682
683int
684any_operand (op, mode)
592696dd 685 rtx op ATTRIBUTE_UNUSED;
296b8152 686 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
687{
688 return 1;
689}
690
a4f6c312 691/* Returns 1 if op is the count register. */
38c1f2d7 692int
a4f6c312 693count_register_operand (op, mode)
592696dd 694 rtx op;
296b8152 695 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
696{
697 if (GET_CODE (op) != REG)
698 return 0;
699
700 if (REGNO (op) == COUNT_REGISTER_REGNUM)
701 return 1;
702
703 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
704 return 1;
705
706 return 0;
707}
708
38c1f2d7 709int
a4f6c312 710xer_operand (op, mode)
592696dd 711 rtx op;
296b8152 712 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
713{
714 if (GET_CODE (op) != REG)
715 return 0;
716
9ebbca7d 717 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
718 return 1;
719
802a0058
MM
720 return 0;
721}
722
c859cda6
DJ
723/* Return 1 if OP is a signed 8-bit constant. Int multiplication
724 by such constants completes more quickly. */
725
726int
727s8bit_cint_operand (op, mode)
728 rtx op;
729 enum machine_mode mode ATTRIBUTE_UNUSED;
730{
731 return ( GET_CODE (op) == CONST_INT
732 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
733}
734
9878760c
RK
735/* Return 1 if OP is a constant that can fit in a D field. */
736
737int
738short_cint_operand (op, mode)
592696dd 739 rtx op;
296b8152 740 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 741{
5f59ecb7
DE
742 return (GET_CODE (op) == CONST_INT
743 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
744}
745
5519a4f9 746/* Similar for an unsigned D field. */
9878760c
RK
747
748int
749u_short_cint_operand (op, mode)
592696dd 750 rtx op;
296b8152 751 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 752{
19684119 753 return (GET_CODE (op) == CONST_INT
5f59ecb7 754 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
9878760c
RK
755}
756
dcfedcd0
RK
757/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
758
759int
760non_short_cint_operand (op, mode)
592696dd 761 rtx op;
296b8152 762 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
763{
764 return (GET_CODE (op) == CONST_INT
a7653a2c 765 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
766}
767
2bfcf297
DB
768/* Returns 1 if OP is a CONST_INT that is a positive value
769 and an exact power of 2. */
770
771int
772exact_log2_cint_operand (op, mode)
592696dd 773 rtx op;
2bfcf297
DB
774 enum machine_mode mode ATTRIBUTE_UNUSED;
775{
776 return (GET_CODE (op) == CONST_INT
777 && INTVAL (op) > 0
778 && exact_log2 (INTVAL (op)) >= 0);
779}
780
9878760c
RK
781/* Returns 1 if OP is a register that is not special (i.e., not MQ,
782 ctr, or lr). */
783
784int
cd2b37d9 785gpc_reg_operand (op, mode)
592696dd 786 rtx op;
9878760c
RK
787 enum machine_mode mode;
788{
789 return (register_operand (op, mode)
802a0058 790 && (GET_CODE (op) != REG
9ebbca7d
GK
791 || (REGNO (op) >= ARG_POINTER_REGNUM
792 && !XER_REGNO_P (REGNO (op)))
793 || REGNO (op) < MQ_REGNO));
9878760c
RK
794}
795
796/* Returns 1 if OP is either a pseudo-register or a register denoting a
797 CR field. */
798
799int
800cc_reg_operand (op, mode)
592696dd 801 rtx op;
9878760c
RK
802 enum machine_mode mode;
803{
804 return (register_operand (op, mode)
805 && (GET_CODE (op) != REG
806 || REGNO (op) >= FIRST_PSEUDO_REGISTER
807 || CR_REGNO_P (REGNO (op))));
808}
809
815cdc52
MM
810/* Returns 1 if OP is either a pseudo-register or a register denoting a
811 CR field that isn't CR0. */
812
813int
814cc_reg_not_cr0_operand (op, mode)
592696dd 815 rtx op;
815cdc52
MM
816 enum machine_mode mode;
817{
818 return (register_operand (op, mode)
819 && (GET_CODE (op) != REG
820 || REGNO (op) >= FIRST_PSEUDO_REGISTER
821 || CR_REGNO_NOT_CR0_P (REGNO (op))));
822}
823
a4f6c312
SS
824/* Returns 1 if OP is either a constant integer valid for a D-field or
825 a non-special register. If a register, it must be in the proper
826 mode unless MODE is VOIDmode. */
9878760c
RK
827
828int
829reg_or_short_operand (op, mode)
592696dd 830 rtx op;
9878760c
RK
831 enum machine_mode mode;
832{
f5a28898 833 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
834}
835
a4f6c312
SS
836/* Similar, except check if the negation of the constant would be
837 valid for a D-field. */
9878760c
RK
838
839int
840reg_or_neg_short_operand (op, mode)
592696dd 841 rtx op;
9878760c
RK
842 enum machine_mode mode;
843{
844 if (GET_CODE (op) == CONST_INT)
845 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
846
cd2b37d9 847 return gpc_reg_operand (op, mode);
9878760c
RK
848}
849
a4f6c312
SS
850/* Return 1 if the operand is either a register or an integer whose
851 high-order 16 bits are zero. */
9878760c
RK
852
853int
854reg_or_u_short_operand (op, mode)
592696dd 855 rtx op;
9878760c
RK
856 enum machine_mode mode;
857{
e675f625 858 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
859}
860
861/* Return 1 is the operand is either a non-special register or ANY
862 constant integer. */
863
864int
865reg_or_cint_operand (op, mode)
592696dd 866 rtx op;
9878760c
RK
867 enum machine_mode mode;
868{
a4f6c312 869 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
870}
871
872/* Return 1 is the operand is either a non-special register or ANY
873 32-bit signed constant integer. */
874
875int
876reg_or_arith_cint_operand (op, mode)
592696dd 877 rtx op;
f6bf7de2
DE
878 enum machine_mode mode;
879{
a4f6c312
SS
880 return (gpc_reg_operand (op, mode)
881 || (GET_CODE (op) == CONST_INT
f6bf7de2 882#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
883 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
884 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 885#endif
a4f6c312 886 ));
9878760c
RK
887}
888
2bfcf297
DB
889/* Return 1 is the operand is either a non-special register or a 32-bit
890 signed constant integer valid for 64-bit addition. */
891
892int
893reg_or_add_cint64_operand (op, mode)
592696dd 894 rtx op;
2bfcf297
DB
895 enum machine_mode mode;
896{
a4f6c312
SS
897 return (gpc_reg_operand (op, mode)
898 || (GET_CODE (op) == CONST_INT
899 && INTVAL (op) < 0x7fff8000
2bfcf297 900#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
901 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
902 < 0x100000000ll)
2bfcf297 903#endif
a4f6c312 904 ));
2bfcf297
DB
905}
906
907/* Return 1 is the operand is either a non-special register or a 32-bit
908 signed constant integer valid for 64-bit subtraction. */
909
910int
911reg_or_sub_cint64_operand (op, mode)
592696dd 912 rtx op;
2bfcf297
DB
913 enum machine_mode mode;
914{
a4f6c312
SS
915 return (gpc_reg_operand (op, mode)
916 || (GET_CODE (op) == CONST_INT
917 && (- INTVAL (op)) < 0x7fff8000
2bfcf297 918#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
919 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
920 < 0x100000000ll)
2bfcf297 921#endif
a4f6c312 922 ));
2bfcf297
DB
923}
924
9ebbca7d
GK
925/* Return 1 is the operand is either a non-special register or ANY
926 32-bit unsigned constant integer. */
927
928int
1d328b19 929reg_or_logical_cint_operand (op, mode)
592696dd 930 rtx op;
9ebbca7d
GK
931 enum machine_mode mode;
932{
1d328b19
GK
933 if (GET_CODE (op) == CONST_INT)
934 {
935 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
936 {
937 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 938 abort ();
1d328b19
GK
939
940 if (INTVAL (op) < 0)
941 return 0;
942 }
943
944 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 945 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
946 }
947 else if (GET_CODE (op) == CONST_DOUBLE)
948 {
949 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
950 || mode != DImode)
a4f6c312 951 abort ();
1d328b19
GK
952
953 return CONST_DOUBLE_HIGH (op) == 0;
954 }
955 else
956 return gpc_reg_operand (op, mode);
9ebbca7d
GK
957}
958
51d3e7d6 959/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
960
961int
962got_operand (op, mode)
592696dd 963 rtx op;
296b8152 964 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
965{
966 return (GET_CODE (op) == SYMBOL_REF
967 || GET_CODE (op) == CONST
968 || GET_CODE (op) == LABEL_REF);
969}
970
38c1f2d7
MM
971/* Return 1 if the operand is a simple references that can be loaded via
972 the GOT (labels involving addition aren't allowed). */
973
974int
975got_no_const_operand (op, mode)
592696dd 976 rtx op;
296b8152 977 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
978{
979 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
980}
981
4e74d8ec
MM
982/* Return the number of instructions it takes to form a constant in an
983 integer register. */
984
985static int
986num_insns_constant_wide (value)
987 HOST_WIDE_INT value;
988{
989 /* signed constant loadable with {cal|addi} */
5f59ecb7 990 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
991 return 1;
992
4e74d8ec 993 /* constant loadable with {cau|addis} */
5f59ecb7 994 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
995 return 1;
996
5f59ecb7 997#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 998 else if (TARGET_POWERPC64)
4e74d8ec 999 {
0d30d435 1000 HOST_WIDE_INT low = value & 0xffffffff;
4e74d8ec
MM
1001 HOST_WIDE_INT high = value >> 32;
1002
0d30d435
DE
1003 low = (low ^ 0x80000000) - 0x80000000; /* sign extend */
1004
0858c623 1005 if (high == 0 && (low & 0x80000000) == 0)
4e74d8ec
MM
1006 return 2;
1007
0858c623 1008 else if (high == -1 && (low & 0x80000000) != 0)
4e74d8ec
MM
1009 return 2;
1010
c81fc13e 1011 else if (! low)
4e74d8ec
MM
1012 return num_insns_constant_wide (high) + 1;
1013
1014 else
1015 return (num_insns_constant_wide (high)
e396202a 1016 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1017 }
1018#endif
1019
1020 else
1021 return 2;
1022}
1023
1024int
1025num_insns_constant (op, mode)
1026 rtx op;
1027 enum machine_mode mode;
1028{
4e74d8ec 1029 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1030 {
1031#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1032 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1033 && mask64_operand (op, mode))
0d30d435
DE
1034 return 2;
1035 else
1036#endif
1037 return num_insns_constant_wide (INTVAL (op));
1038 }
4e74d8ec 1039
6fc48950
MM
1040 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1041 {
1042 long l;
1043 REAL_VALUE_TYPE rv;
1044
1045 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1046 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1047 return num_insns_constant_wide ((HOST_WIDE_INT)l);
1048 }
1049
47ad8c61 1050 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1051 {
47ad8c61
MM
1052 HOST_WIDE_INT low;
1053 HOST_WIDE_INT high;
1054 long l[2];
1055 REAL_VALUE_TYPE rv;
1056 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1057
47ad8c61
MM
1058 if (mode == VOIDmode || mode == DImode)
1059 {
1060 high = CONST_DOUBLE_HIGH (op);
1061 low = CONST_DOUBLE_LOW (op);
1062 }
1063 else
1064 {
1065 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1066 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1067 high = l[endian];
1068 low = l[1 - endian];
1069 }
4e74d8ec 1070
47ad8c61
MM
1071 if (TARGET_32BIT)
1072 return (num_insns_constant_wide (low)
1073 + num_insns_constant_wide (high));
4e74d8ec
MM
1074
1075 else
47ad8c61 1076 {
0858c623 1077 if (high == 0 && (low & 0x80000000) == 0)
47ad8c61
MM
1078 return num_insns_constant_wide (low);
1079
0858c623 1080 else if (high == -1 && (low & 0x80000000) != 0)
47ad8c61
MM
1081 return num_insns_constant_wide (low);
1082
a260abc9
DE
1083 else if (mask64_operand (op, mode))
1084 return 2;
1085
47ad8c61
MM
1086 else if (low == 0)
1087 return num_insns_constant_wide (high) + 1;
1088
1089 else
1090 return (num_insns_constant_wide (high)
1091 + num_insns_constant_wide (low) + 1);
1092 }
4e74d8ec
MM
1093 }
1094
1095 else
1096 abort ();
1097}
1098
a4f6c312
SS
1099/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1100 register with one instruction per word. We only do this if we can
1101 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1102
1103int
1104easy_fp_constant (op, mode)
592696dd
SS
1105 rtx op;
1106 enum machine_mode mode;
9878760c 1107{
9878760c
RK
1108 if (GET_CODE (op) != CONST_DOUBLE
1109 || GET_MODE (op) != mode
4e74d8ec 1110 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1111 return 0;
1112
a4f6c312 1113 /* Consider all constants with -msoft-float to be easy. */
4e74d8ec 1114 if (TARGET_SOFT_FLOAT && mode != DImode)
b6c9286a
MM
1115 return 1;
1116
a4f6c312 1117 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1118 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1119 return 0;
1120
5ae4759c 1121#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1122 /* Similarly if we are using -mrelocatable, consider all constants
1123 to be hard. */
5ae4759c
MM
1124 if (TARGET_RELOCATABLE)
1125 return 0;
1126#endif
1127
042259f2
DE
1128 if (mode == DFmode)
1129 {
1130 long k[2];
1131 REAL_VALUE_TYPE rv;
1132
1133 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1134 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1135
4e74d8ec
MM
1136 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
1137 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
042259f2 1138 }
4e74d8ec
MM
1139
1140 else if (mode == SFmode)
042259f2
DE
1141 {
1142 long l;
1143 REAL_VALUE_TYPE rv;
1144
1145 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1146 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1147
4e74d8ec 1148 return num_insns_constant_wide (l) == 1;
042259f2 1149 }
4e74d8ec 1150
a260abc9 1151 else if (mode == DImode)
c81fc13e 1152 return ((TARGET_POWERPC64
a260abc9
DE
1153 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1154 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1155
a9098fd0
GK
1156 else if (mode == SImode)
1157 return 1;
4e74d8ec
MM
1158 else
1159 abort ();
9878760c 1160}
8f75773e 1161
50a0b056
GK
1162/* Return 1 if the operand is 0.0. */
1163int
1164zero_fp_constant (op, mode)
592696dd
SS
1165 rtx op;
1166 enum machine_mode mode;
50a0b056
GK
1167{
1168 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1169}
1170
a4f6c312
SS
1171/* Return 1 if the operand is in volatile memory. Note that during
1172 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1173 volatile memory references. So this function allows us to
1174 recognize volatile references where its safe. */
1175
1176int
1177volatile_mem_operand (op, mode)
592696dd 1178 rtx op;
b6c9286a
MM
1179 enum machine_mode mode;
1180{
1181 if (GET_CODE (op) != MEM)
1182 return 0;
1183
1184 if (!MEM_VOLATILE_P (op))
1185 return 0;
1186
1187 if (mode != GET_MODE (op))
1188 return 0;
1189
1190 if (reload_completed)
1191 return memory_operand (op, mode);
1192
1193 if (reload_in_progress)
1194 return strict_memory_address_p (mode, XEXP (op, 0));
1195
1196 return memory_address_p (mode, XEXP (op, 0));
1197}
1198
97f6e72f 1199/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1200
1201int
97f6e72f 1202offsettable_mem_operand (op, mode)
592696dd 1203 rtx op;
914c2e77
RK
1204 enum machine_mode mode;
1205{
97f6e72f 1206 return ((GET_CODE (op) == MEM)
677a9668 1207 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1208 mode, XEXP (op, 0)));
914c2e77
RK
1209}
1210
9878760c
RK
1211/* Return 1 if the operand is either an easy FP constant (see above) or
1212 memory. */
1213
1214int
1215mem_or_easy_const_operand (op, mode)
592696dd 1216 rtx op;
9878760c
RK
1217 enum machine_mode mode;
1218{
1219 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1220}
1221
1222/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1223 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1224
1225int
1226add_operand (op, mode)
592696dd 1227 rtx op;
9878760c
RK
1228 enum machine_mode mode;
1229{
2bfcf297
DB
1230 if (GET_CODE (op) == CONST_INT)
1231 return (CONST_OK_FOR_LETTER_P (INTVAL(op), 'I')
1232 || CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'));
1233
1234 return gpc_reg_operand (op, mode);
9878760c
RK
1235}
1236
dcfedcd0
RK
1237/* Return 1 if OP is a constant but not a valid add_operand. */
1238
1239int
1240non_add_cint_operand (op, mode)
592696dd 1241 rtx op;
296b8152 1242 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1243{
1244 return (GET_CODE (op) == CONST_INT
a7653a2c 1245 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
38886f37 1246 && ! CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1247}
1248
9878760c
RK
1249/* Return 1 if the operand is a non-special register or a constant that
1250 can be used as the operand of an OR or XOR insn on the RS/6000. */
1251
1252int
1253logical_operand (op, mode)
592696dd 1254 rtx op;
9878760c
RK
1255 enum machine_mode mode;
1256{
40501e5f 1257 HOST_WIDE_INT opl, oph;
1d328b19 1258
dfbdccdb
GK
1259 if (gpc_reg_operand (op, mode))
1260 return 1;
1d328b19 1261
dfbdccdb 1262 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1263 {
1264 opl = INTVAL (op) & GET_MODE_MASK (mode);
1265
1266#if HOST_BITS_PER_WIDE_INT <= 32
1267 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1268 return 0;
1269#endif
1270 }
dfbdccdb
GK
1271 else if (GET_CODE (op) == CONST_DOUBLE)
1272 {
1d328b19 1273 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1274 abort ();
1d328b19
GK
1275
1276 opl = CONST_DOUBLE_LOW (op);
1277 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1278 if (oph != 0)
38886f37 1279 return 0;
dfbdccdb
GK
1280 }
1281 else
1282 return 0;
1d328b19 1283
40501e5f
AM
1284 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1285 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1286}
1287
dcfedcd0 1288/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1289 above), but could be split into one. */
dcfedcd0
RK
1290
1291int
1292non_logical_cint_operand (op, mode)
592696dd 1293 rtx op;
5f59ecb7 1294 enum machine_mode mode;
dcfedcd0 1295{
dfbdccdb 1296 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1297 && ! logical_operand (op, mode)
1298 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1299}
1300
19ba8161 1301/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1302 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1303 Reject all ones and all zeros, since these should have been optimized
1304 away and confuse the making of MB and ME. */
1305
1306int
19ba8161 1307mask_operand (op, mode)
592696dd 1308 rtx op;
19ba8161 1309 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1310{
02071907 1311 HOST_WIDE_INT c, lsb;
9878760c 1312
19ba8161
DE
1313 if (GET_CODE (op) != CONST_INT)
1314 return 0;
1315
1316 c = INTVAL (op);
1317
c5059423
AM
1318 /* We don't change the number of transitions by inverting,
1319 so make sure we start with the LS bit zero. */
1320 if (c & 1)
1321 c = ~c;
1322
1323 /* Reject all zeros or all ones. */
1324 if (c == 0)
9878760c
RK
1325 return 0;
1326
c5059423
AM
1327 /* Find the first transition. */
1328 lsb = c & -c;
1329
1330 /* Invert to look for a second transition. */
1331 c = ~c;
9878760c 1332
c5059423
AM
1333 /* Erase first transition. */
1334 c &= -lsb;
9878760c 1335
c5059423
AM
1336 /* Find the second transition (if any). */
1337 lsb = c & -c;
1338
1339 /* Match if all the bits above are 1's (or c is zero). */
1340 return c == -lsb;
9878760c
RK
1341}
1342
a260abc9
DE
1343/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1344 It is if there are no more than one 1->0 or 0->1 transitions.
1345 Reject all ones and all zeros, since these should have been optimized
1346 away and confuse the making of MB and ME. */
9878760c
RK
1347
1348int
a260abc9 1349mask64_operand (op, mode)
592696dd 1350 rtx op;
a260abc9
DE
1351 enum machine_mode mode;
1352{
1353 if (GET_CODE (op) == CONST_INT)
1354 {
02071907 1355 HOST_WIDE_INT c, lsb;
a260abc9 1356
c5059423
AM
1357 /* We don't change the number of transitions by inverting,
1358 so make sure we start with the LS bit zero. */
1359 c = INTVAL (op);
1360 if (c & 1)
1361 c = ~c;
a260abc9 1362
c5059423
AM
1363 /* Reject all zeros or all ones. */
1364 if (c == 0)
e2c953b6
DE
1365 return 0;
1366
c5059423
AM
1367 /* Find the transition, and check that all bits above are 1's. */
1368 lsb = c & -c;
1369 return c == -lsb;
e2c953b6 1370 }
a260abc9
DE
1371 else if (GET_CODE (op) == CONST_DOUBLE
1372 && (mode == VOIDmode || mode == DImode))
1373 {
02071907 1374 HOST_WIDE_INT low, high, lsb;
a260abc9 1375
c5059423
AM
1376 if (HOST_BITS_PER_WIDE_INT < 64)
1377 high = CONST_DOUBLE_HIGH (op);
a260abc9 1378
c5059423
AM
1379 low = CONST_DOUBLE_LOW (op);
1380 if (low & 1)
1381 {
1382 if (HOST_BITS_PER_WIDE_INT < 64)
1383 high = ~high;
1384 low = ~low;
1385 }
a260abc9 1386
c5059423
AM
1387 if (low == 0)
1388 {
1389 if (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)
1390 return 0;
a260abc9 1391
c5059423
AM
1392 lsb = high & -high;
1393 return high == -lsb;
1394 }
a260abc9 1395
c5059423
AM
1396 lsb = low & -low;
1397 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
a260abc9
DE
1398 }
1399 else
1400 return 0;
1401}
1402
1403/* Return 1 if the operand is either a non-special register or a constant
1404 that can be used as the operand of a PowerPC64 logical AND insn. */
1405
1406int
1407and64_operand (op, mode)
592696dd 1408 rtx op;
9878760c
RK
1409 enum machine_mode mode;
1410{
a4f6c312 1411 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1412 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1413
1414 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
1415}
1416
a260abc9
DE
1417/* Return 1 if the operand is either a non-special register or a
1418 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1419
1420int
a260abc9 1421and_operand (op, mode)
592696dd 1422 rtx op;
a260abc9 1423 enum machine_mode mode;
dcfedcd0 1424{
a4f6c312 1425 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1426 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1427
1428 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
1429}
1430
9878760c
RK
1431/* Return 1 if the operand is a general register or memory operand. */
1432
1433int
1434reg_or_mem_operand (op, mode)
592696dd
SS
1435 rtx op;
1436 enum machine_mode mode;
9878760c 1437{
b6c9286a
MM
1438 return (gpc_reg_operand (op, mode)
1439 || memory_operand (op, mode)
1440 || volatile_mem_operand (op, mode));
9878760c
RK
1441}
1442
a7a813f7 1443/* Return 1 if the operand is a general register or memory operand without
3cb999d8 1444 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
1445 instruction. */
1446
1447int
1448lwa_operand (op, mode)
592696dd
SS
1449 rtx op;
1450 enum machine_mode mode;
a7a813f7
RK
1451{
1452 rtx inner = op;
1453
1454 if (reload_completed && GET_CODE (inner) == SUBREG)
1455 inner = SUBREG_REG (inner);
1456
1457 return gpc_reg_operand (inner, mode)
1458 || (memory_operand (inner, mode)
1459 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
1460 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
1461 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
1462 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
1463 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
1464}
1465
9878760c
RK
1466/* Return 1 if the operand, used inside a MEM, is a valid first argument
1467 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1468 forced to lr. */
1469
1470int
1471call_operand (op, mode)
592696dd 1472 rtx op;
9878760c
RK
1473 enum machine_mode mode;
1474{
1475 if (mode != VOIDmode && GET_MODE (op) != mode)
1476 return 0;
1477
1478 return (GET_CODE (op) == SYMBOL_REF
1479 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1480}
1481
2af3d377 1482/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
a4f6c312 1483 this file and the function is not weakly defined. */
2af3d377
RK
1484
1485int
1486current_file_function_operand (op, mode)
592696dd 1487 rtx op;
296b8152 1488 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1489{
1490 return (GET_CODE (op) == SYMBOL_REF
1491 && (SYMBOL_REF_FLAG (op)
8f1b829e 1492 || (op == XEXP (DECL_RTL (current_function_decl), 0)
c81fc13e 1493 && ! DECL_WEAK (current_function_decl))));
2af3d377
RK
1494}
1495
9878760c
RK
1496/* Return 1 if this operand is a valid input for a move insn. */
1497
1498int
1499input_operand (op, mode)
592696dd 1500 rtx op;
9878760c
RK
1501 enum machine_mode mode;
1502{
eb4e8003 1503 /* Memory is always valid. */
9878760c
RK
1504 if (memory_operand (op, mode))
1505 return 1;
1506
34792e82 1507 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 1508 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
1509 return 1;
1510
eb4e8003
RK
1511 /* For floating-point, easy constants are valid. */
1512 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1513 && CONSTANT_P (op)
1514 && easy_fp_constant (op, mode))
1515 return 1;
1516
4e74d8ec
MM
1517 /* Allow any integer constant. */
1518 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 1519 && (GET_CODE (op) == CONST_INT
e675f625 1520 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1521 return 1;
1522
eb4e8003
RK
1523 /* For floating-point or multi-word mode, the only remaining valid type
1524 is a register. */
9878760c
RK
1525 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1526 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1527 return register_operand (op, mode);
9878760c 1528
88fe15a1
RK
1529 /* The only cases left are integral modes one word or smaller (we
1530 do not get called for MODE_CC values). These can be in any
1531 register. */
1532 if (register_operand (op, mode))
a8b3aeda 1533 return 1;
88fe15a1 1534
84cf9dda 1535 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 1536 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
1537 return 1;
1538
9ebbca7d
GK
1539 /* A constant pool expression (relative to the TOC) is valid */
1540 if (TOC_RELATIVE_EXPR_P (op))
b6c9286a
MM
1541 return 1;
1542
88228c4b
MM
1543 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1544 to be valid. */
f607bc57 1545 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
1546 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1547 && small_data_operand (op, Pmode))
1548 return 1;
1549
042259f2 1550 return 0;
9878760c 1551}
7509c759 1552
a4f6c312 1553/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
1554
1555int
1556small_data_operand (op, mode)
296b8152
KG
1557 rtx op ATTRIBUTE_UNUSED;
1558 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 1559{
38c1f2d7 1560#if TARGET_ELF
5f59ecb7 1561 rtx sym_ref;
7509c759 1562
d9407988 1563 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 1564 return 0;
a54d04b7 1565
f607bc57 1566 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
1567 return 0;
1568
88228c4b
MM
1569 if (GET_CODE (op) == SYMBOL_REF)
1570 sym_ref = op;
1571
1572 else if (GET_CODE (op) != CONST
1573 || GET_CODE (XEXP (op, 0)) != PLUS
1574 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1575 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
1576 return 0;
1577
88228c4b 1578 else
dbf55e53
MM
1579 {
1580 rtx sum = XEXP (op, 0);
1581 HOST_WIDE_INT summand;
1582
1583 /* We have to be careful here, because it is the referenced address
1584 that must be 32k from _SDA_BASE_, not just the symbol. */
1585 summand = INTVAL (XEXP (sum, 1));
1586 if (summand < 0 || summand > g_switch_value)
1587 return 0;
1588
1589 sym_ref = XEXP (sum, 0);
1590 }
88228c4b
MM
1591
1592 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
1593 return 0;
1594
1595 return 1;
d9407988
MM
1596
1597#else
1598 return 0;
1599#endif
7509c759 1600}
9ebbca7d
GK
1601\f
1602static int
1603constant_pool_expr_1 (op, have_sym, have_toc)
1604 rtx op;
1605 int *have_sym;
1606 int *have_toc;
1607{
1608 switch (GET_CODE(op))
1609 {
1610 case SYMBOL_REF:
a4f6c312
SS
1611 if (CONSTANT_POOL_ADDRESS_P (op))
1612 {
1613 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
1614 {
1615 *have_sym = 1;
1616 return 1;
1617 }
1618 else
1619 return 0;
1620 }
1621 else if (! strcmp (XSTR (op, 0), toc_label_name))
1622 {
1623 *have_toc = 1;
1624 return 1;
1625 }
1626 else
1627 return 0;
9ebbca7d
GK
1628 case PLUS:
1629 case MINUS:
a4f6c312
SS
1630 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) &&
1631 constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc);
9ebbca7d 1632 case CONST:
a4f6c312 1633 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 1634 case CONST_INT:
a4f6c312 1635 return 1;
9ebbca7d 1636 default:
a4f6c312 1637 return 0;
9ebbca7d
GK
1638 }
1639}
1640
1641int
1642constant_pool_expr_p (op)
1643 rtx op;
1644{
1645 int have_sym = 0;
1646 int have_toc = 0;
1647 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
1648}
1649
1650int
1651toc_relative_expr_p (op)
1652 rtx op;
1653{
1654 int have_sym = 0;
1655 int have_toc = 0;
1656 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
1657}
1658
1659/* Try machine-dependent ways of modifying an illegitimate address
1660 to be legitimate. If we find one, return the new, valid address.
1661 This is used from only one place: `memory_address' in explow.c.
1662
a4f6c312
SS
1663 OLDX is the address as it was before break_out_memory_refs was
1664 called. In some cases it is useful to look at this to decide what
1665 needs to be done.
9ebbca7d 1666
a4f6c312 1667 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 1668
a4f6c312
SS
1669 It is always safe for this function to do nothing. It exists to
1670 recognize opportunities to optimize the output.
9ebbca7d
GK
1671
1672 On RS/6000, first check for the sum of a register with a constant
1673 integer that is out of range. If so, generate code to add the
1674 constant with the low-order 16 bits masked to the register and force
1675 this result into another register (this can be done with `cau').
1676 Then generate an address of REG+(CONST&0xffff), allowing for the
1677 possibility of bit 16 being a one.
1678
1679 Then check for the sum of a register and something not constant, try to
1680 load the other things into a register and return the sum. */
1681rtx
1682rs6000_legitimize_address (x, oldx, mode)
1683 rtx x;
1684 rtx oldx ATTRIBUTE_UNUSED;
1685 enum machine_mode mode;
0ac081f6 1686{
9ebbca7d
GK
1687 if (GET_CODE (x) == PLUS
1688 && GET_CODE (XEXP (x, 0)) == REG
1689 && GET_CODE (XEXP (x, 1)) == CONST_INT
1690 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
1691 {
1692 HOST_WIDE_INT high_int, low_int;
1693 rtx sum;
1694 high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff);
1695 low_int = INTVAL (XEXP (x, 1)) & 0xffff;
1696 if (low_int & 0x8000)
1697 high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
1698 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
1699 GEN_INT (high_int)), 0);
1700 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
1701 }
1702 else if (GET_CODE (x) == PLUS
1703 && GET_CODE (XEXP (x, 0)) == REG
1704 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 1705 && GET_MODE_NUNITS (mode) == 1
9ebbca7d
GK
1706 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1707 && (TARGET_POWERPC64 || mode != DImode)
1708 && mode != TImode)
1709 {
1710 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
1711 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
1712 }
0ac081f6
AH
1713 else if (ALTIVEC_VECTOR_MODE (mode))
1714 {
1715 rtx reg;
1716
1717 /* Make sure both operands are registers. */
1718 if (GET_CODE (x) == PLUS)
9f85ed45 1719 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
1720 force_reg (Pmode, XEXP (x, 1)));
1721
1722 reg = force_reg (Pmode, x);
1723 return reg;
1724 }
9ebbca7d
GK
1725 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
1726 && GET_CODE (x) != CONST_INT
1727 && GET_CODE (x) != CONST_DOUBLE
1728 && CONSTANT_P (x)
6ac7bf2c
GK
1729 && GET_MODE_NUNITS (mode) == 1
1730 && (GET_MODE_BITSIZE (mode) <= 32
c3bb62b9 1731 || (TARGET_HARD_FLOAT && mode == DFmode)))
9ebbca7d
GK
1732 {
1733 rtx reg = gen_reg_rtx (Pmode);
1734 emit_insn (gen_elf_high (reg, (x)));
1735 return gen_rtx_LO_SUM (Pmode, reg, (x));
1736 }
ee890fe2
SS
1737 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
1738 && ! flag_pic
1739 && GET_CODE (x) != CONST_INT
1740 && GET_CODE (x) != CONST_DOUBLE
1741 && CONSTANT_P (x)
1742 && (TARGET_HARD_FLOAT || mode != DFmode)
1743 && mode != DImode
1744 && mode != TImode)
1745 {
1746 rtx reg = gen_reg_rtx (Pmode);
1747 emit_insn (gen_macho_high (reg, (x)));
1748 return gen_rtx_LO_SUM (Pmode, reg, (x));
1749 }
9ebbca7d
GK
1750 else if (TARGET_TOC
1751 && CONSTANT_POOL_EXPR_P (x)
a9098fd0 1752 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
1753 {
1754 return create_TOC_reference (x);
1755 }
1756 else
1757 return NULL_RTX;
1758}
258bfae2
FS
1759
1760/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
1761 that is a valid memory address for an instruction.
1762 The MODE argument is the machine mode for the MEM expression
1763 that wants to use this address.
1764
1765 On the RS/6000, there are four valid address: a SYMBOL_REF that
1766 refers to a constant pool entry of an address (or the sum of it
1767 plus a constant), a short (16-bit signed) constant plus a register,
1768 the sum of two registers, or a register indirect, possibly with an
1769 auto-increment. For DFmode and DImode with an constant plus register,
1770 we must ensure that both words are addressable or PowerPC64 with offset
1771 word aligned.
1772
1773 For modes spanning multiple registers (DFmode in 32-bit GPRs,
1774 32-bit DImode, TImode), indexed addressing cannot be used because
1775 adjacent memory cells are accessed by adding word-sized offsets
1776 during assembly output. */
1777int
1778rs6000_legitimate_address (mode, x, reg_ok_strict)
1779 enum machine_mode mode;
1780 rtx x;
1781 int reg_ok_strict;
1782{
1783 if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict))
1784 return 1;
1785 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
1786 && TARGET_UPDATE
1787 && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict))
1788 return 1;
1789 if (LEGITIMATE_SMALL_DATA_P (mode, x))
1790 return 1;
1791 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
1792 return 1;
1793 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
1794 if (! reg_ok_strict
1795 && GET_CODE (x) == PLUS
1796 && GET_CODE (XEXP (x, 0)) == REG
1797 && XEXP (x, 0) == virtual_stack_vars_rtx
1798 && GET_CODE (XEXP (x, 1)) == CONST_INT)
1799 return 1;
1800 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict))
1801 return 1;
1802 if (mode != TImode
1803 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1804 && (TARGET_POWERPC64 || mode != DImode)
1805 && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict))
1806 return 1;
1807 if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict))
1808 return 1;
1809 return 0;
1810}
fb4d4348 1811\f
a4f6c312
SS
1812/* Try to output insns to set TARGET equal to the constant C if it can
1813 be done in less than N insns. Do all computations in MODE.
1814 Returns the place where the output has been placed if it can be
1815 done and the insns have been emitted. If it would take more than N
1816 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
1817
1818rtx
1819rs6000_emit_set_const (dest, mode, source, n)
1820 rtx dest, source;
1821 enum machine_mode mode;
1822 int n ATTRIBUTE_UNUSED;
1823{
1824 HOST_WIDE_INT c0, c1;
1825
1826 if (mode == QImode || mode == HImode || mode == SImode)
1827 {
1828 if (dest == NULL)
1829 dest = gen_reg_rtx (mode);
1830 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
1831 return dest;
1832 }
1833
1834 if (GET_CODE (source) == CONST_INT)
1835 {
1836 c0 = INTVAL (source);
1837 c1 = -(c0 < 0);
1838 }
1839 else if (GET_CODE (source) == CONST_DOUBLE)
1840 {
1841#if HOST_BITS_PER_WIDE_INT >= 64
1842 c0 = CONST_DOUBLE_LOW (source);
1843 c1 = -(c0 < 0);
1844#else
1845 c0 = CONST_DOUBLE_LOW (source);
1846 c1 = CONST_DOUBLE_HIGH (source);
1847#endif
1848 }
1849 else
a4f6c312 1850 abort ();
2bfcf297
DB
1851
1852 return rs6000_emit_set_long_const (dest, c0, c1);
1853}
1854
1855/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
1856 fall back to a straight forward decomposition. We do this to avoid
1857 exponential run times encountered when looking for longer sequences
1858 with rs6000_emit_set_const. */
1859static rtx
1860rs6000_emit_set_long_const (dest, c1, c2)
1861 rtx dest;
1862 HOST_WIDE_INT c1, c2;
1863{
1864 if (!TARGET_POWERPC64)
1865 {
1866 rtx operand1, operand2;
1867
1868 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
1869 DImode);
1870 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
1871 DImode);
1872 emit_move_insn (operand1, GEN_INT (c1));
1873 emit_move_insn (operand2, GEN_INT (c2));
1874 }
1875 else
1876 {
1877 HOST_WIDE_INT d1, d2, d3, d4;
1878
1879 /* Decompose the entire word */
1880#if HOST_BITS_PER_WIDE_INT >= 64
1881 if (c2 != -(c1 < 0))
1882 abort ();
1883 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
1884 c1 -= d1;
1885 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
1886 c1 = (c1 - d2) >> 32;
1887 d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
1888 c1 -= d3;
1889 d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
1890 if (c1 != d4)
1891 abort ();
1892#else
1893 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
1894 c1 -= d1;
1895 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
1896 if (c1 != d2)
1897 abort ();
1898 c2 += (d2 < 0);
1899 d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000;
1900 c2 -= d3;
1901 d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000;
1902 if (c2 != d4)
1903 abort ();
1904#endif
1905
1906 /* Construct the high word */
40501e5f 1907 if (d4 != 0)
2bfcf297
DB
1908 {
1909 emit_move_insn (dest, GEN_INT (d4));
40501e5f 1910 if (d3 != 0)
2bfcf297
DB
1911 emit_move_insn (dest,
1912 gen_rtx_PLUS (DImode, dest, GEN_INT (d3)));
1913 }
1914 else
1915 emit_move_insn (dest, GEN_INT (d3));
1916
1917 /* Shift it into place */
40501e5f
AM
1918 if (d3 != 0 || d4 != 0)
1919 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
2bfcf297
DB
1920
1921 /* Add in the low bits. */
40501e5f 1922 if (d2 != 0)
2bfcf297 1923 emit_move_insn (dest, gen_rtx_PLUS (DImode, dest, GEN_INT (d2)));
40501e5f 1924 if (d1 != 0)
2bfcf297
DB
1925 emit_move_insn (dest, gen_rtx_PLUS (DImode, dest, GEN_INT (d1)));
1926 }
1927
1928 return dest;
1929}
1930
fb4d4348
GK
1931/* Emit a move from SOURCE to DEST in mode MODE. */
1932void
1933rs6000_emit_move (dest, source, mode)
1934 rtx dest;
1935 rtx source;
1936 enum machine_mode mode;
1937{
1938 rtx operands[2];
1939 operands[0] = dest;
1940 operands[1] = source;
1941
1942 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
1943 if (GET_CODE (operands[1]) == CONST_DOUBLE
1944 && ! FLOAT_MODE_P (mode)
1945 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1946 {
1947 /* FIXME. This should never happen. */
1948 /* Since it seems that it does, do the safe thing and convert
1949 to a CONST_INT. */
1950 operands[1] =
1951 GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode));
1952 }
1953 if (GET_CODE (operands[1]) == CONST_DOUBLE
1954 && ! FLOAT_MODE_P (mode)
1955 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
1956 && CONST_DOUBLE_LOW (operands[1]) >= 0)
1957 || (CONST_DOUBLE_HIGH (operands[1]) == -1
1958 && CONST_DOUBLE_LOW (operands[1]) < 0)))
1959 abort ();
c9e8cb32
DD
1960
1961 /* Check if GCC is setting up a block move that will end up using FP
1962 registers as temporaries. We must make sure this is acceptable. */
1963 if (GET_CODE (operands[0]) == MEM
1964 && GET_CODE (operands[1]) == MEM
1965 && mode == DImode
41543739
GK
1966 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
1967 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
1968 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
1969 ? 32 : MEM_ALIGN (operands[0])))
1970 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
1971 ? 32
1972 : MEM_ALIGN (operands[1]))))
1973 && ! MEM_VOLATILE_P (operands [0])
1974 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 1975 {
41543739
GK
1976 emit_move_insn (adjust_address (operands[0], SImode, 0),
1977 adjust_address (operands[1], SImode, 0));
1978 emit_move_insn (adjust_address (operands[0], SImode, 4),
1979 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
1980 return;
1981 }
fb4d4348
GK
1982
1983 if (! no_new_pseudos && GET_CODE (operands[0]) != REG)
1984 operands[1] = force_reg (mode, operands[1]);
a9098fd0 1985
ffc14f31
GK
1986 if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT
1987 && GET_CODE (operands[0]) == MEM)
fb4d4348 1988 {
ffc14f31
GK
1989 int regnum;
1990
1991 if (reload_in_progress || reload_completed)
1992 regnum = true_regnum (operands[1]);
1993 else if (GET_CODE (operands[1]) == REG)
1994 regnum = REGNO (operands[1]);
1995 else
1996 regnum = -1;
fb4d4348
GK
1997
1998 /* If operands[1] is a register, on POWER it may have
1999 double-precision data in it, so truncate it to single
2000 precision. */
2001 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
2002 {
2003 rtx newreg;
2004 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
2005 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
2006 operands[1] = newreg;
2007 }
2008 }
2009
a9098fd0
GK
2010 /* Handle the case where reload calls us with an invalid address;
2011 and the case of CONSTANT_P_RTX. */
2012 if (! general_operand (operands[1], mode)
2013 || ! nonimmediate_operand (operands[0], mode)
2014 || GET_CODE (operands[1]) == CONSTANT_P_RTX)
fb4d4348
GK
2015 {
2016 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2017 return;
2018 }
a9098fd0 2019
fb4d4348
GK
2020 /* FIXME: In the long term, this switch statement should go away
2021 and be replaced by a sequence of tests based on things like
2022 mode == Pmode. */
2023 switch (mode)
2024 {
2025 case HImode:
2026 case QImode:
2027 if (CONSTANT_P (operands[1])
2028 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 2029 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2030 break;
2031
06f4e019 2032 case TFmode:
fb4d4348
GK
2033 case DFmode:
2034 case SFmode:
2035 if (CONSTANT_P (operands[1])
2036 && ! easy_fp_constant (operands[1], mode))
a9098fd0 2037 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2038 break;
2039
0ac081f6
AH
2040 case V16QImode:
2041 case V8HImode:
2042 case V4SFmode:
2043 case V4SImode:
2044 /* fixme: aldyh -- allow vector constants when they are implemented. */
2045 if (CONSTANT_P (operands[1]))
2046 operands[1] = force_const_mem (mode, operands[1]);
2047 break;
2048
fb4d4348 2049 case SImode:
a9098fd0 2050 case DImode:
fb4d4348
GK
2051 /* Use default pattern for address of ELF small data */
2052 if (TARGET_ELF
a9098fd0 2053 && mode == Pmode
f607bc57 2054 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
2055 && (GET_CODE (operands[1]) == SYMBOL_REF
2056 || GET_CODE (operands[1]) == CONST)
2057 && small_data_operand (operands[1], mode))
fb4d4348
GK
2058 {
2059 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2060 return;
2061 }
2062
f607bc57 2063 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
2064 && mode == Pmode && mode == SImode
2065 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
2066 {
2067 emit_insn (gen_movsi_got (operands[0], operands[1]));
2068 return;
2069 }
2070
ee890fe2
SS
2071 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
2072 && TARGET_NO_TOC && ! flag_pic
a9098fd0 2073 && mode == Pmode
fb4d4348
GK
2074 && CONSTANT_P (operands[1])
2075 && GET_CODE (operands[1]) != HIGH
2076 && GET_CODE (operands[1]) != CONST_INT)
2077 {
a9098fd0 2078 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
2079
2080 /* If this is a function address on -mcall-aixdesc,
2081 convert it to the address of the descriptor. */
2082 if (DEFAULT_ABI == ABI_AIX
2083 && GET_CODE (operands[1]) == SYMBOL_REF
2084 && XSTR (operands[1], 0)[0] == '.')
2085 {
2086 const char *name = XSTR (operands[1], 0);
2087 rtx new_ref;
2088 while (*name == '.')
2089 name++;
2090 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
2091 CONSTANT_POOL_ADDRESS_P (new_ref)
2092 = CONSTANT_POOL_ADDRESS_P (operands[1]);
2093 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
2094 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
2095 operands[1] = new_ref;
2096 }
7509c759 2097
ee890fe2
SS
2098 if (DEFAULT_ABI == ABI_DARWIN)
2099 {
2100 emit_insn (gen_macho_high (target, operands[1]));
2101 emit_insn (gen_macho_low (operands[0], target, operands[1]));
2102 return;
2103 }
2104
fb4d4348
GK
2105 emit_insn (gen_elf_high (target, operands[1]));
2106 emit_insn (gen_elf_low (operands[0], target, operands[1]));
2107 return;
2108 }
2109
a9098fd0
GK
2110 /* If this is a SYMBOL_REF that refers to a constant pool entry,
2111 and we have put it in the TOC, we just need to make a TOC-relative
2112 reference to it. */
2113 if (TARGET_TOC
2114 && GET_CODE (operands[1]) == SYMBOL_REF
2115 && CONSTANT_POOL_EXPR_P (operands[1])
2116 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
2117 get_pool_mode (operands[1])))
fb4d4348 2118 {
a9098fd0 2119 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 2120 }
a9098fd0
GK
2121 else if (mode == Pmode
2122 && CONSTANT_P (operands[1])
38886f37
AO
2123 && ((GET_CODE (operands[1]) != CONST_INT
2124 && ! easy_fp_constant (operands[1], mode))
2125 || (GET_CODE (operands[1]) == CONST_INT
2126 && num_insns_constant (operands[1], mode) > 2)
2127 || (GET_CODE (operands[0]) == REG
2128 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0
GK
2129 && GET_CODE (operands[1]) != HIGH
2130 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
2131 && ! TOC_RELATIVE_EXPR_P (operands[1]))
fb4d4348
GK
2132 {
2133 /* Emit a USE operation so that the constant isn't deleted if
2134 expensive optimizations are turned on because nobody
2135 references it. This should only be done for operands that
2136 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
2137 This should not be done for operands that contain LABEL_REFs.
2138 For now, we just handle the obvious case. */
2139 if (GET_CODE (operands[1]) != LABEL_REF)
2140 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
2141
c859cda6 2142#if TARGET_MACHO
ee890fe2
SS
2143 /* Darwin uses a special PIC legitimizer. */
2144 if (DEFAULT_ABI == ABI_DARWIN && flag_pic)
2145 {
ee890fe2
SS
2146 operands[1] =
2147 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
2148 operands[0]);
2149 if (operands[0] != operands[1])
2150 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
2151 return;
2152 }
c859cda6 2153#endif
ee890fe2 2154
fb4d4348
GK
2155 /* If we are to limit the number of things we put in the TOC and
2156 this is a symbol plus a constant we can add in one insn,
2157 just put the symbol in the TOC and add the constant. Don't do
2158 this if reload is in progress. */
2159 if (GET_CODE (operands[1]) == CONST
2160 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
2161 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 2162 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
2163 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
2164 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
2165 && ! side_effects_p (operands[0]))
2166 {
a4f6c312
SS
2167 rtx sym =
2168 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
2169 rtx other = XEXP (XEXP (operands[1], 0), 1);
2170
a9098fd0
GK
2171 sym = force_reg (mode, sym);
2172 if (mode == SImode)
2173 emit_insn (gen_addsi3 (operands[0], sym, other));
2174 else
2175 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
2176 return;
2177 }
2178
a9098fd0 2179 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2180
2181 if (TARGET_TOC
d34c5b80
DE
2182 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
2183 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
2184 get_pool_constant (XEXP (operands[1], 0)),
2185 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 2186 {
ba4828e0
RK
2187 operands[1]
2188 = gen_rtx_MEM (mode,
2189 create_TOC_reference (XEXP (operands[1], 0)));
2190 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 2191 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 2192 }
fb4d4348
GK
2193 }
2194 break;
a9098fd0 2195
fb4d4348
GK
2196 case TImode:
2197 if (GET_CODE (operands[0]) == MEM
2198 && GET_CODE (XEXP (operands[0], 0)) != REG
2199 && ! reload_in_progress)
792760b9
RK
2200 operands[0]
2201 = replace_equiv_address (operands[0],
2202 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
2203
2204 if (GET_CODE (operands[1]) == MEM
2205 && GET_CODE (XEXP (operands[1], 0)) != REG
2206 && ! reload_in_progress)
792760b9
RK
2207 operands[1]
2208 = replace_equiv_address (operands[1],
2209 copy_addr_to_reg (XEXP (operands[1], 0)));
fb4d4348
GK
2210 break;
2211
2212 default:
2213 abort ();
2214 }
2215
a9098fd0
GK
2216 /* Above, we may have called force_const_mem which may have returned
2217 an invalid address. If we can, fix this up; otherwise, reload will
2218 have to deal with it. */
2219 if (GET_CODE (operands[1]) == MEM
2220 && ! memory_address_p (mode, XEXP (operands[1], 0))
2221 && ! reload_in_progress)
f4ef873c 2222 operands[1] = adjust_address (operands[1], mode, 0);
a9098fd0 2223
fb4d4348 2224 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
02a4ec28 2225 return;
fb4d4348 2226}
4697a36c
MM
2227\f
2228/* Initialize a variable CUM of type CUMULATIVE_ARGS
2229 for a call to a function whose data type is FNTYPE.
2230 For a library call, FNTYPE is 0.
2231
2232 For incoming args we set the number of arguments in the prototype large
1c20ae99 2233 so we never return a PARALLEL. */
4697a36c
MM
2234
2235void
2236init_cumulative_args (cum, fntype, libname, incoming)
2237 CUMULATIVE_ARGS *cum;
2238 tree fntype;
296b8152 2239 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
2240 int incoming;
2241{
2242 static CUMULATIVE_ARGS zero_cumulative;
2243
2244 *cum = zero_cumulative;
2245 cum->words = 0;
2246 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 2247 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 2248 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 2249 cum->call_cookie = CALL_NORMAL;
4cc833b7 2250 cum->sysv_gregno = GP_ARG_MIN_REG;
4697a36c
MM
2251
2252 if (incoming)
bd227acc 2253 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
2254
2255 else if (cum->prototype)
2256 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
2257 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
2258 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
2259
2260 else
2261 cum->nargs_prototype = 0;
2262
2263 cum->orig_nargs = cum->nargs_prototype;
7509c759 2264
9ebbca7d
GK
2265 /* Check for longcall's */
2266 if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
2267 cum->call_cookie = CALL_LONG;
2268
4697a36c
MM
2269 if (TARGET_DEBUG_ARG)
2270 {
2271 fprintf (stderr, "\ninit_cumulative_args:");
2272 if (fntype)
2273 {
2274 tree ret_type = TREE_TYPE (fntype);
2275 fprintf (stderr, " ret code = %s,",
2276 tree_code_name[ (int)TREE_CODE (ret_type) ]);
2277 }
2278
6a4cee5f
MM
2279 if (cum->call_cookie & CALL_LONG)
2280 fprintf (stderr, " longcall,");
2281
4697a36c
MM
2282 fprintf (stderr, " proto = %d, nargs = %d\n",
2283 cum->prototype, cum->nargs_prototype);
2284 }
2285}
2286\f
c229cba9
DE
2287/* If defined, a C expression which determines whether, and in which
2288 direction, to pad out an argument with extra space. The value
2289 should be of type `enum direction': either `upward' to pad above
2290 the argument, `downward' to pad below, or `none' to inhibit
2291 padding.
2292
2293 For the AIX ABI structs are always stored left shifted in their
2294 argument slot. */
2295
9ebbca7d 2296enum direction
c229cba9
DE
2297function_arg_padding (mode, type)
2298 enum machine_mode mode;
2299 tree type;
2300{
c85f7c16 2301 if (type != 0 && AGGREGATE_TYPE_P (type))
9ebbca7d 2302 return upward;
c229cba9
DE
2303
2304 /* This is the default definition. */
2305 return (! BYTES_BIG_ENDIAN
9ebbca7d 2306 ? upward
c229cba9
DE
2307 : ((mode == BLKmode
2308 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
2309 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
2310 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
9ebbca7d 2311 ? downward : upward));
c229cba9
DE
2312}
2313
b6c9286a
MM
2314/* If defined, a C expression that gives the alignment boundary, in bits,
2315 of an argument with the specified mode and type. If it is not defined,
2316 PARM_BOUNDARY is used for all arguments.
2317
2310f99a 2318 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
2319
2320int
2321function_arg_boundary (mode, type)
2322 enum machine_mode mode;
9ebbca7d 2323 tree type ATTRIBUTE_UNUSED;
b6c9286a 2324{
f607bc57 2325 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 2326 return 64;
0ac081f6
AH
2327 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
2328 return 128;
9ebbca7d 2329 else
b6c9286a 2330 return PARM_BOUNDARY;
b6c9286a
MM
2331}
2332\f
4697a36c
MM
2333/* Update the data in CUM to advance over an argument
2334 of mode MODE and data type TYPE.
2335 (TYPE is null for libcalls where that information may not be available.) */
2336
2337void
2338function_arg_advance (cum, mode, type, named)
2339 CUMULATIVE_ARGS *cum;
2340 enum machine_mode mode;
2341 tree type;
2342 int named;
2343{
2344 cum->nargs_prototype--;
2345
0ac081f6
AH
2346 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
2347 {
2348 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
2349 cum->vregno++;
2350 else
2351 cum->words += RS6000_ARG_SIZE (mode, type);
2352 }
f607bc57 2353 else if (DEFAULT_ABI == ABI_V4)
4697a36c 2354 {
4cc833b7
RH
2355 if (TARGET_HARD_FLOAT
2356 && (mode == SFmode || mode == DFmode))
4697a36c 2357 {
4cc833b7
RH
2358 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2359 cum->fregno++;
2360 else
2361 {
2362 if (mode == DFmode)
2363 cum->words += cum->words & 1;
d34c5b80 2364 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 2365 }
4697a36c 2366 }
4cc833b7
RH
2367 else
2368 {
2369 int n_words;
2370 int gregno = cum->sysv_gregno;
2371
2372 /* Aggregates and IEEE quad get passed by reference. */
2373 if ((type && AGGREGATE_TYPE_P (type))
2374 || mode == TFmode)
2375 n_words = 1;
2376 else
d34c5b80 2377 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7
RH
2378
2379 /* Long long is put in odd registers. */
2380 if (n_words == 2 && (gregno & 1) == 0)
2381 gregno += 1;
2382
2383 /* Long long is not split between registers and stack. */
2384 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
2385 {
2386 /* Long long is aligned on the stack. */
2387 if (n_words == 2)
2388 cum->words += cum->words & 1;
2389 cum->words += n_words;
2390 }
4697a36c 2391
4cc833b7
RH
2392 /* Note: continuing to accumulate gregno past when we've started
2393 spilling to the stack indicates the fact that we've started
2394 spilling to the stack to expand_builtin_saveregs. */
2395 cum->sysv_gregno = gregno + n_words;
2396 }
4697a36c 2397
4cc833b7
RH
2398 if (TARGET_DEBUG_ARG)
2399 {
2400 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
2401 cum->words, cum->fregno);
2402 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
2403 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
2404 fprintf (stderr, "mode = %4s, named = %d\n",
2405 GET_MODE_NAME (mode), named);
2406 }
4697a36c
MM
2407 }
2408 else
4cc833b7
RH
2409 {
2410 int align = (TARGET_32BIT && (cum->words & 1) != 0
2411 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 2412
d34c5b80 2413 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 2414
d34c5b80
DE
2415 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
2416 cum->fregno++;
4cc833b7
RH
2417
2418 if (TARGET_DEBUG_ARG)
2419 {
2420 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
2421 cum->words, cum->fregno);
2422 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
2423 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
2424 fprintf (stderr, "named = %d, align = %d\n", named, align);
2425 }
2426 }
4697a36c
MM
2427}
2428\f
2429/* Determine where to put an argument to a function.
2430 Value is zero to push the argument on the stack,
2431 or a hard register in which to store the argument.
2432
2433 MODE is the argument's machine mode.
2434 TYPE is the data type of the argument (as a tree).
2435 This is null for libcalls where that information may
2436 not be available.
2437 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2438 the preceding args and about the function being called.
2439 NAMED is nonzero if this argument is a named parameter
2440 (otherwise it is an extra parameter matching an ellipsis).
2441
2442 On RS/6000 the first eight words of non-FP are normally in registers
2443 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
2444 Under V.4, the first 8 FP args are in registers.
2445
2446 If this is floating-point and no prototype is specified, we use
2447 both an FP and integer register (or possibly FP reg and stack). Library
2448 functions (when TYPE is zero) always have the proper types for args,
2449 so we can pass the FP value just in one register. emit_library_function
1c20ae99 2450 doesn't support PARALLEL anyway. */
4697a36c
MM
2451
2452struct rtx_def *
2453function_arg (cum, mode, type, named)
2454 CUMULATIVE_ARGS *cum;
2455 enum machine_mode mode;
2456 tree type;
20c29ebe 2457 int named;
4697a36c 2458{
4cc833b7 2459 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 2460
a4f6c312
SS
2461 /* Return a marker to indicate whether CR1 needs to set or clear the
2462 bit that V.4 uses to say fp args were passed in registers.
2463 Assume that we don't need the marker for software floating point,
2464 or compiler generated library calls. */
4697a36c
MM
2465 if (mode == VOIDmode)
2466 {
f607bc57 2467 if (abi == ABI_V4
7509c759
MM
2468 && TARGET_HARD_FLOAT
2469 && cum->nargs_prototype < 0
4697a36c 2470 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 2471 {
6a4cee5f
MM
2472 return GEN_INT (cum->call_cookie
2473 | ((cum->fregno == FP_ARG_MIN_REG)
2474 ? CALL_V4_SET_FP_ARGS
2475 : CALL_V4_CLEAR_FP_ARGS));
7509c759 2476 }
4697a36c 2477
7509c759 2478 return GEN_INT (cum->call_cookie);
4697a36c
MM
2479 }
2480
0ac081f6
AH
2481 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
2482 {
20c29ebe 2483 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
2484 return gen_rtx_REG (mode, cum->vregno);
2485 else
2486 return NULL;
2487 }
f607bc57 2488 else if (abi == ABI_V4)
4697a36c 2489 {
4cc833b7
RH
2490 if (TARGET_HARD_FLOAT
2491 && (mode == SFmode || mode == DFmode))
2492 {
2493 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2494 return gen_rtx_REG (mode, cum->fregno);
2495 else
2496 return NULL;
2497 }
2498 else
2499 {
2500 int n_words;
2501 int gregno = cum->sysv_gregno;
2502
2503 /* Aggregates and IEEE quad get passed by reference. */
2504 if ((type && AGGREGATE_TYPE_P (type))
2505 || mode == TFmode)
2506 n_words = 1;
2507 else
d34c5b80 2508 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7
RH
2509
2510 /* Long long is put in odd registers. */
2511 if (n_words == 2 && (gregno & 1) == 0)
2512 gregno += 1;
2513
2514 /* Long long is not split between registers and stack. */
2515 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
2516 return gen_rtx_REG (mode, gregno);
2517 else
2518 return NULL;
2519 }
4697a36c 2520 }
4cc833b7
RH
2521 else
2522 {
2523 int align = (TARGET_32BIT && (cum->words & 1) != 0
2524 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2525 int align_words = cum->words + align;
4697a36c 2526
4cc833b7
RH
2527 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2528 return NULL_RTX;
2529
2530 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2531 {
2532 if (! type
2533 || ((cum->nargs_prototype > 0)
2534 /* IBM AIX extended its linkage convention definition always
2535 to require FP args after register save area hole on the
2536 stack. */
2537 && (DEFAULT_ABI != ABI_AIX
2538 || ! TARGET_XL_CALL
2539 || (align_words < GP_ARG_NUM_REG))))
2540 return gen_rtx_REG (mode, cum->fregno);
2541
2542 return gen_rtx_PARALLEL (mode,
2543 gen_rtvec (2,
39403d82 2544 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
2545 ((align_words >= GP_ARG_NUM_REG)
2546 ? NULL_RTX
2547 : (align_words
d34c5b80 2548 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
2549 > GP_ARG_NUM_REG
2550 /* If this is partially on the stack, then
2551 we only include the portion actually
2552 in registers here. */
39403d82 2553 ? gen_rtx_REG (SImode,
1c20ae99 2554 GP_ARG_MIN_REG + align_words)
39403d82 2555 : gen_rtx_REG (mode,
1c20ae99
JW
2556 GP_ARG_MIN_REG + align_words))),
2557 const0_rtx),
39403d82
DE
2558 gen_rtx_EXPR_LIST (VOIDmode,
2559 gen_rtx_REG (mode, cum->fregno),
1c20ae99 2560 const0_rtx)));
4cc833b7
RH
2561 }
2562 else if (align_words < GP_ARG_NUM_REG)
2563 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
2564 else
2565 return NULL_RTX;
4697a36c 2566 }
4697a36c
MM
2567}
2568\f
2569/* For an arg passed partly in registers and partly in memory,
2570 this is the number of registers used.
2571 For args passed entirely in registers or entirely in memory, zero. */
2572
2573int
2574function_arg_partial_nregs (cum, mode, type, named)
2575 CUMULATIVE_ARGS *cum;
2576 enum machine_mode mode;
2577 tree type;
d34c5b80 2578 int named ATTRIBUTE_UNUSED;
4697a36c 2579{
f607bc57 2580 if (DEFAULT_ABI == ABI_V4)
4697a36c 2581 return 0;
4697a36c 2582
0ac081f6
AH
2583 if (USE_FP_FOR_ARG_P (*cum, mode, type)
2584 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
2585 {
2586 if (cum->nargs_prototype >= 0)
2587 return 0;
2588 }
2589
2590 if (cum->words < GP_ARG_NUM_REG
d34c5b80 2591 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
2592 {
2593 int ret = GP_ARG_NUM_REG - cum->words;
2594 if (ret && TARGET_DEBUG_ARG)
2595 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2596
2597 return ret;
2598 }
2599
2600 return 0;
2601}
2602\f
2603/* A C expression that indicates when an argument must be passed by
2604 reference. If nonzero for an argument, a copy of that argument is
2605 made in memory and a pointer to the argument is passed instead of
2606 the argument itself. The pointer is passed in whatever way is
2607 appropriate for passing a pointer to that type.
2608
2609 Under V.4, structures and unions are passed by reference. */
2610
2611int
2612function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
2613 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2614 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 2615 tree type;
296b8152 2616 int named ATTRIBUTE_UNUSED;
4697a36c 2617{
f607bc57 2618 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
2619 && ((type && AGGREGATE_TYPE_P (type))
2620 || mode == TFmode))
4697a36c
MM
2621 {
2622 if (TARGET_DEBUG_ARG)
2623 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
2624
2625 return 1;
2626 }
4697a36c
MM
2627
2628 return 0;
2629}
4697a36c
MM
2630\f
2631/* Perform any needed actions needed for a function that is receiving a
2632 variable number of arguments.
2633
2634 CUM is as above.
2635
2636 MODE and TYPE are the mode and type of the current parameter.
2637
2638 PRETEND_SIZE is a variable that should be set to the amount of stack
2639 that must be pushed by the prolog to pretend that our caller pushed
2640 it.
2641
2642 Normally, this macro will push all remaining incoming registers on the
2643 stack and set PRETEND_SIZE to the length of the registers pushed. */
2644
2645void
2646setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2647 CUMULATIVE_ARGS *cum;
2648 enum machine_mode mode;
2649 tree type;
2650 int *pretend_size;
2651 int no_rtl;
2652
2653{
4cc833b7
RH
2654 CUMULATIVE_ARGS next_cum;
2655 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 2656 rtx save_area = NULL_RTX, mem;
dfafc897 2657 int first_reg_offset, set;
d34c5b80
DE
2658 tree fntype;
2659 int stdarg_p;
4697a36c 2660
d34c5b80
DE
2661 fntype = TREE_TYPE (current_function_decl);
2662 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
2663 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2664 != void_type_node));
4cc833b7 2665
d34c5b80
DE
2666 /* For varargs, we do not want to skip the dummy va_dcl argument.
2667 For stdargs, we do want to skip the last named argument. */
2668 next_cum = *cum;
2669 if (stdarg_p)
2670 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 2671
f607bc57 2672 if (DEFAULT_ABI == ABI_V4)
d34c5b80 2673 {
4cc833b7
RH
2674 /* Indicate to allocate space on the stack for varargs save area. */
2675 /* ??? Does this really have to be located at a magic spot on the
2676 stack, or can we allocate this with assign_stack_local instead. */
00dba523 2677 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 2678 if (! no_rtl)
2c4974b7 2679 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 2680 - RS6000_VARARGS_SIZE);
4cc833b7
RH
2681
2682 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 2683 }
60e2d0ca 2684 else
4697a36c 2685 {
d34c5b80 2686 first_reg_offset = next_cum.words;
4cc833b7 2687 save_area = virtual_incoming_args_rtx;
00dba523 2688 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
2689
2690 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 2691 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 2692 }
4697a36c 2693
dfafc897 2694 set = get_varargs_alias_set ();
c81fc13e 2695 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 2696 {
dfafc897
FS
2697 mem = gen_rtx_MEM (BLKmode,
2698 plus_constant (save_area,
2699 first_reg_offset * reg_size)),
ba4828e0 2700 set_mem_alias_set (mem, set);
8ac61af7 2701 set_mem_align (mem, BITS_PER_WORD);
dfafc897 2702
4cc833b7 2703 move_block_from_reg
dfafc897 2704 (GP_ARG_MIN_REG + first_reg_offset, mem,
4cc833b7
RH
2705 GP_ARG_NUM_REG - first_reg_offset,
2706 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
2707
2708 /* ??? Does ABI_V4 need this at all? */
4697a36c
MM
2709 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
2710 }
2711
4697a36c 2712 /* Save FP registers if needed. */
f607bc57 2713 if (DEFAULT_ABI == ABI_V4
c81fc13e 2714 && TARGET_HARD_FLOAT && ! no_rtl
4cc833b7 2715 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 2716 {
4cc833b7 2717 int fregno = next_cum.fregno;
9ebbca7d 2718 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
2719 rtx lab = gen_label_rtx ();
2720 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 2721
4cc833b7 2722 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 2723 pc_rtx,
39403d82 2724 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
2725 gen_rtx_NE (VOIDmode, cr1,
2726 const0_rtx),
39403d82 2727 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
2728 pc_rtx)));
2729
4cc833b7
RH
2730 while (fregno <= FP_ARG_V4_MAX_REG)
2731 {
dfafc897 2732 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 2733 set_mem_alias_set (mem, set);
dfafc897 2734 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
2735 fregno++;
2736 off += 8;
4697a36c 2737 }
4cc833b7
RH
2738
2739 emit_label (lab);
4697a36c 2740 }
4697a36c 2741}
4697a36c 2742
dfafc897 2743/* Create the va_list data type. */
2c4974b7 2744
dfafc897
FS
2745tree
2746rs6000_build_va_list ()
2747{
bab45a51 2748 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4697a36c 2749
9ebbca7d
GK
2750 /* For AIX, prefer 'char *' because that's what the system
2751 header files like. */
f607bc57 2752 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 2753 return build_pointer_type (char_type_node);
dfafc897 2754
0f4fd75d 2755 record = make_lang_type (RECORD_TYPE);
bab45a51 2756 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 2757
9ebbca7d
GK
2758 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
2759 unsigned_char_type_node);
2760 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
2761 unsigned_char_type_node);
dfafc897
FS
2762 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
2763 ptr_type_node);
2764 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
2765 ptr_type_node);
2766
2767 DECL_FIELD_CONTEXT (f_gpr) = record;
2768 DECL_FIELD_CONTEXT (f_fpr) = record;
2769 DECL_FIELD_CONTEXT (f_ovf) = record;
2770 DECL_FIELD_CONTEXT (f_sav) = record;
2771
bab45a51
FS
2772 TREE_CHAIN (record) = type_decl;
2773 TYPE_NAME (record) = type_decl;
dfafc897
FS
2774 TYPE_FIELDS (record) = f_gpr;
2775 TREE_CHAIN (f_gpr) = f_fpr;
2776 TREE_CHAIN (f_fpr) = f_ovf;
2777 TREE_CHAIN (f_ovf) = f_sav;
2778
2779 layout_type (record);
2780
2781 /* The correct type is an array type of one element. */
2782 return build_array_type (record, build_index_type (size_zero_node));
2783}
2784
2785/* Implement va_start. */
2786
2787void
2788rs6000_va_start (stdarg_p, valist, nextarg)
2789 int stdarg_p;
2790 tree valist;
2791 rtx nextarg;
4697a36c 2792{
dfafc897
FS
2793 HOST_WIDE_INT words, n_gpr, n_fpr;
2794 tree f_gpr, f_fpr, f_ovf, f_sav;
2795 tree gpr, fpr, ovf, sav, t;
2c4974b7 2796
dfafc897 2797 /* Only SVR4 needs something special. */
f607bc57 2798 if (DEFAULT_ABI != ABI_V4)
dfafc897
FS
2799 {
2800 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2801 return;
2802 }
2803
973a648b 2804 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
2805 f_fpr = TREE_CHAIN (f_gpr);
2806 f_ovf = TREE_CHAIN (f_fpr);
2807 f_sav = TREE_CHAIN (f_ovf);
2808
8ebecc3b 2809 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
2810 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2811 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2812 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2813 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2814
2815 /* Count number of gp and fp argument registers used. */
4cc833b7 2816 words = current_function_args_info.words;
dfafc897
FS
2817 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
2818 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
2819
2820 if (TARGET_DEBUG_ARG)
78e1b90d
DE
2821 {
2822 fputs ("va_start: words = ", stderr);
2823 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words);
2824 fputs (", n_gpr = ", stderr);
2825 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr);
2826 fputs (", n_fpr = ", stderr);
2827 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr);
2828 putc ('\n', stderr);
2829 }
dfafc897
FS
2830
2831 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
2832 TREE_SIDE_EFFECTS (t) = 1;
2833 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2834
2835 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
2836 TREE_SIDE_EFFECTS (t) = 1;
2837 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2838
2839 /* Find the overflow area. */
2840 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
2841 if (words != 0)
2842 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
2843 build_int_2 (words * UNITS_PER_WORD, 0));
2844 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2845 TREE_SIDE_EFFECTS (t) = 1;
2846 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2847
2848 /* Find the register save area. */
2849 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
2850 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
2851 build_int_2 (-RS6000_VARARGS_SIZE, -1));
2852 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
2853 TREE_SIDE_EFFECTS (t) = 1;
2854 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2855}
2856
2857/* Implement va_arg. */
2858
2859rtx
2860rs6000_va_arg (valist, type)
2861 tree valist, type;
2862{
2863 tree f_gpr, f_fpr, f_ovf, f_sav;
2864 tree gpr, fpr, ovf, sav, reg, t, u;
2865 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
2866 rtx lab_false, lab_over, addr_rtx, r;
2867
9ebbca7d
GK
2868 /* For AIX, the rule is that structures are passed left-aligned in
2869 their stack slot. However, GCC does not presently do this:
2870 structures which are the same size as integer types are passed
2871 right-aligned, as if they were in fact integers. This only
2872 matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */
f607bc57 2873 if (DEFAULT_ABI != ABI_V4)
9ebbca7d
GK
2874 {
2875 HOST_WIDE_INT align, rounded_size;
2876 enum machine_mode mode;
2877 tree addr_tree;
2878
2879 /* Compute the rounded size of the type. */
2880 align = PARM_BOUNDARY / BITS_PER_UNIT;
2881 rounded_size = (((int_size_in_bytes (type) + align - 1) / align)
2882 * align);
2883
2884 addr_tree = valist;
2885
2886 mode = TYPE_MODE (type);
2887 if (mode != BLKmode)
2888 {
2889 HOST_WIDE_INT adj;
2890 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2891 if (rounded_size > align)
2892 adj = rounded_size;
2893
2894 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2895 build_int_2 (rounded_size - adj, 0));
2896 }
2897
2898 addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2899 addr_rtx = copy_to_reg (addr_rtx);
2900
2901 /* Compute new value for AP. */
2902 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2903 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2904 build_int_2 (rounded_size, 0)));
2905 TREE_SIDE_EFFECTS (t) = 1;
2906 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2907
2908 return addr_rtx;
2909 }
dfafc897 2910
973a648b 2911 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
2912 f_fpr = TREE_CHAIN (f_gpr);
2913 f_ovf = TREE_CHAIN (f_fpr);
2914 f_sav = TREE_CHAIN (f_ovf);
2915
8ebecc3b 2916 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
2917 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2918 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2919 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2920 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2921
2922 size = int_size_in_bytes (type);
2923 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 2924
dfafc897 2925 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 2926 {
dfafc897
FS
2927 /* Aggregates and long doubles are passed by reference. */
2928 indirect_p = 1;
2929 reg = gpr;
2930 n_reg = 1;
2931 sav_ofs = 0;
2932 sav_scale = 4;
2933 size = rsize = UNITS_PER_WORD;
2934 }
2935 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
2936 {
2937 /* FP args go in FP registers, if present. */
2938 indirect_p = 0;
2939 reg = fpr;
2940 n_reg = 1;
2941 sav_ofs = 8*4;
2942 sav_scale = 8;
4cc833b7 2943 }
dfafc897
FS
2944 else
2945 {
2946 /* Otherwise into GP registers. */
2947 indirect_p = 0;
2948 reg = gpr;
2949 n_reg = rsize;
2950 sav_ofs = 0;
2951 sav_scale = 4;
2952 }
2953
a4f6c312 2954 /* Pull the value out of the saved registers ... */
dfafc897
FS
2955
2956 lab_false = gen_label_rtx ();
2957 lab_over = gen_label_rtx ();
2958 addr_rtx = gen_reg_rtx (Pmode);
2959
2960 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
a06ef755
RK
2961 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
2962 lab_false);
2c4974b7 2963
dfafc897
FS
2964 /* Long long is aligned in the registers. */
2965 if (n_reg > 1)
2c4974b7 2966 {
dfafc897
FS
2967 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
2968 build_int_2 (n_reg - 1, 0));
2969 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
2970 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
2971 TREE_SIDE_EFFECTS (u) = 1;
2972 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
2c4974b7 2973 }
dfafc897
FS
2974
2975 if (sav_ofs)
2976 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2c4974b7 2977 else
dfafc897 2978 t = sav;
2c4974b7 2979
dfafc897
FS
2980 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
2981 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 2982
dfafc897
FS
2983 u = build1 (CONVERT_EXPR, integer_type_node, u);
2984 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 2985
dfafc897
FS
2986 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
2987 TREE_SIDE_EFFECTS (u) = 1;
2988
2989 t = build (PLUS_EXPR, ptr_type_node, t, u);
2990 TREE_SIDE_EFFECTS (t) = 1;
2991
2992 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2993 if (r != addr_rtx)
2994 emit_move_insn (addr_rtx, r);
2995
2996 emit_jump_insn (gen_jump (lab_over));
2997 emit_barrier ();
2998 emit_label (lab_false);
2999
a4f6c312 3000 /* ... otherwise out of the overflow area. */
dfafc897
FS
3001
3002 /* Make sure we don't find reg 7 for the next int arg. */
3003 if (n_reg > 1)
3004 {
3005 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
3006 TREE_SIDE_EFFECTS (t) = 1;
3007 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3008 }
3009
3010 /* Care for on-stack alignment if needed. */
3011 if (rsize <= 1)
3012 t = ovf;
3013 else
3014 {
3015 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
3016 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
3017 }
3018 t = save_expr (t);
3019
3020 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3021 if (r != addr_rtx)
3022 emit_move_insn (addr_rtx, r);
3023
3024 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
3025 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3026 TREE_SIDE_EFFECTS (t) = 1;
3027 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3028
3029 emit_label (lab_over);
3030
3031 if (indirect_p)
3032 {
3033 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 3034 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
3035 emit_move_insn (addr_rtx, r);
3036 }
3037
3038 return addr_rtx;
4697a36c 3039}
0ac081f6
AH
3040
3041/* Builtins. */
3042
3043#define def_builtin(MASK, NAME, TYPE, CODE) \
3044do { \
3045 if ((MASK) & target_flags) \
3046 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL); \
3047} while (0)
3048
3049struct builtin_description
3050{
3051 const unsigned int mask;
3052 const enum insn_code icode;
3053 const char *const name;
3054 const enum rs6000_builtins code;
3055};
2212663f
DB
3056/* Simple ternary operations: VECd = foo (VECa, VECb, VECc) */
3057static const struct builtin_description bdesc_3arg[] =
3058 {
3059 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
3060 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
3061 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
3062 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
3063 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
3064 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
3065 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
3066 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
3067 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
3068 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
617e0e1d 3069 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
2212663f
DB
3070 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
3071 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
3072 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
3073 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
617e0e1d
DB
3074 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
3075 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
3076 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
3077 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
2212663f
DB
3078 };
3079
3080/* Simple binary operations: VECc = foo (VECa, VECb). */
0ac081f6
AH
3081static const struct builtin_description bdesc_2arg[] =
3082{
f18c054f
DB
3083 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
3084 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
3085 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
3086 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
3087 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
3088 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
3089 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
3090 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
3091 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
3092 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
3093 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 3094 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
3095 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
3096 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
3097 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
3098 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
3099 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
3100 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
3101 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
3102 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
3103 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
3104 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
3105 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
3106 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
3107 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
3108 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
3109 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
3110 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
3111 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
3112 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
3113 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
3114 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
3115 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
3116 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
3117 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
3118 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
3119 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
3120 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
3121 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
3122 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
3123 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
3124 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
3125 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
3126 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
3127 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
3128 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
3129 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
3130 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
3131 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
3132 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
3133 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
3134 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
3135 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
3136 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
3137 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
3138 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
3139 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
3140 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
3141 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
3142 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
3143 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
3144 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
3145 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
3146 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
3147 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 3148 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
3149 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
3150 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
3151 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
3152 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
3153 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
3154 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
3155 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
3156 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
3157 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
3158 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
3159 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
3160 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
3161 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
3162 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
3163 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
3164 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
3165 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
3166 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
3167 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
3168 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
3169 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
3170 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 3171 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
3172 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
3173 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
3174 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
3175 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
3176 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
3177 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
3178 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
3179 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
3180 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
3181 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
3182 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
3183 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
3184 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
3185 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
3186 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
3187 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
3188 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
3189 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
3190 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
3191 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
3192 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
3193 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
3194 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 3195 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
0ac081f6 3196};
617e0e1d
DB
3197/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
3198 foo (VECa). */
2212663f
DB
3199static const struct builtin_description bdesc_1arg[] =
3200{
617e0e1d
DB
3201 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
3202 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
3203 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
3204 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
3205 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
3206 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
3207 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
3208 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
3209 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
3210 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
3211 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
3212};
3213
3214static rtx
3215altivec_expand_unop_builtin (icode, arglist, target)
3216 enum insn_code icode;
3217 tree arglist;
3218 rtx target;
3219{
3220 rtx pat;
3221 tree arg0 = TREE_VALUE (arglist);
3222 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3223 enum machine_mode tmode = insn_data[icode].operand[0].mode;
3224 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
3225
3226 if (! target
3227 || GET_MODE (target) != tmode
3228 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3229 target = gen_reg_rtx (tmode);
3230
3231 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3232 op0 = copy_to_mode_reg (mode0, op0);
3233
3234 pat = GEN_FCN (icode) (target, op0);
3235 if (! pat)
3236 return 0;
3237 emit_insn (pat);
0ac081f6 3238
2212663f
DB
3239 return target;
3240}
0ac081f6
AH
3241static rtx
3242altivec_expand_binop_builtin (icode, arglist, target)
3243 enum insn_code icode;
3244 tree arglist;
3245 rtx target;
3246{
3247 rtx pat;
3248 tree arg0 = TREE_VALUE (arglist);
3249 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3250 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3251 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3252 enum machine_mode tmode = insn_data[icode].operand[0].mode;
3253 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
3254 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
3255
3256 if (! target
3257 || GET_MODE (target) != tmode
3258 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3259 target = gen_reg_rtx (tmode);
3260
3261 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3262 op0 = copy_to_mode_reg (mode0, op0);
3263 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
3264 op1 = copy_to_mode_reg (mode1, op1);
3265
3266 pat = GEN_FCN (icode) (target, op0, op1);
3267 if (! pat)
3268 return 0;
3269 emit_insn (pat);
3270
3271 return target;
3272}
2212663f
DB
3273static rtx
3274altivec_expand_ternop_builtin (icode, arglist, target)
3275 enum insn_code icode;
3276 tree arglist;
3277 rtx target;
3278{
3279 rtx pat;
3280 tree arg0 = TREE_VALUE (arglist);
3281 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3282 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
3283 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3284 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3285 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
3286 enum machine_mode tmode = insn_data[icode].operand[0].mode;
3287 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
3288 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
3289 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 3290
2212663f
DB
3291 if (! target
3292 || GET_MODE (target) != tmode
3293 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3294 target = gen_reg_rtx (tmode);
3295
3296 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3297 op0 = copy_to_mode_reg (mode0, op0);
3298 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
3299 op1 = copy_to_mode_reg (mode1, op1);
3300 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
3301 op2 = copy_to_mode_reg (mode2, op2);
3302
3303 pat = GEN_FCN (icode) (target, op0, op1, op2);
3304 if (! pat)
3305 return 0;
3306 emit_insn (pat);
3307
3308 return target;
3309}
0ac081f6 3310static rtx
00b960c7 3311altivec_expand_builtin (exp, target)
0ac081f6
AH
3312 tree exp;
3313 rtx target;
0ac081f6
AH
3314{
3315 struct builtin_description *d;
3316 size_t i;
3317 enum insn_code icode;
3318 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
3319 tree arglist = TREE_OPERAND (exp, 1);
00b960c7
AH
3320 tree arg0, arg1;
3321 rtx op0, op1, pat;
3322 enum machine_mode tmode, mode0, mode1;
0ac081f6
AH
3323 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3324
3325 switch (fcode)
3326 {
f18c054f
DB
3327 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
3328 icode = CODE_FOR_altivec_lvx_16qi;
0ac081f6
AH
3329 arg0 = TREE_VALUE (arglist);
3330 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3331 tmode = insn_data[icode].operand[0].mode;
3332 mode0 = insn_data[icode].operand[1].mode;
3333
3334 if (! target
3335 || GET_MODE (target) != tmode
3336 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3337 target = gen_reg_rtx (tmode);
3338
3339 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3340 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3341
3342 pat = GEN_FCN (icode) (target, op0);
3343 if (! pat)
3344 return 0;
3345 emit_insn (pat);
3346 return target;
f18c054f
DB
3347 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
3348 icode = CODE_FOR_altivec_lvx_8hi;
3349 arg0 = TREE_VALUE (arglist);
3350 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3351 tmode = insn_data[icode].operand[0].mode;
3352 mode0 = insn_data[icode].operand[1].mode;
0ac081f6 3353
f18c054f
DB
3354 if (! target
3355 || GET_MODE (target) != tmode
3356 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3357 target = gen_reg_rtx (tmode);
3358
3359 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3360 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3361
3362 pat = GEN_FCN (icode) (target, op0);
3363 if (! pat)
3364 return 0;
3365 emit_insn (pat);
3366 return target;
3367 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
3368 icode = CODE_FOR_altivec_lvx_4si;
3369 arg0 = TREE_VALUE (arglist);
3370 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3371 tmode = insn_data[icode].operand[0].mode;
3372 mode0 = insn_data[icode].operand[1].mode;
3373
3374 if (! target
3375 || GET_MODE (target) != tmode
3376 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3377 target = gen_reg_rtx (tmode);
3378
3379 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3380 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3381
3382 pat = GEN_FCN (icode) (target, op0);
3383 if (! pat)
3384 return 0;
3385 emit_insn (pat);
3386 return target;
3387 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
3388 icode = CODE_FOR_altivec_lvx_4sf;
3389 arg0 = TREE_VALUE (arglist);
3390 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3391 tmode = insn_data[icode].operand[0].mode;
3392 mode0 = insn_data[icode].operand[1].mode;
3393
3394 if (! target
3395 || GET_MODE (target) != tmode
3396 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
3397 target = gen_reg_rtx (tmode);
3398
3399 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
3400 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3401
3402 pat = GEN_FCN (icode) (target, op0);
3403 if (! pat)
3404 return 0;
3405 emit_insn (pat);
3406 return target;
3407
3408 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
3409 icode = CODE_FOR_altivec_stvx_16qi;
3410 arg0 = TREE_VALUE (arglist);
3411 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3412 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3413 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3414 mode0 = insn_data[icode].operand[0].mode;
3415 mode1 = insn_data[icode].operand[1].mode;
3416
3417 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
3418 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3419 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
3420 op1 = copy_to_mode_reg (mode1, op1);
3421
3422 pat = GEN_FCN (icode) (op0, op1);
3423 if (! pat)
3424 return 0;
3425 emit_insn (pat);
3426 return NULL_RTX;
3427 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
3428 icode = CODE_FOR_altivec_stvx_8hi;
3429 arg0 = TREE_VALUE (arglist);
3430 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3431 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3432 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3433 mode0 = insn_data[icode].operand[0].mode;
3434 mode1 = insn_data[icode].operand[1].mode;
3435
3436 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
3437 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3438 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
3439 op1 = copy_to_mode_reg (mode1, op1);
3440
3441 pat = GEN_FCN (icode) (op0, op1);
3442 if (! pat)
3443 return 0;
3444 emit_insn (pat);
3445 return NULL_RTX;
3446 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
3447 icode = CODE_FOR_altivec_stvx_4si;
3448 arg0 = TREE_VALUE (arglist);
3449 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3450 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3451 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3452 mode0 = insn_data[icode].operand[0].mode;
3453 mode1 = insn_data[icode].operand[1].mode;
3454
3455 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
3456 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3457 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
3458 op1 = copy_to_mode_reg (mode1, op1);
3459
3460 pat = GEN_FCN (icode) (op0, op1);
3461 if (! pat)
3462 return 0;
3463 emit_insn (pat);
3464 return NULL_RTX;
3465 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
3466 icode = CODE_FOR_altivec_stvx_4sf;
0ac081f6
AH
3467 arg0 = TREE_VALUE (arglist);
3468 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
3469 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
3470 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
3471 mode0 = insn_data[icode].operand[0].mode;
3472 mode1 = insn_data[icode].operand[1].mode;
3473
3474 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
3475 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3476 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
3477 op1 = copy_to_mode_reg (mode1, op1);
3478
3479 pat = GEN_FCN (icode) (op0, op1);
3480 if (! pat)
3481 return 0;
3482 emit_insn (pat);
3483 return NULL_RTX;
3484 }
2212663f
DB
3485 /* Handle simple unary operations. */
3486 d = (struct builtin_description *) bdesc_1arg;
3487 for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
3488 if (d->code == fcode)
3489 return altivec_expand_unop_builtin (d->icode, arglist, target);
0ac081f6
AH
3490
3491 /* Handle simple binary operations. */
00b960c7
AH
3492 d = (struct builtin_description *) bdesc_2arg;
3493 for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
0ac081f6
AH
3494 if (d->code == fcode)
3495 return altivec_expand_binop_builtin (d->icode, arglist, target);
3496
2212663f
DB
3497 /* Handle simple ternary operations. */
3498 d = (struct builtin_description *) bdesc_3arg;
3499 for (i = 0; i < sizeof (bdesc_3arg) / sizeof *d; i++, d++)
3500 if (d->code == fcode)
3501 return altivec_expand_ternop_builtin (d->icode, arglist, target);
3502
0ac081f6
AH
3503 abort ();
3504 return NULL_RTX;
3505}
3506
3507/* Expand an expression EXP that calls a built-in function,
3508 with result going to TARGET if that's convenient
3509 (and in mode MODE if that's convenient).
3510 SUBTARGET may be used as the target for computing one of EXP's operands.
3511 IGNORE is nonzero if the value is to be ignored. */
3512
3513static rtx
3514rs6000_expand_builtin (exp, target, subtarget, mode, ignore)
3515 tree exp;
3516 rtx target;
00b960c7
AH
3517 rtx subtarget ATTRIBUTE_UNUSED;
3518 enum machine_mode mode ATTRIBUTE_UNUSED;
3519 int ignore ATTRIBUTE_UNUSED;
0ac081f6
AH
3520{
3521 if (TARGET_ALTIVEC)
00b960c7 3522 return altivec_expand_builtin (exp, target);
0ac081f6
AH
3523
3524 abort ();
3525}
3526
3527static void
6fa3f289 3528rs6000_init_builtins ()
0ac081f6
AH
3529{
3530 if (TARGET_ALTIVEC)
3531 altivec_init_builtins ();
3532}
3533
3534static void
3535altivec_init_builtins (void)
3536{
3537 struct builtin_description * d;
3538 size_t i;
3539
3540 tree endlink = void_list_node;
3541
3542 tree pint_type_node = build_pointer_type (integer_type_node);
f18c054f
DB
3543 tree pshort_type_node = build_pointer_type (short_integer_type_node);
3544 tree pchar_type_node = build_pointer_type (char_type_node);
3545 tree pfloat_type_node = build_pointer_type (float_type_node);
2212663f
DB
3546 tree v4sf_ftype_v4sf_v4sf_v16qi
3547 = build_function_type (V4SF_type_node,
3548 tree_cons (NULL_TREE, V4SF_type_node,
3549 tree_cons (NULL_TREE, V4SF_type_node,
3550 tree_cons (NULL_TREE,
3551 V16QI_type_node,
3552 endlink))));
3553 tree v4si_ftype_v4si_v4si_v16qi
3554 = build_function_type (V4SI_type_node,
3555 tree_cons (NULL_TREE, V4SI_type_node,
3556 tree_cons (NULL_TREE, V4SI_type_node,
3557 tree_cons (NULL_TREE,
3558 V16QI_type_node,
3559 endlink))));
3560 tree v8hi_ftype_v8hi_v8hi_v16qi
3561 = build_function_type (V8HI_type_node,
3562 tree_cons (NULL_TREE, V8HI_type_node,
3563 tree_cons (NULL_TREE, V8HI_type_node,
3564 tree_cons (NULL_TREE,
3565 V16QI_type_node,
3566 endlink))));
3567 tree v16qi_ftype_v16qi_v16qi_v16qi
3568 = build_function_type (V16QI_type_node,
3569 tree_cons (NULL_TREE, V16QI_type_node,
3570 tree_cons (NULL_TREE, V16QI_type_node,
3571 tree_cons (NULL_TREE,
3572 V16QI_type_node,
3573 endlink))));
3574
3575 /* V4SI foo (char) */
3576 tree v4si_ftype_char
3577 = build_function_type (V4SI_type_node,
3578 tree_cons (NULL_TREE, char_type_node, endlink));
3579
3580 /* V8HI foo (char) */
3581 tree v8hi_ftype_char
3582 = build_function_type (V8HI_type_node,
3583 tree_cons (NULL_TREE, char_type_node, endlink));
3584
3585 /* V16QI foo (char) */
3586 tree v16qi_ftype_char
3587 = build_function_type (V16QI_type_node,
3588 tree_cons (NULL_TREE, char_type_node, endlink));
617e0e1d
DB
3589 /* V4SF foo (V4SF) */
3590 tree v4sf_ftype_v4sf
3591 = build_function_type (V4SF_type_node,
3592 tree_cons (NULL_TREE, V4SF_type_node, endlink));
0ac081f6
AH
3593
3594 /* V4SI foo (int *). */
3595 tree v4si_ftype_pint
3596 = build_function_type (V4SI_type_node,
3597 tree_cons (NULL_TREE, pint_type_node, endlink));
f18c054f
DB
3598 /* V8HI foo (short *). */
3599 tree v8hi_ftype_pshort
3600 = build_function_type (V8HI_type_node,
3601 tree_cons (NULL_TREE, pshort_type_node, endlink));
3602 /* V16QI foo (char *). */
3603 tree v16qi_ftype_pchar
3604 = build_function_type (V16QI_type_node,
3605 tree_cons (NULL_TREE, pchar_type_node, endlink));
3606 /* V4SF foo (float *). */
3607 tree v4sf_ftype_pfloat
3608 = build_function_type (V4SF_type_node,
3609 tree_cons (NULL_TREE, pfloat_type_node, endlink));
0ac081f6
AH
3610
3611 /* void foo (int *, V4SI). */
3612 tree void_ftype_pint_v4si
3613 = build_function_type (void_type_node,
3614 tree_cons (NULL_TREE, pint_type_node,
3615 tree_cons (NULL_TREE, V4SI_type_node,
3616 endlink)));
f18c054f
DB
3617 /* void foo (short *, V8HI). */
3618 tree void_ftype_pshort_v8hi
3619 = build_function_type (void_type_node,
3620 tree_cons (NULL_TREE, pshort_type_node,
3621 tree_cons (NULL_TREE, V8HI_type_node,
3622 endlink)));
3623 /* void foo (char *, V16QI). */
3624 tree void_ftype_pchar_v16qi
3625 = build_function_type (void_type_node,
3626 tree_cons (NULL_TREE, pchar_type_node,
3627 tree_cons (NULL_TREE, V16QI_type_node,
3628 endlink)));
3629 /* void foo (float *, V4SF). */
3630 tree void_ftype_pfloat_v4sf
3631 = build_function_type (void_type_node,
3632 tree_cons (NULL_TREE, pfloat_type_node,
3633 tree_cons (NULL_TREE, V4SF_type_node,
3634 endlink)));
0ac081f6
AH
3635
3636 tree v4si_ftype_v4si_v4si
3637 = build_function_type (V4SI_type_node,
3638 tree_cons (NULL_TREE, V4SI_type_node,
3639 tree_cons (NULL_TREE, V4SI_type_node,
3640 endlink)));
2212663f 3641 /* These are really for the unsigned 5 bit literals */
617e0e1d
DB
3642 tree v4sf_ftype_v4si_char
3643 = build_function_type (V4SF_type_node,
3644 tree_cons (NULL_TREE, V4SI_type_node,
3645 tree_cons (NULL_TREE, char_type_node,
3646 endlink)));
3647 tree v4si_ftype_v4sf_char
3648 = build_function_type (V4SI_type_node,
3649 tree_cons (NULL_TREE, V4SF_type_node,
3650 tree_cons (NULL_TREE, char_type_node,
3651 endlink)));
2212663f
DB
3652 tree v4si_ftype_v4si_char
3653 = build_function_type (V4SI_type_node,
3654 tree_cons (NULL_TREE, V4SI_type_node,
3655 tree_cons (NULL_TREE, char_type_node,
3656 endlink)));
3657 tree v8hi_ftype_v8hi_char
3658 = build_function_type (V8HI_type_node,
3659 tree_cons (NULL_TREE, V8HI_type_node,
3660 tree_cons (NULL_TREE, char_type_node,
3661 endlink)));
3662 tree v16qi_ftype_v16qi_char
3663 = build_function_type (V16QI_type_node,
3664 tree_cons (NULL_TREE, V16QI_type_node,
3665 tree_cons (NULL_TREE, char_type_node,
3666 endlink)));
0ac081f6
AH
3667
3668 tree v4sf_ftype_v4sf_v4sf
3669 = build_function_type (V4SF_type_node,
3670 tree_cons (NULL_TREE, V4SF_type_node,
3671 tree_cons (NULL_TREE, V4SF_type_node,
3672 endlink)));
617e0e1d
DB
3673 tree v4sf_ftype_v4sf_v4sf_v4si
3674 = build_function_type (V4SF_type_node,
3675 tree_cons (NULL_TREE, V4SF_type_node,
3676 tree_cons (NULL_TREE, V4SF_type_node,
3677 tree_cons (NULL_TREE,
3678 V4SI_type_node,
3679 endlink))));
2212663f
DB
3680 tree v4sf_ftype_v4sf_v4sf_v4sf
3681 = build_function_type (V4SF_type_node,
3682 tree_cons (NULL_TREE, V4SF_type_node,
3683 tree_cons (NULL_TREE, V4SF_type_node,
3684 tree_cons (NULL_TREE,
3685 V4SF_type_node,
3686 endlink))));
617e0e1d
DB
3687 tree v4si_ftype_v4si_v4si_v4si
3688 = build_function_type (V4SI_type_node,
3689 tree_cons (NULL_TREE, V4SI_type_node,
3690 tree_cons (NULL_TREE, V4SI_type_node,
3691 tree_cons (NULL_TREE,
3692 V4SI_type_node,
3693 endlink))));
2212663f 3694
0ac081f6
AH
3695 tree v8hi_ftype_v8hi_v8hi
3696 = build_function_type (V8HI_type_node,
3697 tree_cons (NULL_TREE, V8HI_type_node,
3698 tree_cons (NULL_TREE, V8HI_type_node,
3699 endlink)));
2212663f
DB
3700 tree v8hi_ftype_v8hi_v8hi_v8hi
3701 = build_function_type (V8HI_type_node,
3702 tree_cons (NULL_TREE, V8HI_type_node,
3703 tree_cons (NULL_TREE, V8HI_type_node,
3704 tree_cons (NULL_TREE,
3705 V8HI_type_node,
3706 endlink))));
3707 tree v4si_ftype_v8hi_v8hi_v4si
3708 = build_function_type (V4SI_type_node,
3709 tree_cons (NULL_TREE, V8HI_type_node,
3710 tree_cons (NULL_TREE, V8HI_type_node,
3711 tree_cons (NULL_TREE,
3712 V4SI_type_node,
3713 endlink))));
3714 tree v4si_ftype_v16qi_v16qi_v4si
3715 = build_function_type (V4SI_type_node,
3716 tree_cons (NULL_TREE, V16QI_type_node,
3717 tree_cons (NULL_TREE, V16QI_type_node,
3718 tree_cons (NULL_TREE,
3719 V4SI_type_node,
3720 endlink))));
3721
0ac081f6
AH
3722 tree v16qi_ftype_v16qi_v16qi
3723 = build_function_type (V16QI_type_node,
3724 tree_cons (NULL_TREE, V16QI_type_node,
3725 tree_cons (NULL_TREE, V16QI_type_node,
3726 endlink)));
2212663f 3727
0ac081f6
AH
3728 tree v4si_ftype_v4sf_v4sf
3729 = build_function_type (V4SI_type_node,
3730 tree_cons (NULL_TREE, V4SF_type_node,
3731 tree_cons (NULL_TREE, V4SF_type_node,
3732 endlink)));
3733
3734 tree v8hi_ftype_v16qi_v16qi
3735 = build_function_type (V8HI_type_node,
3736 tree_cons (NULL_TREE, V16QI_type_node,
3737 tree_cons (NULL_TREE, V16QI_type_node,
3738 endlink)));
3739
3740 tree v4si_ftype_v8hi_v8hi
3741 = build_function_type (V4SI_type_node,
3742 tree_cons (NULL_TREE, V8HI_type_node,
3743 tree_cons (NULL_TREE, V8HI_type_node,
3744 endlink)));
3745
3746 tree v8hi_ftype_v4si_v4si
3747 = build_function_type (V8HI_type_node,
3748 tree_cons (NULL_TREE, V4SI_type_node,
3749 tree_cons (NULL_TREE, V4SI_type_node,
3750 endlink)));
3751
3752 tree v16qi_ftype_v8hi_v8hi
3753 = build_function_type (V16QI_type_node,
3754 tree_cons (NULL_TREE, V8HI_type_node,
3755 tree_cons (NULL_TREE, V8HI_type_node,
3756 endlink)));
3757
3758 tree v4si_ftype_v16qi_v4si
3759 = build_function_type (V4SI_type_node,
3760 tree_cons (NULL_TREE, V16QI_type_node,
3761 tree_cons (NULL_TREE, V4SI_type_node,
3762 endlink)));
3763
3764 tree v4si_ftype_v8hi_v4si
3765 = build_function_type (V4SI_type_node,
3766 tree_cons (NULL_TREE, V8HI_type_node,
3767 tree_cons (NULL_TREE, V4SI_type_node,
3768 endlink)));
3769
3770 tree int_ftype_v4si_v4si
3771 = build_function_type (integer_type_node,
3772 tree_cons (NULL_TREE, V4SI_type_node,
3773 tree_cons (NULL_TREE, V4SI_type_node,
3774 endlink)));
3775
3776 tree int_ftype_v4sf_v4sf
3777 = build_function_type (integer_type_node,
3778 tree_cons (NULL_TREE, V4SF_type_node,
3779 tree_cons (NULL_TREE, V4SF_type_node,
3780 endlink)));
3781
3782 tree int_ftype_v16qi_v16qi
3783 = build_function_type (integer_type_node,
3784 tree_cons (NULL_TREE, V16QI_type_node,
3785 tree_cons (NULL_TREE, V16QI_type_node,
3786 endlink)));
3787
3788 tree int_ftype_v8hi_v8hi
3789 = build_function_type (integer_type_node,
3790 tree_cons (NULL_TREE, V8HI_type_node,
3791 tree_cons (NULL_TREE, V8HI_type_node,
3792 endlink)));
3793
f18c054f
DB
3794 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pfloat, ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
3795 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
3796 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pint, ALTIVEC_BUILTIN_LD_INTERNAL_4si);
3797 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, ALTIVEC_BUILTIN_ST_INTERNAL_4si);
3798 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pshort, ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
3799 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
3800 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pchar, ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
3801 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
0ac081f6 3802
2212663f
DB
3803 /* Add the simple ternary operators. */
3804 d = (struct builtin_description *) bdesc_3arg;
3805 for (i = 0; i < sizeof (bdesc_3arg) / sizeof *d; i++, d++)
3806 {
3807
3808 enum machine_mode mode0, mode1, mode2, mode3;
3809 tree type;
3810
3811 if (d->name == 0)
3812 continue;
3813
3814 mode0 = insn_data[d->icode].operand[0].mode;
3815 mode1 = insn_data[d->icode].operand[1].mode;
3816 mode2 = insn_data[d->icode].operand[2].mode;
3817 mode3 = insn_data[d->icode].operand[3].mode;
3818
3819 /* When all four are of the same mode. */
3820 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
3821 {
3822 switch (mode0)
3823 {
617e0e1d
DB
3824 case V4SImode:
3825 type = v4si_ftype_v4si_v4si_v4si;
3826 break;
2212663f
DB
3827 case V4SFmode:
3828 type = v4sf_ftype_v4sf_v4sf_v4sf;
3829 break;
3830 case V8HImode:
3831 type = v8hi_ftype_v8hi_v8hi_v8hi;
3832 break;
3833 case V16QImode:
3834 type = v16qi_ftype_v16qi_v16qi_v16qi;
3835 break;
3836 default:
3837 abort();
3838 }
3839 }
3840 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
3841 {
3842 switch (mode0)
3843 {
3844 case V4SImode:
3845 type = v4si_ftype_v4si_v4si_v16qi;
3846 break;
3847 case V4SFmode:
3848 type = v4sf_ftype_v4sf_v4sf_v16qi;
3849 break;
3850 case V8HImode:
3851 type = v8hi_ftype_v8hi_v8hi_v16qi;
3852 break;
3853 case V16QImode:
3854 type = v16qi_ftype_v16qi_v16qi_v16qi;
3855 break;
3856 default:
3857 abort();
3858 }
3859 }
3860 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
3861 && mode3 == V4SImode)
2212663f 3862 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
3863 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
3864 && mode3 == V4SImode)
2212663f 3865 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
3866 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
3867 && mode3 == V4SImode)
3868 type = v4sf_ftype_v4sf_v4sf_v4si;
2212663f
DB
3869 else
3870 abort ();
3871
3872 def_builtin (d->mask, d->name, type, d->code);
3873 }
3874
0ac081f6 3875 /* Add the simple binary operators. */
00b960c7
AH
3876 d = (struct builtin_description *) bdesc_2arg;
3877 for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
0ac081f6
AH
3878 {
3879 enum machine_mode mode0, mode1, mode2;
3880 tree type;
3881
3882 if (d->name == 0)
3883 continue;
3884
3885 mode0 = insn_data[d->icode].operand[0].mode;
3886 mode1 = insn_data[d->icode].operand[1].mode;
3887 mode2 = insn_data[d->icode].operand[2].mode;
3888
3889 /* When all three operands are of the same mode. */
3890 if (mode0 == mode1 && mode1 == mode2)
3891 {
3892 switch (mode0)
3893 {
3894 case V4SFmode:
3895 type = v4sf_ftype_v4sf_v4sf;
3896 break;
3897 case V4SImode:
3898 type = v4si_ftype_v4si_v4si;
3899 break;
3900 case V16QImode:
3901 type = v16qi_ftype_v16qi_v16qi;
3902 break;
3903 case V8HImode:
3904 type = v8hi_ftype_v8hi_v8hi;
3905 break;
3906 default:
3907 abort ();
3908 }
3909 }
3910
3911 /* A few other combos we really don't want to do manually. */
3912
3913 /* vint, vfloat, vfloat. */
3914 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
3915 type = v4si_ftype_v4sf_v4sf;
3916
3917 /* vshort, vchar, vchar. */
3918 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
3919 type = v8hi_ftype_v16qi_v16qi;
3920
3921 /* vint, vshort, vshort. */
3922 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
3923 type = v4si_ftype_v8hi_v8hi;
3924
3925 /* vshort, vint, vint. */
3926 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
3927 type = v8hi_ftype_v4si_v4si;
3928
3929 /* vchar, vshort, vshort. */
3930 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
3931 type = v16qi_ftype_v8hi_v8hi;
3932
3933 /* vint, vchar, vint. */
3934 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
3935 type = v4si_ftype_v16qi_v4si;
3936
3937 /* vint, vshort, vint. */
3938 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
3939 type = v4si_ftype_v8hi_v4si;
2212663f
DB
3940
3941 /* vint, vint, 5 bit literal. */
3942 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
3943 type = v4si_ftype_v4si_char;
3944
3945 /* vshort, vshort, 5 bit literal. */
3946 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
3947 type = v8hi_ftype_v8hi_char;
3948
3949 /* vchar, vchar, 5 bit literal. */
3950 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
3951 type = v16qi_ftype_v16qi_char;
0ac081f6 3952
617e0e1d
DB
3953 /* vfloat, vint, 5 bit literal. */
3954 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
3955 type = v4sf_ftype_v4si_char;
3956
3957 /* vint, vfloat, 5 bit literal. */
3958 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
3959 type = v4si_ftype_v4sf_char;
3960
0ac081f6
AH
3961 /* fixme: aldyh */
3962 /* int, x, x. */
3963 else if (mode0 == SImode)
3964 {
3965 switch (mode1)
3966 {
3967 case V4SImode:
3968 type = int_ftype_v4si_v4si;
3969 break;
3970 case V4SFmode:
3971 type = int_ftype_v4sf_v4sf;
3972 break;
3973 case V16QImode:
3974 type = int_ftype_v16qi_v16qi;
3975 break;
3976 case V8HImode:
3977 type = int_ftype_v8hi_v8hi;
3978 break;
3979 default:
3980 abort ();
3981 }
3982 }
3983
3984 else
3985 abort ();
3986
2212663f
DB
3987 def_builtin (d->mask, d->name, type, d->code);
3988 }
3989 /* Add the simple unary operators. */
3990 d = (struct builtin_description *) bdesc_1arg;
3991 for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
3992 {
3993 enum machine_mode mode0, mode1;
3994 tree type;
3995
3996 if (d->name == 0)
3997 continue;
3998
3999 mode0 = insn_data[d->icode].operand[0].mode;
4000 mode1 = insn_data[d->icode].operand[1].mode;
4001
4002 if (mode0 == V4SImode && mode1 == QImode)
4003 type = v4si_ftype_char;
4004 else if (mode0 == V8HImode && mode1 == QImode)
4005 type = v8hi_ftype_char;
4006 else if (mode0 == V16QImode && mode1 == QImode)
4007 type = v16qi_ftype_char;
617e0e1d
DB
4008 else if (mode0 == V4SFmode && mode1 == V4SFmode)
4009 type = v4sf_ftype_v4sf;
2212663f
DB
4010 else
4011 abort ();
4012
0ac081f6
AH
4013 def_builtin (d->mask, d->name, type, d->code);
4014 }
4015}
4016
5b5040b9
RK
4017\f
4018/* Generate a memory reference for expand_block_move, copying volatile,
4019 and other bits from an original memory reference. */
4020
4021static rtx
4022expand_block_move_mem (mode, addr, orig_mem)
4023 enum machine_mode mode;
4024 rtx addr;
4025 rtx orig_mem;
4026{
39403d82 4027 rtx mem = gen_rtx_MEM (mode, addr);
b6c9286a 4028
c6df88cb 4029 MEM_COPY_ATTRIBUTES (mem, orig_mem);
5b5040b9
RK
4030 return mem;
4031}
4032
7e69e155
MM
4033/* Expand a block move operation, and return 1 if successful. Return 0
4034 if we should let the compiler generate normal code.
4035
4036 operands[0] is the destination
4037 operands[1] is the source
4038 operands[2] is the length
4039 operands[3] is the alignment */
4040
3933e0e1
MM
4041#define MAX_MOVE_REG 4
4042
7e69e155
MM
4043int
4044expand_block_move (operands)
4045 rtx operands[];
4046{
b6c9286a
MM
4047 rtx orig_dest = operands[0];
4048 rtx orig_src = operands[1];
7e69e155 4049 rtx bytes_rtx = operands[2];
7e69e155 4050 rtx align_rtx = operands[3];
3933e0e1 4051 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 4052 int align;
3933e0e1
MM
4053 int bytes;
4054 int offset;
4055 int num_reg;
4056 int i;
7e69e155
MM
4057 rtx src_reg;
4058 rtx dest_reg;
3933e0e1
MM
4059 rtx src_addr;
4060 rtx dest_addr;
7e69e155 4061 rtx tmp_reg;
3933e0e1 4062 rtx stores[MAX_MOVE_REG];
7e69e155
MM
4063 int move_bytes;
4064
3933e0e1 4065 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 4066 if (! constp)
3933e0e1
MM
4067 return 0;
4068
5ee95df6
FS
4069 /* If this is not a fixed size alignment, abort */
4070 if (GET_CODE (align_rtx) != CONST_INT)
4071 abort ();
4072 align = INTVAL (align_rtx);
4073
7e69e155 4074 /* Anything to move? */
3933e0e1
MM
4075 bytes = INTVAL (bytes_rtx);
4076 if (bytes <= 0)
7e69e155
MM
4077 return 1;
4078
ea9982a8
TR
4079 /* store_one_arg depends on expand_block_move to handle at least the size of
4080 reg_parm_stack_space. */
4081 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
4082 return 0;
4083
4084 /* Move the address into scratch registers. */
b6c9286a
MM
4085 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
4086 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
7e69e155 4087
3933e0e1 4088 if (TARGET_STRING) /* string instructions are available */
7e69e155 4089 {
3933e0e1 4090 for ( ; bytes > 0; bytes -= move_bytes)
7e69e155 4091 {
3933e0e1 4092 if (bytes > 24 /* move up to 32 bytes at a time */
cc0d9ba8
DE
4093 && ! fixed_regs[5]
4094 && ! fixed_regs[6]
4095 && ! fixed_regs[7]
4096 && ! fixed_regs[8]
4097 && ! fixed_regs[9]
4098 && ! fixed_regs[10]
4099 && ! fixed_regs[11]
4100 && ! fixed_regs[12])
3933e0e1
MM
4101 {
4102 move_bytes = (bytes > 32) ? 32 : bytes;
cc0d9ba8
DE
4103 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
4104 dest_reg,
4105 orig_dest),
4106 expand_block_move_mem (BLKmode,
4107 src_reg,
4108 orig_src),
4109 GEN_INT ((move_bytes == 32)
4110 ? 0 : move_bytes),
4c64a852 4111 align_rtx));
3933e0e1
MM
4112 }
4113 else if (bytes > 16 /* move up to 24 bytes at a time */
f9562f27
DE
4114 && ! fixed_regs[5]
4115 && ! fixed_regs[6]
cc0d9ba8
DE
4116 && ! fixed_regs[7]
4117 && ! fixed_regs[8]
4118 && ! fixed_regs[9]
f9562f27 4119 && ! fixed_regs[10])
3933e0e1
MM
4120 {
4121 move_bytes = (bytes > 24) ? 24 : bytes;
cc0d9ba8
DE
4122 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
4123 dest_reg,
4124 orig_dest),
4125 expand_block_move_mem (BLKmode,
4126 src_reg,
4127 orig_src),
3933e0e1 4128 GEN_INT (move_bytes),
4c64a852 4129 align_rtx));
3933e0e1
MM
4130 }
4131 else if (bytes > 8 /* move up to 16 bytes at a time */
f9562f27
DE
4132 && ! fixed_regs[5]
4133 && ! fixed_regs[6]
4134 && ! fixed_regs[7]
4135 && ! fixed_regs[8])
3933e0e1
MM
4136 {
4137 move_bytes = (bytes > 16) ? 16 : bytes;
cc0d9ba8
DE
4138 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
4139 dest_reg,
4140 orig_dest),
4141 expand_block_move_mem (BLKmode,
4142 src_reg,
4143 orig_src),
3933e0e1 4144 GEN_INT (move_bytes),
4c64a852 4145 align_rtx));
3933e0e1 4146 }
acad7ed3 4147 else if (bytes >= 8 && TARGET_POWERPC64
a4f6c312 4148 /* 64-bit loads and stores require word-aligned
82e41834 4149 displacements. */
a4f6c312 4150 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
acad7ed3
DE
4151 {
4152 move_bytes = 8;
4153 tmp_reg = gen_reg_rtx (DImode);
4154 emit_move_insn (tmp_reg,
4155 expand_block_move_mem (DImode,
2eba1afa 4156 src_reg, orig_src));
acad7ed3 4157 emit_move_insn (expand_block_move_mem (DImode,
2eba1afa 4158 dest_reg, orig_dest),
acad7ed3
DE
4159 tmp_reg);
4160 }
09a625f7 4161 else if (bytes > 4 && !TARGET_POWERPC64)
3933e0e1
MM
4162 { /* move up to 8 bytes at a time */
4163 move_bytes = (bytes > 8) ? 8 : bytes;
cc0d9ba8
DE
4164 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
4165 dest_reg,
4166 orig_dest),
4167 expand_block_move_mem (BLKmode,
4168 src_reg,
4169 orig_src),
3933e0e1 4170 GEN_INT (move_bytes),
4c64a852 4171 align_rtx));
3933e0e1 4172 }
cc0d9ba8 4173 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
4174 { /* move 4 bytes */
4175 move_bytes = 4;
4176 tmp_reg = gen_reg_rtx (SImode);
cc0d9ba8
DE
4177 emit_move_insn (tmp_reg,
4178 expand_block_move_mem (SImode,
4179 src_reg, orig_src));
4180 emit_move_insn (expand_block_move_mem (SImode,
4181 dest_reg, orig_dest),
4182 tmp_reg);
3933e0e1 4183 }
cc0d9ba8 4184 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
4185 { /* move 2 bytes */
4186 move_bytes = 2;
4187 tmp_reg = gen_reg_rtx (HImode);
cc0d9ba8
DE
4188 emit_move_insn (tmp_reg,
4189 expand_block_move_mem (HImode,
4190 src_reg, orig_src));
4191 emit_move_insn (expand_block_move_mem (HImode,
4192 dest_reg, orig_dest),
4193 tmp_reg);
3933e0e1
MM
4194 }
4195 else if (bytes == 1) /* move 1 byte */
4196 {
4197 move_bytes = 1;
4198 tmp_reg = gen_reg_rtx (QImode);
cc0d9ba8
DE
4199 emit_move_insn (tmp_reg,
4200 expand_block_move_mem (QImode,
4201 src_reg, orig_src));
4202 emit_move_insn (expand_block_move_mem (QImode,
4203 dest_reg, orig_dest),
4204 tmp_reg);
3933e0e1
MM
4205 }
4206 else
4207 { /* move up to 4 bytes at a time */
4208 move_bytes = (bytes > 4) ? 4 : bytes;
cc0d9ba8
DE
4209 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
4210 dest_reg,
4211 orig_dest),
4212 expand_block_move_mem (BLKmode,
4213 src_reg,
4214 orig_src),
3933e0e1 4215 GEN_INT (move_bytes),
4c64a852 4216 align_rtx));
3933e0e1 4217 }
4c64a852 4218
015892ee
RK
4219 if (bytes > move_bytes)
4220 {
cc0d9ba8
DE
4221 if (! TARGET_POWERPC64)
4222 {
4223 emit_insn (gen_addsi3 (src_reg, src_reg,
4224 GEN_INT (move_bytes)));
4225 emit_insn (gen_addsi3 (dest_reg, dest_reg,
4226 GEN_INT (move_bytes)));
4227 }
4228 else
4229 {
4230 emit_insn (gen_adddi3 (src_reg, src_reg,
4231 GEN_INT (move_bytes)));
4232 emit_insn (gen_adddi3 (dest_reg, dest_reg,
4233 GEN_INT (move_bytes)));
4234 }
015892ee 4235 }
4c64a852 4236 }
3933e0e1
MM
4237 }
4238
4239 else /* string instructions not available */
4240 {
4241 num_reg = offset = 0;
4242 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
7e69e155 4243 {
3933e0e1
MM
4244 /* Calculate the correct offset for src/dest */
4245 if (offset == 0)
7e69e155 4246 {
3933e0e1
MM
4247 src_addr = src_reg;
4248 dest_addr = dest_reg;
4249 }
4250 else
4251 {
c5c76735
JL
4252 src_addr = plus_constant (src_reg, offset);
4253 dest_addr = plus_constant (dest_reg, offset);
3933e0e1
MM
4254 }
4255
cc0d9ba8
DE
4256 /* Generate the appropriate load and store, saving the stores
4257 for later. */
4258 if (bytes >= 8 && TARGET_POWERPC64
a4f6c312
SS
4259 /* 64-bit loads and stores require word-aligned
4260 displacements. */
cc0d9ba8 4261 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
b6c9286a
MM
4262 {
4263 move_bytes = 8;
4264 tmp_reg = gen_reg_rtx (DImode);
cc0d9ba8
DE
4265 emit_insn (gen_movdi (tmp_reg,
4266 expand_block_move_mem (DImode,
4267 src_addr,
4268 orig_src)));
4269 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
4270 dest_addr,
4271 orig_dest),
4272 tmp_reg);
b6c9286a 4273 }
cc0d9ba8 4274 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
4275 {
4276 move_bytes = 4;
4277 tmp_reg = gen_reg_rtx (SImode);
cc0d9ba8
DE
4278 emit_insn (gen_movsi (tmp_reg,
4279 expand_block_move_mem (SImode,
4280 src_addr,
4281 orig_src)));
4282 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
4283 dest_addr,
4284 orig_dest),
4285 tmp_reg);
3933e0e1 4286 }
cc0d9ba8 4287 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
4288 {
4289 move_bytes = 2;
4290 tmp_reg = gen_reg_rtx (HImode);
c81fc13e 4291 emit_insn (gen_movhi (tmp_reg,
cc0d9ba8
DE
4292 expand_block_move_mem (HImode,
4293 src_addr,
4294 orig_src)));
4295 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
4296 dest_addr,
4297 orig_dest),
4298 tmp_reg);
3933e0e1
MM
4299 }
4300 else
4301 {
4302 move_bytes = 1;
4303 tmp_reg = gen_reg_rtx (QImode);
c81fc13e 4304 emit_insn (gen_movqi (tmp_reg,
cc0d9ba8
DE
4305 expand_block_move_mem (QImode,
4306 src_addr,
4307 orig_src)));
4308 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
4309 dest_addr,
4310 orig_dest),
a4f6c312 4311 tmp_reg);
3933e0e1
MM
4312 }
4313
4314 if (num_reg >= MAX_MOVE_REG)
4315 {
4316 for (i = 0; i < num_reg; i++)
4317 emit_insn (stores[i]);
4318 num_reg = 0;
7e69e155
MM
4319 }
4320 }
3933e0e1 4321
b6c9286a
MM
4322 for (i = 0; i < num_reg; i++)
4323 emit_insn (stores[i]);
7e69e155
MM
4324 }
4325
4326 return 1;
4327}
4328
9878760c
RK
4329\f
4330/* Return 1 if OP is a load multiple operation. It is known to be a
4331 PARALLEL and the first section will be tested. */
4332
4333int
4334load_multiple_operation (op, mode)
4335 rtx op;
296b8152 4336 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
4337{
4338 int count = XVECLEN (op, 0);
e2c953b6 4339 unsigned int dest_regno;
9878760c
RK
4340 rtx src_addr;
4341 int i;
4342
4343 /* Perform a quick check so we don't blow up below. */
4344 if (count <= 1
4345 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4346 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
4347 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
4348 return 0;
4349
4350 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
4351 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
4352
4353 for (i = 1; i < count; i++)
4354 {
4355 rtx elt = XVECEXP (op, 0, i);
4356
4357 if (GET_CODE (elt) != SET
4358 || GET_CODE (SET_DEST (elt)) != REG
4359 || GET_MODE (SET_DEST (elt)) != SImode
4360 || REGNO (SET_DEST (elt)) != dest_regno + i
4361 || GET_CODE (SET_SRC (elt)) != MEM
4362 || GET_MODE (SET_SRC (elt)) != SImode
4363 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
4364 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
4365 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
4366 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
4367 return 0;
4368 }
4369
4370 return 1;
4371}
4372
4373/* Similar, but tests for store multiple. Here, the second vector element
4374 is a CLOBBER. It will be tested later. */
4375
4376int
4377store_multiple_operation (op, mode)
4378 rtx op;
296b8152 4379 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
4380{
4381 int count = XVECLEN (op, 0) - 1;
e2c953b6 4382 unsigned int src_regno;
9878760c
RK
4383 rtx dest_addr;
4384 int i;
4385
4386 /* Perform a quick check so we don't blow up below. */
4387 if (count <= 1
4388 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4389 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
4390 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
4391 return 0;
4392
4393 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
4394 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
4395
4396 for (i = 1; i < count; i++)
4397 {
4398 rtx elt = XVECEXP (op, 0, i + 1);
4399
4400 if (GET_CODE (elt) != SET
4401 || GET_CODE (SET_SRC (elt)) != REG
4402 || GET_MODE (SET_SRC (elt)) != SImode
4403 || REGNO (SET_SRC (elt)) != src_regno + i
4404 || GET_CODE (SET_DEST (elt)) != MEM
4405 || GET_MODE (SET_DEST (elt)) != SImode
4406 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
4407 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
4408 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
4409 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
4410 return 0;
4411 }
4412
4413 return 1;
4414}
9ebbca7d 4415
00b960c7
AH
4416/* Return 1 for a parallel vrsave operation. */
4417
4418int
4419vrsave_operation (op, mode)
4420 rtx op;
4421 enum machine_mode mode ATTRIBUTE_UNUSED;
4422{
4423 int count = XVECLEN (op, 0);
4424 unsigned int dest_regno, src_regno;
4425 int i;
4426
4427 if (count <= 1
4428 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4429 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
4430 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
4431 return 0;
4432
4433 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
4434 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
4435
4436 if (dest_regno != VRSAVE_REGNO
4437 && src_regno != VRSAVE_REGNO)
4438 return 0;
4439
4440 for (i = 1; i < count; i++)
4441 {
4442 rtx elt = XVECEXP (op, 0, i);
4443
9aa86737
AH
4444 if (GET_CODE (elt) != CLOBBER
4445 && GET_CODE (elt) != SET)
00b960c7
AH
4446 return 0;
4447 }
4448
4449 return 1;
4450}
4451
a4f6c312 4452/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
4453
4454int
4455mtcrf_operation (op, mode)
4456 rtx op;
4457 enum machine_mode mode ATTRIBUTE_UNUSED;
4458{
4459 int count = XVECLEN (op, 0);
4460 int i;
9ebbca7d
GK
4461 rtx src_reg;
4462
4463 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
4464 if (count < 1
4465 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4466 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
4467 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 4468 return 0;
e35b9579 4469 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
4470
4471 if (GET_CODE (src_reg) != REG
4472 || GET_MODE (src_reg) != SImode
4473 || ! INT_REGNO_P (REGNO (src_reg)))
4474 return 0;
4475
e35b9579 4476 for (i = 0; i < count; i++)
9ebbca7d
GK
4477 {
4478 rtx exp = XVECEXP (op, 0, i);
4479 rtx unspec;
4480 int maskval;
4481
4482 if (GET_CODE (exp) != SET
4483 || GET_CODE (SET_DEST (exp)) != REG
4484 || GET_MODE (SET_DEST (exp)) != CCmode
4485 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
4486 return 0;
4487 unspec = SET_SRC (exp);
4488 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
4489
4490 if (GET_CODE (unspec) != UNSPEC
4491 || XINT (unspec, 1) != 20
4492 || XVECLEN (unspec, 0) != 2
4493 || XVECEXP (unspec, 0, 0) != src_reg
4494 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
4495 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
4496 return 0;
4497 }
e35b9579 4498 return 1;
9ebbca7d
GK
4499}
4500
a4f6c312 4501/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
4502
4503int
4504lmw_operation (op, mode)
4505 rtx op;
4506 enum machine_mode mode ATTRIBUTE_UNUSED;
4507{
4508 int count = XVECLEN (op, 0);
e2c953b6 4509 unsigned int dest_regno;
9ebbca7d 4510 rtx src_addr;
e2c953b6 4511 unsigned int base_regno;
9ebbca7d
GK
4512 HOST_WIDE_INT offset;
4513 int i;
4514
4515 /* Perform a quick check so we don't blow up below. */
4516 if (count <= 1
4517 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4518 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
4519 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
4520 return 0;
4521
4522 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
4523 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
4524
4525 if (dest_regno > 31
e2c953b6 4526 || count != 32 - (int) dest_regno)
9ebbca7d
GK
4527 return 0;
4528
258bfae2 4529 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0))
9ebbca7d
GK
4530 {
4531 offset = 0;
4532 base_regno = REGNO (src_addr);
4533 if (base_regno == 0)
4534 return 0;
4535 }
258bfae2 4536 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0))
9ebbca7d
GK
4537 {
4538 offset = INTVAL (XEXP (src_addr, 1));
4539 base_regno = REGNO (XEXP (src_addr, 0));
4540 }
4541 else
4542 return 0;
4543
4544 for (i = 0; i < count; i++)
4545 {
4546 rtx elt = XVECEXP (op, 0, i);
4547 rtx newaddr;
4548 rtx addr_reg;
4549 HOST_WIDE_INT newoffset;
4550
4551 if (GET_CODE (elt) != SET
4552 || GET_CODE (SET_DEST (elt)) != REG
4553 || GET_MODE (SET_DEST (elt)) != SImode
4554 || REGNO (SET_DEST (elt)) != dest_regno + i
4555 || GET_CODE (SET_SRC (elt)) != MEM
4556 || GET_MODE (SET_SRC (elt)) != SImode)
4557 return 0;
4558 newaddr = XEXP (SET_SRC (elt), 0);
258bfae2 4559 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
4560 {
4561 newoffset = 0;
4562 addr_reg = newaddr;
4563 }
258bfae2 4564 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
4565 {
4566 addr_reg = XEXP (newaddr, 0);
4567 newoffset = INTVAL (XEXP (newaddr, 1));
4568 }
4569 else
4570 return 0;
4571 if (REGNO (addr_reg) != base_regno
4572 || newoffset != offset + 4 * i)
4573 return 0;
4574 }
4575
4576 return 1;
4577}
4578
a4f6c312 4579/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
4580
4581int
4582stmw_operation (op, mode)
4583 rtx op;
4584 enum machine_mode mode ATTRIBUTE_UNUSED;
4585{
4586 int count = XVECLEN (op, 0);
e2c953b6 4587 unsigned int src_regno;
9ebbca7d 4588 rtx dest_addr;
e2c953b6 4589 unsigned int base_regno;
9ebbca7d
GK
4590 HOST_WIDE_INT offset;
4591 int i;
4592
4593 /* Perform a quick check so we don't blow up below. */
4594 if (count <= 1
4595 || GET_CODE (XVECEXP (op, 0, 0)) != SET
4596 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
4597 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
4598 return 0;
4599
4600 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
4601 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
4602
4603 if (src_regno > 31
e2c953b6 4604 || count != 32 - (int) src_regno)
9ebbca7d
GK
4605 return 0;
4606
258bfae2 4607 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0))
9ebbca7d
GK
4608 {
4609 offset = 0;
4610 base_regno = REGNO (dest_addr);
4611 if (base_regno == 0)
4612 return 0;
4613 }
258bfae2 4614 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0))
9ebbca7d
GK
4615 {
4616 offset = INTVAL (XEXP (dest_addr, 1));
4617 base_regno = REGNO (XEXP (dest_addr, 0));
4618 }
4619 else
4620 return 0;
4621
4622 for (i = 0; i < count; i++)
4623 {
4624 rtx elt = XVECEXP (op, 0, i);
4625 rtx newaddr;
4626 rtx addr_reg;
4627 HOST_WIDE_INT newoffset;
4628
4629 if (GET_CODE (elt) != SET
4630 || GET_CODE (SET_SRC (elt)) != REG
4631 || GET_MODE (SET_SRC (elt)) != SImode
4632 || REGNO (SET_SRC (elt)) != src_regno + i
4633 || GET_CODE (SET_DEST (elt)) != MEM
4634 || GET_MODE (SET_DEST (elt)) != SImode)
4635 return 0;
4636 newaddr = XEXP (SET_DEST (elt), 0);
258bfae2 4637 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
4638 {
4639 newoffset = 0;
4640 addr_reg = newaddr;
4641 }
258bfae2 4642 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
4643 {
4644 addr_reg = XEXP (newaddr, 0);
4645 newoffset = INTVAL (XEXP (newaddr, 1));
4646 }
4647 else
4648 return 0;
4649 if (REGNO (addr_reg) != base_regno
4650 || newoffset != offset + 4 * i)
4651 return 0;
4652 }
4653
4654 return 1;
4655}
9878760c 4656\f
a4f6c312
SS
4657/* A validation routine: say whether CODE, a condition code, and MODE
4658 match. The other alternatives either don't make sense or should
4659 never be generated. */
39a10a29 4660
39a10a29
GK
4661static void
4662validate_condition_mode (code, mode)
4663 enum rtx_code code;
4664 enum machine_mode mode;
4665{
4666 if (GET_RTX_CLASS (code) != '<'
4667 || GET_MODE_CLASS (mode) != MODE_CC)
4668 abort ();
4669
4670 /* These don't make sense. */
4671 if ((code == GT || code == LT || code == GE || code == LE)
4672 && mode == CCUNSmode)
4673 abort ();
4674
4675 if ((code == GTU || code == LTU || code == GEU || code == LEU)
4676 && mode != CCUNSmode)
4677 abort ();
4678
4679 if (mode != CCFPmode
4680 && (code == ORDERED || code == UNORDERED
4681 || code == UNEQ || code == LTGT
4682 || code == UNGT || code == UNLT
4683 || code == UNGE || code == UNLE))
a4f6c312 4684 abort ();
39a10a29 4685
de6c5979
BL
4686 /* These should never be generated except for
4687 flag_unsafe_math_optimizations. */
39a10a29 4688 if (mode == CCFPmode
de6c5979 4689 && ! flag_unsafe_math_optimizations
39a10a29
GK
4690 && (code == LE || code == GE
4691 || code == UNEQ || code == LTGT
4692 || code == UNGT || code == UNLT))
4693 abort ();
4694
4695 /* These are invalid; the information is not there. */
4696 if (mode == CCEQmode
4697 && code != EQ && code != NE)
4698 abort ();
4699}
4700
9878760c
RK
4701/* Return 1 if OP is a comparison operation that is valid for a branch insn.
4702 We only check the opcode against the mode of the CC value here. */
4703
4704int
4705branch_comparison_operator (op, mode)
592696dd 4706 rtx op;
296b8152 4707 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
4708{
4709 enum rtx_code code = GET_CODE (op);
4710 enum machine_mode cc_mode;
4711
4712 if (GET_RTX_CLASS (code) != '<')
4713 return 0;
4714
4715 cc_mode = GET_MODE (XEXP (op, 0));
4716 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
4717 return 0;
4718
39a10a29 4719 validate_condition_mode (code, cc_mode);
9878760c 4720
39a10a29
GK
4721 return 1;
4722}
4723
4724/* Return 1 if OP is a comparison operation that is valid for a branch
4725 insn and which is true if the corresponding bit in the CC register
4726 is set. */
4727
4728int
4729branch_positive_comparison_operator (op, mode)
592696dd 4730 rtx op;
39a10a29
GK
4731 enum machine_mode mode;
4732{
4733 enum rtx_code code;
4734
4735 if (! branch_comparison_operator (op, mode))
9878760c
RK
4736 return 0;
4737
39a10a29
GK
4738 code = GET_CODE (op);
4739 return (code == EQ || code == LT || code == GT
4740 || code == LTU || code == GTU
4741 || code == UNORDERED);
9878760c
RK
4742}
4743
4744/* Return 1 if OP is a comparison operation that is valid for an scc insn.
4745 We check the opcode against the mode of the CC value and disallow EQ or
4746 NE comparisons for integers. */
4747
4748int
4749scc_comparison_operator (op, mode)
592696dd 4750 rtx op;
9878760c
RK
4751 enum machine_mode mode;
4752{
4753 enum rtx_code code = GET_CODE (op);
4754 enum machine_mode cc_mode;
4755
4756 if (GET_MODE (op) != mode && mode != VOIDmode)
4757 return 0;
4758
4759 if (GET_RTX_CLASS (code) != '<')
4760 return 0;
4761
4762 cc_mode = GET_MODE (XEXP (op, 0));
4763 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
4764 return 0;
4765
39a10a29 4766 validate_condition_mode (code, cc_mode);
9878760c 4767
39a10a29 4768 if (code == NE && cc_mode != CCFPmode)
c5defebb
RK
4769 return 0;
4770
9878760c
RK
4771 return 1;
4772}
e0cd0770
JC
4773
4774int
4775trap_comparison_operator (op, mode)
4776 rtx op;
4777 enum machine_mode mode;
4778{
4779 if (mode != VOIDmode && mode != GET_MODE (op))
4780 return 0;
39a10a29 4781 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 4782}
dfbdccdb
GK
4783
4784int
4785boolean_operator (op, mode)
4786 rtx op;
4787 enum machine_mode mode ATTRIBUTE_UNUSED;
4788{
4789 enum rtx_code code = GET_CODE (op);
4790 return (code == AND || code == IOR || code == XOR);
4791}
1d328b19
GK
4792
4793int
4794boolean_or_operator (op, mode)
4795 rtx op;
4796 enum machine_mode mode ATTRIBUTE_UNUSED;
4797{
4798 enum rtx_code code = GET_CODE (op);
4799 return (code == IOR || code == XOR);
4800}
50a0b056
GK
4801
4802int
4803min_max_operator (op, mode)
4804 rtx op;
4805 enum machine_mode mode ATTRIBUTE_UNUSED;
4806{
4807 enum rtx_code code = GET_CODE (op);
4808 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
4809}
9878760c
RK
4810\f
4811/* Return 1 if ANDOP is a mask that has no bits on that are not in the
4812 mask required to convert the result of a rotate insn into a shift
4813 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
4814
4815int
4816includes_lshift_p (shiftop, andop)
592696dd
SS
4817 rtx shiftop;
4818 rtx andop;
9878760c 4819{
e2c953b6
DE
4820 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
4821
4822 shift_mask <<= INTVAL (shiftop);
9878760c
RK
4823
4824 return (INTVAL (andop) & ~shift_mask) == 0;
4825}
4826
4827/* Similar, but for right shift. */
4828
4829int
4830includes_rshift_p (shiftop, andop)
592696dd
SS
4831 rtx shiftop;
4832 rtx andop;
9878760c 4833{
a7653a2c 4834 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
4835
4836 shift_mask >>= INTVAL (shiftop);
4837
e2c953b6
DE
4838 return (INTVAL (andop) & ~shift_mask) == 0;
4839}
4840
c5059423
AM
4841/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
4842 to perform a left shift. It must have exactly SHIFTOP least
4843 signifigant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
4844
4845int
c5059423 4846includes_rldic_lshift_p (shiftop, andop)
592696dd
SS
4847 rtx shiftop;
4848 rtx andop;
e2c953b6 4849{
c5059423
AM
4850 if (GET_CODE (andop) == CONST_INT)
4851 {
02071907 4852 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 4853
c5059423 4854 c = INTVAL (andop);
02071907 4855 if (c == 0 || c == ~0)
c5059423 4856 return 0;
e2c953b6 4857
02071907 4858 shift_mask = ~0;
c5059423
AM
4859 shift_mask <<= INTVAL (shiftop);
4860
4861 /* Find the least signifigant one bit. */
4862 lsb = c & -c;
4863
4864 /* It must coincide with the LSB of the shift mask. */
4865 if (-lsb != shift_mask)
4866 return 0;
e2c953b6 4867
c5059423
AM
4868 /* Invert to look for the next transition (if any). */
4869 c = ~c;
4870
4871 /* Remove the low group of ones (originally low group of zeros). */
4872 c &= -lsb;
4873
4874 /* Again find the lsb, and check we have all 1's above. */
4875 lsb = c & -c;
4876 return c == -lsb;
4877 }
4878 else if (GET_CODE (andop) == CONST_DOUBLE
4879 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
4880 {
02071907
AM
4881 HOST_WIDE_INT low, high, lsb;
4882 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
4883
4884 low = CONST_DOUBLE_LOW (andop);
4885 if (HOST_BITS_PER_WIDE_INT < 64)
4886 high = CONST_DOUBLE_HIGH (andop);
4887
4888 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 4889 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
4890 return 0;
4891
4892 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
4893 {
02071907 4894 shift_mask_high = ~0;
c5059423
AM
4895 if (INTVAL (shiftop) > 32)
4896 shift_mask_high <<= INTVAL (shiftop) - 32;
4897
4898 lsb = high & -high;
4899
4900 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
4901 return 0;
4902
4903 high = ~high;
4904 high &= -lsb;
4905
4906 lsb = high & -high;
4907 return high == -lsb;
4908 }
4909
02071907 4910 shift_mask_low = ~0;
c5059423
AM
4911 shift_mask_low <<= INTVAL (shiftop);
4912
4913 lsb = low & -low;
4914
4915 if (-lsb != shift_mask_low)
4916 return 0;
4917
4918 if (HOST_BITS_PER_WIDE_INT < 64)
4919 high = ~high;
4920 low = ~low;
4921 low &= -lsb;
4922
4923 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
4924 {
4925 lsb = high & -high;
4926 return high == -lsb;
4927 }
4928
4929 lsb = low & -low;
4930 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
4931 }
4932 else
4933 return 0;
4934}
e2c953b6 4935
c5059423
AM
4936/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
4937 to perform a left shift. It must have SHIFTOP or more least
4938 signifigant 0's, with the remainder of the word 1's. */
e2c953b6 4939
c5059423
AM
4940int
4941includes_rldicr_lshift_p (shiftop, andop)
592696dd
SS
4942 rtx shiftop;
4943 rtx andop;
c5059423 4944{
e2c953b6 4945 if (GET_CODE (andop) == CONST_INT)
c5059423 4946 {
02071907 4947 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 4948
02071907 4949 shift_mask = ~0;
c5059423
AM
4950 shift_mask <<= INTVAL (shiftop);
4951 c = INTVAL (andop);
4952
4953 /* Find the least signifigant one bit. */
4954 lsb = c & -c;
4955
4956 /* It must be covered by the shift mask.
a4f6c312 4957 This test also rejects c == 0. */
c5059423
AM
4958 if ((lsb & shift_mask) == 0)
4959 return 0;
4960
4961 /* Check we have all 1's above the transition, and reject all 1's. */
4962 return c == -lsb && lsb != 1;
4963 }
4964 else if (GET_CODE (andop) == CONST_DOUBLE
4965 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
4966 {
02071907 4967 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
4968
4969 low = CONST_DOUBLE_LOW (andop);
4970
4971 if (HOST_BITS_PER_WIDE_INT < 64)
4972 {
02071907 4973 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
4974
4975 high = CONST_DOUBLE_HIGH (andop);
4976
4977 if (low == 0)
4978 {
02071907 4979 shift_mask_high = ~0;
c5059423
AM
4980 if (INTVAL (shiftop) > 32)
4981 shift_mask_high <<= INTVAL (shiftop) - 32;
4982
4983 lsb = high & -high;
4984
4985 if ((lsb & shift_mask_high) == 0)
4986 return 0;
4987
4988 return high == -lsb;
4989 }
4990 if (high != ~0)
4991 return 0;
4992 }
4993
02071907 4994 shift_mask_low = ~0;
c5059423
AM
4995 shift_mask_low <<= INTVAL (shiftop);
4996
4997 lsb = low & -low;
4998
4999 if ((lsb & shift_mask_low) == 0)
5000 return 0;
5001
5002 return low == -lsb && lsb != 1;
5003 }
e2c953b6 5004 else
c5059423 5005 return 0;
9878760c 5006}
35068b43
RK
5007
5008/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
5009 for lfq and stfq insns.
5010
5011 Note reg1 and reg2 *must* be hard registers. To be sure we will
5012 abort if we are passed pseudo registers. */
5013
5014int
5015registers_ok_for_quad_peep (reg1, reg2)
5016 rtx reg1, reg2;
5017{
5018 /* We might have been passed a SUBREG. */
5019 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
5020 return 0;
5021
5022 return (REGNO (reg1) == REGNO (reg2) - 1);
5023}
5024
a4f6c312
SS
5025/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
5026 addr1 and addr2 must be in consecutive memory locations
5027 (addr2 == addr1 + 8). */
35068b43
RK
5028
5029int
5030addrs_ok_for_quad_peep (addr1, addr2)
592696dd
SS
5031 rtx addr1;
5032 rtx addr2;
35068b43 5033{
e2c953b6 5034 unsigned int reg1;
35068b43
RK
5035 int offset1;
5036
5037 /* Extract an offset (if used) from the first addr. */
5038 if (GET_CODE (addr1) == PLUS)
5039 {
5040 /* If not a REG, return zero. */
5041 if (GET_CODE (XEXP (addr1, 0)) != REG)
5042 return 0;
5043 else
5044 {
5045 reg1 = REGNO (XEXP (addr1, 0));
5046 /* The offset must be constant! */
5047 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
5048 return 0;
5049 offset1 = INTVAL (XEXP (addr1, 1));
5050 }
5051 }
5052 else if (GET_CODE (addr1) != REG)
5053 return 0;
5054 else
5055 {
5056 reg1 = REGNO (addr1);
5057 /* This was a simple (mem (reg)) expression. Offset is 0. */
5058 offset1 = 0;
5059 }
5060
acad7ed3 5061 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
35068b43
RK
5062 if (GET_CODE (addr2) != PLUS)
5063 return 0;
5064
5065 if (GET_CODE (XEXP (addr2, 0)) != REG
5066 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
5067 return 0;
5068
5069 if (reg1 != REGNO (XEXP (addr2, 0)))
5070 return 0;
5071
5072 /* The offset for the second addr must be 8 more than the first addr. */
5073 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
5074 return 0;
5075
5076 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
5077 instructions. */
5078 return 1;
5079}
9878760c
RK
5080\f
5081/* Return the register class of a scratch register needed to copy IN into
5082 or out of a register in CLASS in MODE. If it can be done directly,
5083 NO_REGS is returned. */
5084
5085enum reg_class
5086secondary_reload_class (class, mode, in)
5087 enum reg_class class;
296b8152 5088 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
5089 rtx in;
5090{
5accd822 5091 int regno;
9878760c 5092
46fad5b7
DJ
5093 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN && flag_pic))
5094 {
5095 /* We cannot copy a symbolic operand directly into anything
5096 other than BASE_REGS for TARGET_ELF. So indicate that a
5097 register from BASE_REGS is needed as an intermediate
5098 register.
5099
5100 On Darwin, pic addresses require a load from memory, which
5101 needs a base register. */
5102 if (class != BASE_REGS
5103 && (GET_CODE (in) == SYMBOL_REF
5104 || GET_CODE (in) == HIGH
5105 || GET_CODE (in) == LABEL_REF
5106 || GET_CODE (in) == CONST))
5107 return BASE_REGS;
5108 }
e7b7998a 5109
5accd822
DE
5110 if (GET_CODE (in) == REG)
5111 {
5112 regno = REGNO (in);
5113 if (regno >= FIRST_PSEUDO_REGISTER)
5114 {
5115 regno = true_regnum (in);
5116 if (regno >= FIRST_PSEUDO_REGISTER)
5117 regno = -1;
5118 }
5119 }
5120 else if (GET_CODE (in) == SUBREG)
5121 {
5122 regno = true_regnum (in);
5123 if (regno >= FIRST_PSEUDO_REGISTER)
5124 regno = -1;
5125 }
5126 else
5127 regno = -1;
5128
9878760c
RK
5129 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
5130 into anything. */
5131 if (class == GENERAL_REGS || class == BASE_REGS
5132 || (regno >= 0 && INT_REGNO_P (regno)))
5133 return NO_REGS;
5134
5135 /* Constants, memory, and FP registers can go into FP registers. */
5136 if ((regno == -1 || FP_REGNO_P (regno))
5137 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
5138 return NO_REGS;
5139
0ac081f6
AH
5140 /* Memory, and AltiVec registers can go into AltiVec registers. */
5141 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
5142 && class == ALTIVEC_REGS)
5143 return NO_REGS;
5144
9878760c
RK
5145 /* We can copy among the CR registers. */
5146 if ((class == CR_REGS || class == CR0_REGS)
5147 && regno >= 0 && CR_REGNO_P (regno))
5148 return NO_REGS;
5149
5150 /* Otherwise, we need GENERAL_REGS. */
5151 return GENERAL_REGS;
5152}
5153\f
5154/* Given a comparison operation, return the bit number in CCR to test. We
5155 know this is a valid comparison.
5156
5157 SCC_P is 1 if this is for an scc. That means that %D will have been
5158 used instead of %C, so the bits will be in different places.
5159
b4ac57ab 5160 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
5161
5162int
5163ccr_bit (op, scc_p)
592696dd 5164 rtx op;
9878760c
RK
5165 int scc_p;
5166{
5167 enum rtx_code code = GET_CODE (op);
5168 enum machine_mode cc_mode;
5169 int cc_regnum;
5170 int base_bit;
9ebbca7d 5171 rtx reg;
9878760c
RK
5172
5173 if (GET_RTX_CLASS (code) != '<')
5174 return -1;
5175
9ebbca7d
GK
5176 reg = XEXP (op, 0);
5177
5178 if (GET_CODE (reg) != REG
5179 || ! CR_REGNO_P (REGNO (reg)))
5180 abort ();
5181
5182 cc_mode = GET_MODE (reg);
5183 cc_regnum = REGNO (reg);
5184 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 5185
39a10a29 5186 validate_condition_mode (code, cc_mode);
c5defebb 5187
9878760c
RK
5188 switch (code)
5189 {
5190 case NE:
5191 return scc_p ? base_bit + 3 : base_bit + 2;
5192 case EQ:
5193 return base_bit + 2;
1c882ea4 5194 case GT: case GTU: case UNLE:
9878760c 5195 return base_bit + 1;
1c882ea4 5196 case LT: case LTU: case UNGE:
9878760c 5197 return base_bit;
1c882ea4
GK
5198 case ORDERED: case UNORDERED:
5199 return base_bit + 3;
9878760c
RK
5200
5201 case GE: case GEU:
39a10a29 5202 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
5203 unordered position. So test that bit. For integer, this is ! LT
5204 unless this is an scc insn. */
39a10a29 5205 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
5206
5207 case LE: case LEU:
39a10a29 5208 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 5209
9878760c
RK
5210 default:
5211 abort ();
5212 }
5213}
1ff7789b 5214\f
8d30c4ee 5215/* Return the GOT register. */
1ff7789b
MM
5216
5217struct rtx_def *
5218rs6000_got_register (value)
5f59ecb7 5219 rtx value ATTRIBUTE_UNUSED;
1ff7789b 5220{
a4f6c312
SS
5221 /* The second flow pass currently (June 1999) can't update
5222 regs_ever_live without disturbing other parts of the compiler, so
5223 update it here to make the prolog/epilogue code happy. */
3cb999d8 5224 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
8d30c4ee 5225 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 5226
8d30c4ee 5227 current_function_uses_pic_offset_table = 1;
3cb999d8 5228
1ff7789b
MM
5229 return pic_offset_table_rtx;
5230}
a7df97e6 5231\f
71f123ca 5232/* Functions to init, mark and free struct machine_function.
a7df97e6
MM
5233 These will be called, via pointer variables,
5234 from push_function_context and pop_function_context. */
5235
00dba523
NC
5236static void
5237rs6000_init_machine_status (p)
a7df97e6
MM
5238 struct function *p;
5239{
71f123ca
FS
5240 p->machine = (machine_function *) xcalloc (1, sizeof (machine_function));
5241}
a7df97e6 5242
00dba523
NC
5243static void
5244rs6000_free_machine_status (p)
a7df97e6
MM
5245 struct function *p;
5246{
00dba523
NC
5247 if (p->machine == NULL)
5248 return;
a7df97e6 5249
00dba523
NC
5250 free (p->machine);
5251 p->machine = NULL;
a7df97e6
MM
5252}
5253
9878760c
RK
5254\f
5255/* Print an operand. Recognize special options, documented below. */
5256
38c1f2d7 5257#if TARGET_ELF
d9407988 5258#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 5259#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
5260#else
5261#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 5262#define SMALL_DATA_REG 0
ba5e43aa
MM
5263#endif
5264
9878760c
RK
5265void
5266print_operand (file, x, code)
5267 FILE *file;
5268 rtx x;
9ebbca7d 5269 int code;
9878760c
RK
5270{
5271 int i;
a260abc9 5272 HOST_WIDE_INT val;
9878760c
RK
5273
5274 /* These macros test for integers and extract the low-order bits. */
5275#define INT_P(X) \
5276((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
5277 && GET_MODE (X) == VOIDmode)
5278
5279#define INT_LOWPART(X) \
5280 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
5281
5282 switch (code)
5283 {
a8b3aeda 5284 case '.':
a85d226b
RK
5285 /* Write out an instruction after the call which may be replaced
5286 with glue code by the loader. This depends on the AIX version. */
5287 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
5288 return;
5289
81eace42
GK
5290 /* %a is output_address. */
5291
9854d9ed
RK
5292 case 'A':
5293 /* If X is a constant integer whose low-order 5 bits are zero,
5294 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 5295 in the AIX assembler where "sri" with a zero shift count
9854d9ed
RK
5296 write a trash instruction. */
5297 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 5298 putc ('l', file);
9854d9ed 5299 else
76229ac8 5300 putc ('r', file);
9854d9ed
RK
5301 return;
5302
5303 case 'b':
e2c953b6
DE
5304 /* If constant, low-order 16 bits of constant, unsigned.
5305 Otherwise, write normally. */
5306 if (INT_P (x))
5307 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
5308 else
5309 print_operand (file, x, 0);
cad12a8d
RK
5310 return;
5311
a260abc9
DE
5312 case 'B':
5313 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
5314 for 64-bit mask direction. */
296b8152 5315 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 5316 return;
a260abc9 5317
81eace42
GK
5318 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
5319 output_operand. */
5320
9854d9ed 5321 case 'D':
39a10a29
GK
5322 /* There used to be a comment for 'C' reading "This is an
5323 optional cror needed for certain floating-point
5324 comparisons. Otherwise write nothing." */
5325
9854d9ed
RK
5326 /* Similar, except that this is for an scc, so we must be able to
5327 encode the test in a single bit that is one. We do the above
5328 for any LE, GE, GEU, or LEU and invert the bit for NE. */
5329 if (GET_CODE (x) == LE || GET_CODE (x) == GE
5330 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
5331 {
9ebbca7d 5332 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
5333
5334 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
5335 base_bit + 2,
5336 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
5337 }
5338
5339 else if (GET_CODE (x) == NE)
5340 {
9ebbca7d 5341 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
5342
5343 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
5344 base_bit + 2, base_bit + 2);
5345 }
5346 return;
5347
5348 case 'E':
39a10a29 5349 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
5350 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
5351 output_operand_lossage ("invalid %%E value");
78fbdbf7 5352 else
39a10a29 5353 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 5354 return;
9854d9ed
RK
5355
5356 case 'f':
5357 /* X is a CR register. Print the shift count needed to move it
5358 to the high-order four bits. */
5359 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
5360 output_operand_lossage ("invalid %%f value");
5361 else
9ebbca7d 5362 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
5363 return;
5364
5365 case 'F':
5366 /* Similar, but print the count for the rotate in the opposite
5367 direction. */
5368 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
5369 output_operand_lossage ("invalid %%F value");
5370 else
9ebbca7d 5371 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
5372 return;
5373
5374 case 'G':
5375 /* X is a constant integer. If it is negative, print "m",
5376 otherwise print "z". This is to make a aze or ame insn. */
5377 if (GET_CODE (x) != CONST_INT)
5378 output_operand_lossage ("invalid %%G value");
5379 else if (INTVAL (x) >= 0)
76229ac8 5380 putc ('z', file);
9854d9ed 5381 else
76229ac8 5382 putc ('m', file);
9854d9ed 5383 return;
e2c953b6 5384
9878760c 5385 case 'h':
a4f6c312
SS
5386 /* If constant, output low-order five bits. Otherwise, write
5387 normally. */
9878760c 5388 if (INT_P (x))
5f59ecb7 5389 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
5390 else
5391 print_operand (file, x, 0);
5392 return;
5393
64305719 5394 case 'H':
a4f6c312
SS
5395 /* If constant, output low-order six bits. Otherwise, write
5396 normally. */
64305719 5397 if (INT_P (x))
5f59ecb7 5398 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
5399 else
5400 print_operand (file, x, 0);
5401 return;
5402
9854d9ed
RK
5403 case 'I':
5404 /* Print `i' if this is a constant, else nothing. */
9878760c 5405 if (INT_P (x))
76229ac8 5406 putc ('i', file);
9878760c
RK
5407 return;
5408
9854d9ed
RK
5409 case 'j':
5410 /* Write the bit number in CCR for jump. */
5411 i = ccr_bit (x, 0);
5412 if (i == -1)
5413 output_operand_lossage ("invalid %%j code");
9878760c 5414 else
9854d9ed 5415 fprintf (file, "%d", i);
9878760c
RK
5416 return;
5417
9854d9ed
RK
5418 case 'J':
5419 /* Similar, but add one for shift count in rlinm for scc and pass
5420 scc flag to `ccr_bit'. */
5421 i = ccr_bit (x, 1);
5422 if (i == -1)
5423 output_operand_lossage ("invalid %%J code");
5424 else
a0466a68
RK
5425 /* If we want bit 31, write a shift count of zero, not 32. */
5426 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
5427 return;
5428
9854d9ed
RK
5429 case 'k':
5430 /* X must be a constant. Write the 1's complement of the
5431 constant. */
9878760c 5432 if (! INT_P (x))
9854d9ed 5433 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
5434 else
5435 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
5436 return;
5437
81eace42 5438 case 'K':
9ebbca7d
GK
5439 /* X must be a symbolic constant on ELF. Write an
5440 expression suitable for an 'addi' that adds in the low 16
5441 bits of the MEM. */
5442 if (GET_CODE (x) != CONST)
5443 {
5444 print_operand_address (file, x);
5445 fputs ("@l", file);
5446 }
5447 else
5448 {
5449 if (GET_CODE (XEXP (x, 0)) != PLUS
5450 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
5451 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
5452 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 5453 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
5454 print_operand_address (file, XEXP (XEXP (x, 0), 0));
5455 fputs ("@l", file);
5456 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
5457 }
81eace42
GK
5458 return;
5459
5460 /* %l is output_asm_label. */
9ebbca7d 5461
9854d9ed
RK
5462 case 'L':
5463 /* Write second word of DImode or DFmode reference. Works on register
5464 or non-indexed memory only. */
5465 if (GET_CODE (x) == REG)
5ebfb2ba 5466 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
5467 else if (GET_CODE (x) == MEM)
5468 {
5469 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 5470 we have already done it, we can just use an offset of word. */
9854d9ed
RK
5471 if (GET_CODE (XEXP (x, 0)) == PRE_INC
5472 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
5473 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
5474 UNITS_PER_WORD));
9854d9ed 5475 else
d7624dc0
RK
5476 output_address (XEXP (adjust_address_nv (x, SImode,
5477 UNITS_PER_WORD),
5478 0));
ed8908e7 5479
ba5e43aa 5480 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
5481 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
5482 reg_names[SMALL_DATA_REG]);
9854d9ed 5483 }
9878760c 5484 return;
9854d9ed 5485
9878760c
RK
5486 case 'm':
5487 /* MB value for a mask operand. */
5488 if (! mask_operand (x, VOIDmode))
5489 output_operand_lossage ("invalid %%m value");
5490
5491 val = INT_LOWPART (x);
5492
5493 /* If the high bit is set and the low bit is not, the value is zero.
5494 If the high bit is zero, the value is the first 1 bit we find from
5495 the left. */
0858c623 5496 if ((val & 0x80000000) && ((val & 1) == 0))
9878760c 5497 {
19d2d16f 5498 putc ('0', file);
9878760c
RK
5499 return;
5500 }
0858c623 5501 else if ((val & 0x80000000) == 0)
9878760c
RK
5502 {
5503 for (i = 1; i < 32; i++)
0858c623 5504 if ((val <<= 1) & 0x80000000)
9878760c
RK
5505 break;
5506 fprintf (file, "%d", i);
5507 return;
5508 }
5509
5510 /* Otherwise, look for the first 0 bit from the right. The result is its
5511 number plus 1. We know the low-order bit is one. */
5512 for (i = 0; i < 32; i++)
5513 if (((val >>= 1) & 1) == 0)
5514 break;
5515
a260abc9 5516 /* If we ended in ...01, i would be 0. The correct value is 31, so
9878760c
RK
5517 we want 31 - i. */
5518 fprintf (file, "%d", 31 - i);
5519 return;
5520
5521 case 'M':
5522 /* ME value for a mask operand. */
5523 if (! mask_operand (x, VOIDmode))
a260abc9 5524 output_operand_lossage ("invalid %%M value");
9878760c
RK
5525
5526 val = INT_LOWPART (x);
5527
5528 /* If the low bit is set and the high bit is not, the value is 31.
5529 If the low bit is zero, the value is the first 1 bit we find from
5530 the right. */
0858c623 5531 if ((val & 1) && ((val & 0x80000000) == 0))
9878760c 5532 {
76229ac8 5533 fputs ("31", file);
9878760c
RK
5534 return;
5535 }
5536 else if ((val & 1) == 0)
5537 {
5538 for (i = 0; i < 32; i++)
5539 if ((val >>= 1) & 1)
5540 break;
5541
a260abc9 5542 /* If we had ....10, i would be 0. The result should be
9878760c
RK
5543 30, so we need 30 - i. */
5544 fprintf (file, "%d", 30 - i);
5545 return;
5546 }
5547
5548 /* Otherwise, look for the first 0 bit from the left. The result is its
5549 number minus 1. We know the high-order bit is one. */
5550 for (i = 0; i < 32; i++)
0858c623 5551 if (((val <<= 1) & 0x80000000) == 0)
9878760c
RK
5552 break;
5553
5554 fprintf (file, "%d", i);
5555 return;
5556
81eace42
GK
5557 /* %n outputs the negative of its operand. */
5558
9878760c
RK
5559 case 'N':
5560 /* Write the number of elements in the vector times 4. */
5561 if (GET_CODE (x) != PARALLEL)
5562 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
5563 else
5564 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
5565 return;
5566
5567 case 'O':
5568 /* Similar, but subtract 1 first. */
5569 if (GET_CODE (x) != PARALLEL)
1427100a 5570 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
5571 else
5572 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
5573 return;
5574
9854d9ed
RK
5575 case 'p':
5576 /* X is a CONST_INT that is a power of two. Output the logarithm. */
5577 if (! INT_P (x)
2bfcf297 5578 || INT_LOWPART (x) < 0
9854d9ed
RK
5579 || (i = exact_log2 (INT_LOWPART (x))) < 0)
5580 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
5581 else
5582 fprintf (file, "%d", i);
9854d9ed
RK
5583 return;
5584
9878760c
RK
5585 case 'P':
5586 /* The operand must be an indirect memory reference. The result
a4f6c312 5587 is the register number. */
9878760c
RK
5588 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
5589 || REGNO (XEXP (x, 0)) >= 32)
5590 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
5591 else
5592 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
5593 return;
5594
dfbdccdb
GK
5595 case 'q':
5596 /* This outputs the logical code corresponding to a boolean
5597 expression. The expression may have one or both operands
39a10a29
GK
5598 negated (if one, only the first one). For condition register
5599 logical operations, it will also treat the negated
5600 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 5601 {
63bc1d05 5602 const char *const *t = 0;
dfbdccdb
GK
5603 const char *s;
5604 enum rtx_code code = GET_CODE (x);
5605 static const char * const tbl[3][3] = {
5606 { "and", "andc", "nor" },
5607 { "or", "orc", "nand" },
5608 { "xor", "eqv", "xor" } };
5609
5610 if (code == AND)
5611 t = tbl[0];
5612 else if (code == IOR)
5613 t = tbl[1];
5614 else if (code == XOR)
5615 t = tbl[2];
5616 else
5617 output_operand_lossage ("invalid %%q value");
5618
5619 if (GET_CODE (XEXP (x, 0)) != NOT)
5620 s = t[0];
5621 else
5622 {
5623 if (GET_CODE (XEXP (x, 1)) == NOT)
5624 s = t[2];
5625 else
5626 s = t[1];
5627 }
5628
5629 fputs (s, file);
5630 }
5631 return;
5632
9854d9ed
RK
5633 case 'R':
5634 /* X is a CR register. Print the mask for `mtcrf'. */
5635 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
5636 output_operand_lossage ("invalid %%R value");
5637 else
9ebbca7d 5638 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 5639 return;
9854d9ed
RK
5640
5641 case 's':
5642 /* Low 5 bits of 32 - value */
5643 if (! INT_P (x))
5644 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
5645 else
5646 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 5647 return;
9854d9ed 5648
a260abc9
DE
5649 case 'S':
5650 /* PowerPC64 mask position. All 0's and all 1's are excluded.
5651 CONST_INT 32-bit mask is considered sign-extended so any
5652 transition must occur within the CONST_INT, not on the boundary. */
5653 if (! mask64_operand (x, VOIDmode))
5654 output_operand_lossage ("invalid %%S value");
5655
5656 val = INT_LOWPART (x);
5657
5658 if (val & 1) /* Clear Left */
5659 {
a238cd8b
DE
5660 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
5661 if (!((val >>= 1) & 1))
5662 break;
a260abc9 5663
a238cd8b
DE
5664#if HOST_BITS_PER_WIDE_INT == 32
5665 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
5666 {
5667 val = CONST_DOUBLE_HIGH (x);
5668
5669 if (val == 0)
5670 --i;
5671 else
5672 for (i = 32; i < 64; i++)
5673 if (!((val >>= 1) & 1))
5674 break;
5675 }
a260abc9 5676#endif
a238cd8b
DE
5677 /* i = index of last set bit from right
5678 mask begins at 63 - i from left */
5679 if (i > 63)
5680 output_operand_lossage ("%%S computed all 1's mask");
cccf3bdc 5681
a260abc9
DE
5682 fprintf (file, "%d", 63 - i);
5683 return;
5684 }
5685 else /* Clear Right */
5686 {
a238cd8b
DE
5687 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
5688 if ((val >>= 1) & 1)
5689 break;
a260abc9 5690
a238cd8b 5691#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
5692 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
5693 {
a238cd8b 5694 val = CONST_DOUBLE_HIGH (x);
a260abc9 5695
a238cd8b 5696 if (val == (HOST_WIDE_INT) -1)
a260abc9 5697 --i;
a260abc9 5698 else
a238cd8b
DE
5699 for (i = 32; i < 64; i++)
5700 if ((val >>= 1) & 1)
a260abc9
DE
5701 break;
5702 }
5703#endif
a238cd8b
DE
5704 /* i = index of last clear bit from right
5705 mask ends at 62 - i from left */
5706 if (i > 62)
5707 output_operand_lossage ("%%S computed all 0's mask");
cccf3bdc 5708
a238cd8b 5709 fprintf (file, "%d", 62 - i);
a260abc9
DE
5710 return;
5711 }
5712
cccf3bdc
DE
5713 case 'T':
5714 /* Print the symbolic name of a branch target register. */
5715 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
5716 && REGNO (x) != COUNT_REGISTER_REGNUM))
5717 output_operand_lossage ("invalid %%T value");
e2c953b6 5718 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
5719 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
5720 else
5721 fputs ("ctr", file);
5722 return;
5723
9854d9ed 5724 case 'u':
802a0058 5725 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
5726 if (! INT_P (x))
5727 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
5728 else
5729 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
5730 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
5731 return;
5732
802a0058
MM
5733 case 'v':
5734 /* High-order 16 bits of constant for use in signed operand. */
5735 if (! INT_P (x))
5736 output_operand_lossage ("invalid %%v value");
e2c953b6 5737 else
134c32f6
DE
5738 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
5739 (INT_LOWPART (x) >> 16) & 0xffff);
5740 return;
802a0058 5741
9854d9ed
RK
5742 case 'U':
5743 /* Print `u' if this has an auto-increment or auto-decrement. */
5744 if (GET_CODE (x) == MEM
5745 && (GET_CODE (XEXP (x, 0)) == PRE_INC
5746 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 5747 putc ('u', file);
9854d9ed 5748 return;
9878760c 5749
e0cd0770
JC
5750 case 'V':
5751 /* Print the trap code for this operand. */
5752 switch (GET_CODE (x))
5753 {
5754 case EQ:
5755 fputs ("eq", file); /* 4 */
5756 break;
5757 case NE:
5758 fputs ("ne", file); /* 24 */
5759 break;
5760 case LT:
5761 fputs ("lt", file); /* 16 */
5762 break;
5763 case LE:
5764 fputs ("le", file); /* 20 */
5765 break;
5766 case GT:
5767 fputs ("gt", file); /* 8 */
5768 break;
5769 case GE:
5770 fputs ("ge", file); /* 12 */
5771 break;
5772 case LTU:
5773 fputs ("llt", file); /* 2 */
5774 break;
5775 case LEU:
5776 fputs ("lle", file); /* 6 */
5777 break;
5778 case GTU:
5779 fputs ("lgt", file); /* 1 */
5780 break;
5781 case GEU:
5782 fputs ("lge", file); /* 5 */
5783 break;
5784 default:
5785 abort ();
5786 }
5787 break;
5788
9854d9ed
RK
5789 case 'w':
5790 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
5791 normally. */
5792 if (INT_P (x))
5f59ecb7
DE
5793 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5794 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
5795 else
5796 print_operand (file, x, 0);
9878760c
RK
5797 return;
5798
9854d9ed 5799 case 'W':
e2c953b6 5800 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
5801 val = (GET_CODE (x) == CONST_INT
5802 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
5803
5804 if (val < 0)
5805 i = -1;
9854d9ed 5806 else
e2c953b6
DE
5807 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
5808 if ((val <<= 1) < 0)
5809 break;
5810
5811#if HOST_BITS_PER_WIDE_INT == 32
5812 if (GET_CODE (x) == CONST_INT && i >= 0)
5813 i += 32; /* zero-extend high-part was all 0's */
5814 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
5815 {
5816 val = CONST_DOUBLE_LOW (x);
5817
5818 if (val == 0)
a4f6c312 5819 abort ();
e2c953b6
DE
5820 else if (val < 0)
5821 --i;
5822 else
5823 for ( ; i < 64; i++)
5824 if ((val <<= 1) < 0)
5825 break;
5826 }
5827#endif
5828
5829 fprintf (file, "%d", i + 1);
9854d9ed 5830 return;
9878760c 5831
9854d9ed
RK
5832 case 'X':
5833 if (GET_CODE (x) == MEM
258bfae2 5834 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0))
76229ac8 5835 putc ('x', file);
9854d9ed 5836 return;
9878760c 5837
9854d9ed
RK
5838 case 'Y':
5839 /* Like 'L', for third word of TImode */
5840 if (GET_CODE (x) == REG)
5ebfb2ba 5841 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 5842 else if (GET_CODE (x) == MEM)
9878760c 5843 {
9854d9ed
RK
5844 if (GET_CODE (XEXP (x, 0)) == PRE_INC
5845 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 5846 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 5847 else
d7624dc0 5848 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 5849 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
5850 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
5851 reg_names[SMALL_DATA_REG]);
9878760c
RK
5852 }
5853 return;
9854d9ed 5854
9878760c 5855 case 'z':
b4ac57ab
RS
5856 /* X is a SYMBOL_REF. Write out the name preceded by a
5857 period and without any trailing data in brackets. Used for function
4d30c363
MM
5858 names. If we are configured for System V (or the embedded ABI) on
5859 the PowerPC, do not emit the period, since those systems do not use
5860 TOCs and the like. */
9878760c
RK
5861 if (GET_CODE (x) != SYMBOL_REF)
5862 abort ();
5863
b6c9286a
MM
5864 if (XSTR (x, 0)[0] != '.')
5865 {
5866 switch (DEFAULT_ABI)
5867 {
5868 default:
5869 abort ();
5870
5871 case ABI_AIX:
5872 putc ('.', file);
5873 break;
5874
5875 case ABI_V4:
5876 case ABI_AIX_NODESC:
ee890fe2 5877 case ABI_DARWIN:
b6c9286a 5878 break;
b6c9286a
MM
5879 }
5880 }
54ee9799
DE
5881#if TARGET_AIX
5882 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
5883#else
9ebbca7d 5884 assemble_name (file, XSTR (x, 0));
54ee9799 5885#endif
9878760c
RK
5886 return;
5887
9854d9ed
RK
5888 case 'Z':
5889 /* Like 'L', for last word of TImode. */
5890 if (GET_CODE (x) == REG)
5ebfb2ba 5891 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
5892 else if (GET_CODE (x) == MEM)
5893 {
5894 if (GET_CODE (XEXP (x, 0)) == PRE_INC
5895 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 5896 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 5897 else
d7624dc0 5898 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 5899 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
5900 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
5901 reg_names[SMALL_DATA_REG]);
9854d9ed 5902 }
5c23c401 5903 return;
0ac081f6
AH
5904
5905 /* Print AltiVec memory operand. */
5906 case 'y':
5907 {
5908 rtx tmp;
5909
5910 if (GET_CODE (x) != MEM)
5911 abort ();
5912
5913 tmp = XEXP (x, 0);
5914
5915 if (GET_CODE (tmp) == REG)
5916 fprintf (file, "0, %s", reg_names[REGNO (tmp)]);
5917 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
5918 {
5919 if (REGNO (XEXP (tmp, 0)) == 0)
5920 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
5921 reg_names[ REGNO (XEXP (tmp, 0)) ]);
5922 else
5923 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
5924 reg_names[ REGNO (XEXP (tmp, 1)) ]);
5925 }
5926 else
5927 abort ();
5928 break;
5929 }
9854d9ed 5930
9878760c
RK
5931 case 0:
5932 if (GET_CODE (x) == REG)
5933 fprintf (file, "%s", reg_names[REGNO (x)]);
5934 else if (GET_CODE (x) == MEM)
5935 {
5936 /* We need to handle PRE_INC and PRE_DEC here, since we need to
5937 know the width from the mode. */
5938 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
5939 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
5940 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 5941 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
5942 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
5943 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 5944 else
a54d04b7 5945 output_address (XEXP (x, 0));
9878760c
RK
5946 }
5947 else
a54d04b7 5948 output_addr_const (file, x);
a85d226b 5949 return;
9878760c
RK
5950
5951 default:
5952 output_operand_lossage ("invalid %%xn code");
5953 }
5954}
5955\f
5956/* Print the address of an operand. */
5957
5958void
5959print_operand_address (file, x)
5960 FILE *file;
592696dd 5961 rtx x;
9878760c
RK
5962{
5963 if (GET_CODE (x) == REG)
4697a36c 5964 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
5965 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
5966 || GET_CODE (x) == LABEL_REF)
9878760c
RK
5967 {
5968 output_addr_const (file, x);
ba5e43aa 5969 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
5970 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
5971 reg_names[SMALL_DATA_REG]);
9ebbca7d 5972 else if (TARGET_TOC)
a4f6c312 5973 abort ();
9878760c
RK
5974 }
5975 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
5976 {
5977 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
5978 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
5979 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 5980 else
4697a36c
MM
5981 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
5982 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
5983 }
5984 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
5f59ecb7
DE
5985 {
5986 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
5987 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
5988 }
3cb999d8
DE
5989#if TARGET_ELF
5990 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
5991 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
5992 {
5993 output_addr_const (file, XEXP (x, 1));
5994 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
5995 }
c859cda6
DJ
5996#endif
5997#if TARGET_MACHO
5998 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
5999 && CONSTANT_P (XEXP (x, 1)))
6000 {
6001 fprintf (file, "lo16(");
6002 output_addr_const (file, XEXP (x, 1));
6003 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
6004 }
3cb999d8 6005#endif
9ebbca7d
GK
6006 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
6007 {
2bfcf297 6008 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 6009 {
2bfcf297
DB
6010 rtx contains_minus = XEXP (x, 1);
6011 rtx minus, symref;
6012 const char *name;
9ebbca7d
GK
6013
6014 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 6015 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
6016 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
6017 contains_minus = XEXP (contains_minus, 0);
6018
2bfcf297
DB
6019 minus = XEXP (contains_minus, 0);
6020 symref = XEXP (minus, 0);
6021 XEXP (contains_minus, 0) = symref;
6022 if (TARGET_ELF)
6023 {
6024 char *newname;
6025
6026 name = XSTR (symref, 0);
6027 newname = alloca (strlen (name) + sizeof ("@toc"));
6028 strcpy (newname, name);
6029 strcat (newname, "@toc");
6030 XSTR (symref, 0) = newname;
6031 }
6032 output_addr_const (file, XEXP (x, 1));
6033 if (TARGET_ELF)
6034 XSTR (symref, 0) = name;
9ebbca7d
GK
6035 XEXP (contains_minus, 0) = minus;
6036 }
6037 else
6038 output_addr_const (file, XEXP (x, 1));
6039
6040 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
6041 }
9878760c
RK
6042 else
6043 abort ();
6044}
6045\f
301d03af
RS
6046/* Target hook for assembling integer objects. The powerpc version has
6047 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
6048 is defined. It also needs to handle DI-mode objects on 64-bit
6049 targets. */
6050
6051static bool
6052rs6000_assemble_integer (x, size, aligned_p)
6053 rtx x;
6054 unsigned int size;
6055 int aligned_p;
6056{
6057#ifdef RELOCATABLE_NEEDS_FIXUP
6058 /* Special handling for SI values. */
6059 if (size == 4 && aligned_p)
6060 {
6061 extern int in_toc_section PARAMS ((void));
6062 static int recurse = 0;
6063
6064 /* For -mrelocatable, we mark all addresses that need to be fixed up
6065 in the .fixup section. */
6066 if (TARGET_RELOCATABLE
6067 && !in_toc_section ()
6068 && !in_text_section ()
6069 && !recurse
6070 && GET_CODE (x) != CONST_INT
6071 && GET_CODE (x) != CONST_DOUBLE
6072 && CONSTANT_P (x))
6073 {
6074 char buf[256];
6075
6076 recurse = 1;
6077 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
6078 fixuplabelno++;
6079 ASM_OUTPUT_LABEL (asm_out_file, buf);
6080 fprintf (asm_out_file, "\t.long\t(");
6081 output_addr_const (asm_out_file, x);
6082 fprintf (asm_out_file, ")@fixup\n");
6083 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
6084 ASM_OUTPUT_ALIGN (asm_out_file, 2);
6085 fprintf (asm_out_file, "\t.long\t");
6086 assemble_name (asm_out_file, buf);
6087 fprintf (asm_out_file, "\n\t.previous\n");
6088 recurse = 0;
6089 return true;
6090 }
6091 /* Remove initial .'s to turn a -mcall-aixdesc function
6092 address into the address of the descriptor, not the function
6093 itself. */
6094 else if (GET_CODE (x) == SYMBOL_REF
6095 && XSTR (x, 0)[0] == '.'
6096 && DEFAULT_ABI == ABI_AIX)
6097 {
6098 const char *name = XSTR (x, 0);
6099 while (*name == '.')
6100 name++;
6101
6102 fprintf (asm_out_file, "\t.long\t%s\n", name);
6103 return true;
6104 }
6105 }
6106#endif /* RELOCATABLE_NEEDS_FIXUP */
6107 return default_assemble_integer (x, size, aligned_p);
6108}
6109\f
39a10a29
GK
6110enum rtx_code
6111rs6000_reverse_condition (mode, code)
6112 enum machine_mode mode;
6113 enum rtx_code code;
6114{
6115 /* Reversal of FP compares takes care -- an ordered compare
6116 becomes an unordered compare and vice versa. */
6117 if (mode == CCFPmode)
bab6226b 6118 return reverse_condition_maybe_unordered (code);
39a10a29 6119 else
bab6226b 6120 return reverse_condition (code);
39a10a29
GK
6121}
6122
39a10a29
GK
6123/* Generate a compare for CODE. Return a brand-new rtx that
6124 represents the result of the compare. */
a4f6c312 6125
39a10a29
GK
6126static rtx
6127rs6000_generate_compare (code)
6128 enum rtx_code code;
6129{
6130 enum machine_mode comp_mode;
6131 rtx compare_result;
6132
6133 if (rs6000_compare_fp_p)
6134 comp_mode = CCFPmode;
6135 else if (code == GTU || code == LTU
6136 || code == GEU || code == LEU)
6137 comp_mode = CCUNSmode;
6138 else
6139 comp_mode = CCmode;
6140
6141 /* First, the compare. */
6142 compare_result = gen_reg_rtx (comp_mode);
6143 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
6144 gen_rtx_COMPARE (comp_mode,
6145 rs6000_compare_op0,
6146 rs6000_compare_op1)));
6147
ca5adc63 6148 /* Some kinds of FP comparisons need an OR operation;
de6c5979 6149 except for flag_unsafe_math_optimizations we don't bother. */
39a10a29 6150 if (rs6000_compare_fp_p
de6c5979 6151 && ! flag_unsafe_math_optimizations
39a10a29
GK
6152 && (code == LE || code == GE
6153 || code == UNEQ || code == LTGT
6154 || code == UNGT || code == UNLT))
6155 {
6156 enum rtx_code or1, or2;
6157 rtx or1_rtx, or2_rtx, compare2_rtx;
6158 rtx or_result = gen_reg_rtx (CCEQmode);
6159
6160 switch (code)
6161 {
6162 case LE: or1 = LT; or2 = EQ; break;
6163 case GE: or1 = GT; or2 = EQ; break;
6164 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
6165 case LTGT: or1 = LT; or2 = GT; break;
6166 case UNGT: or1 = UNORDERED; or2 = GT; break;
6167 case UNLT: or1 = UNORDERED; or2 = LT; break;
6168 default: abort ();
6169 }
6170 validate_condition_mode (or1, comp_mode);
6171 validate_condition_mode (or2, comp_mode);
6172 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
6173 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
6174 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
6175 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
6176 const_true_rtx);
6177 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
6178
6179 compare_result = or_result;
6180 code = EQ;
6181 }
6182
6183 validate_condition_mode (code, GET_MODE (compare_result));
6184
6185 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
6186}
6187
6188
6189/* Emit the RTL for an sCOND pattern. */
6190
6191void
6192rs6000_emit_sCOND (code, result)
6193 enum rtx_code code;
6194 rtx result;
6195{
6196 rtx condition_rtx;
6197 enum machine_mode op_mode;
6198
6199 condition_rtx = rs6000_generate_compare (code);
6200
6201 op_mode = GET_MODE (rs6000_compare_op0);
6202 if (op_mode == VOIDmode)
6203 op_mode = GET_MODE (rs6000_compare_op1);
6204
6205 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
6206 {
6207 PUT_MODE (condition_rtx, DImode);
6208 convert_move (result, condition_rtx, 0);
6209 }
6210 else
6211 {
6212 PUT_MODE (condition_rtx, SImode);
6213 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
6214 }
6215}
6216
39a10a29
GK
6217/* Emit a branch of kind CODE to location LOC. */
6218
6219void
6220rs6000_emit_cbranch (code, loc)
6221 enum rtx_code code;
6222 rtx loc;
6223{
6224 rtx condition_rtx, loc_ref;
6225
6226 condition_rtx = rs6000_generate_compare (code);
6227 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
6228 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
6229 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
6230 loc_ref, pc_rtx)));
6231}
6232
12a4e8c5
GK
6233/* Return the string to output a conditional branch to LABEL, which is
6234 the operand number of the label, or -1 if the branch is really a
6235 conditional return.
6236
6237 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
6238 condition code register and its mode specifies what kind of
6239 comparison we made.
6240
6241 REVERSED is non-zero if we should reverse the sense of the comparison.
6242
6243 INSN is the insn. */
6244
6245char *
6246output_cbranch (op, label, reversed, insn)
6247 rtx op;
6248 const char * label;
6249 int reversed;
6250 rtx insn;
6251{
6252 static char string[64];
6253 enum rtx_code code = GET_CODE (op);
6254 rtx cc_reg = XEXP (op, 0);
6255 enum machine_mode mode = GET_MODE (cc_reg);
6256 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 6257 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
6258 int really_reversed = reversed ^ need_longbranch;
6259 char *s = string;
6260 const char *ccode;
6261 const char *pred;
6262 rtx note;
6263
39a10a29
GK
6264 validate_condition_mode (code, mode);
6265
6266 /* Work out which way this really branches. We could use
6267 reverse_condition_maybe_unordered here always but this
6268 makes the resulting assembler clearer. */
12a4e8c5 6269 if (really_reversed)
39a10a29 6270 code = rs6000_reverse_condition (mode, code);
12a4e8c5 6271
39a10a29 6272 switch (code)
12a4e8c5
GK
6273 {
6274 /* Not all of these are actually distinct opcodes, but
6275 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
6276 case NE: case LTGT:
6277 ccode = "ne"; break;
6278 case EQ: case UNEQ:
6279 ccode = "eq"; break;
6280 case GE: case GEU:
6281 ccode = "ge"; break;
6282 case GT: case GTU: case UNGT:
6283 ccode = "gt"; break;
6284 case LE: case LEU:
6285 ccode = "le"; break;
6286 case LT: case LTU: case UNLT:
6287 ccode = "lt"; break;
12a4e8c5
GK
6288 case UNORDERED: ccode = "un"; break;
6289 case ORDERED: ccode = "nu"; break;
6290 case UNGE: ccode = "nl"; break;
6291 case UNLE: ccode = "ng"; break;
6292 default:
a4f6c312 6293 abort ();
12a4e8c5
GK
6294 }
6295
94a54f47
GK
6296 /* Maybe we have a guess as to how likely the branch is.
6297 The old mnemonics don't have a way to specify this information. */
12a4e8c5
GK
6298 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
6299 if (note != NULL_RTX)
6300 {
6301 /* PROB is the difference from 50%. */
6302 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
6303
6304 /* For branches that are very close to 50%, assume not-taken. */
6305 if (abs (prob) > REG_BR_PROB_BASE / 20
6306 && ((prob > 0) ^ need_longbranch))
6307 pred = "+";
6308 else
6309 pred = "-";
6310 }
6311 else
6312 pred = "";
6313
6314 if (label == NULL)
94a54f47 6315 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 6316 else
94a54f47 6317 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 6318
37c67319
GK
6319 /* We need to escape any '%' characters in the reg_names string.
6320 Assume they'd only be the first character... */
6321 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
6322 *s++ = '%';
94a54f47 6323 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
6324
6325 if (label != NULL)
6326 {
6327 /* If the branch distance was too far, we may have to use an
6328 unconditional branch to go the distance. */
6329 if (need_longbranch)
44518ddd 6330 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
6331 else
6332 s += sprintf (s, ",%s", label);
6333 }
6334
6335 return string;
6336}
50a0b056
GK
6337
6338/* Emit a conditional move: move TRUE_COND to DEST if OP of the
6339 operands of the last comparison is nonzero/true, FALSE_COND if it
6340 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 6341
50a0b056
GK
6342int
6343rs6000_emit_cmove (dest, op, true_cond, false_cond)
6344 rtx dest;
6345 rtx op;
6346 rtx true_cond;
6347 rtx false_cond;
6348{
6349 enum rtx_code code = GET_CODE (op);
6350 rtx op0 = rs6000_compare_op0;
6351 rtx op1 = rs6000_compare_op1;
6352 REAL_VALUE_TYPE c1;
6353 enum machine_mode mode = GET_MODE (op0);
6354 rtx temp;
6355
6356 /* First, work out if the hardware can do this at all, or
6357 if it's too slow... */
6358 /* If the comparison is an integer one, since we only have fsel
6359 it'll be cheaper to use a branch. */
6360 if (! rs6000_compare_fp_p)
6361 return 0;
6362
6363 /* Eliminate half of the comparisons by switching operands, this
6364 makes the remaining code simpler. */
6365 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
6366 || code == LTGT || code == LT)
6367 {
6368 code = reverse_condition_maybe_unordered (code);
6369 temp = true_cond;
6370 true_cond = false_cond;
6371 false_cond = temp;
6372 }
6373
6374 /* UNEQ and LTGT take four instructions for a comparison with zero,
6375 it'll probably be faster to use a branch here too. */
6376 if (code == UNEQ)
6377 return 0;
6378
6379 if (GET_CODE (op1) == CONST_DOUBLE)
6380 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
6381
6382 /* We're going to try to implement comparions by performing
6383 a subtract, then comparing against zero. Unfortunately,
6384 Inf - Inf is NaN which is not zero, and so if we don't
6385 know that the the operand is finite and the comparison
6386 would treat EQ different to UNORDERED, we can't do it. */
6387 if (! flag_unsafe_math_optimizations
6388 && code != GT && code != UNGE
6389 && (GET_CODE (op1) != CONST_DOUBLE || target_isinf (c1))
6390 /* Constructs of the form (a OP b ? a : b) are safe. */
6391 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
6392 || (! rtx_equal_p (op0, true_cond)
6393 && ! rtx_equal_p (op1, true_cond))))
6394 return 0;
6395 /* At this point we know we can use fsel. */
6396
6397 /* Reduce the comparison to a comparison against zero. */
6398 temp = gen_reg_rtx (mode);
6399 emit_insn (gen_rtx_SET (VOIDmode, temp,
6400 gen_rtx_MINUS (mode, op0, op1)));
6401 op0 = temp;
6402 op1 = CONST0_RTX (mode);
6403
6404 /* If we don't care about NaNs we can reduce some of the comparisons
6405 down to faster ones. */
6406 if (flag_unsafe_math_optimizations)
6407 switch (code)
6408 {
6409 case GT:
6410 code = LE;
6411 temp = true_cond;
6412 true_cond = false_cond;
6413 false_cond = temp;
6414 break;
6415 case UNGE:
6416 code = GE;
6417 break;
6418 case UNEQ:
6419 code = EQ;
6420 break;
6421 default:
6422 break;
6423 }
6424
6425 /* Now, reduce everything down to a GE. */
6426 switch (code)
6427 {
6428 case GE:
6429 break;
6430
6431 case LE:
6432 temp = gen_reg_rtx (mode);
6433 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0)));
6434 op0 = temp;
6435 break;
6436
6437 case ORDERED:
6438 temp = gen_reg_rtx (mode);
6439 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (mode, op0)));
6440 op0 = temp;
6441 break;
6442
6443 case EQ:
6444 temp = gen_reg_rtx (mode);
6445 emit_insn (gen_rtx_SET (VOIDmode, temp,
6446 gen_rtx_NEG (mode,
6447 gen_rtx_ABS (mode, op0))));
6448 op0 = temp;
6449 break;
6450
6451 case UNGE:
6452 temp = gen_reg_rtx (mode);
6453 emit_insn (gen_rtx_SET (VOIDmode, temp,
6454 gen_rtx_IF_THEN_ELSE (mode,
6455 gen_rtx_GE (VOIDmode,
6456 op0, op1),
6457 true_cond, false_cond)));
6458 false_cond = temp;
6459 true_cond = false_cond;
6460
6461 temp = gen_reg_rtx (mode);
6462 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0)));
6463 op0 = temp;
6464 break;
6465
6466 case GT:
6467 temp = gen_reg_rtx (mode);
6468 emit_insn (gen_rtx_SET (VOIDmode, temp,
6469 gen_rtx_IF_THEN_ELSE (mode,
6470 gen_rtx_GE (VOIDmode,
6471 op0, op1),
6472 true_cond, false_cond)));
6473 true_cond = temp;
6474 false_cond = true_cond;
6475
6476 temp = gen_reg_rtx (mode);
6477 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0)));
6478 op0 = temp;
6479 break;
6480
6481 default:
6482 abort ();
6483 }
6484
6485 emit_insn (gen_rtx_SET (VOIDmode, dest,
9f1a9740 6486 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
50a0b056
GK
6487 gen_rtx_GE (VOIDmode,
6488 op0, op1),
6489 true_cond, false_cond)));
6490 return 1;
6491}
6492
6493void
6494rs6000_emit_minmax (dest, code, op0, op1)
6495 rtx dest;
6496 enum rtx_code code;
6497 rtx op0;
6498 rtx op1;
6499{
6500 enum machine_mode mode = GET_MODE (op0);
6501 rtx target;
6502 if (code == SMAX || code == UMAX)
6503 target = emit_conditional_move (dest, GE, op0, op1, mode,
6504 op0, op1, mode, 0);
6505 else
6506 target = emit_conditional_move (dest, GE, op0, op1, mode,
6507 op1, op0, mode, 0);
6508 if (target == NULL_RTX)
6509 abort ();
6510 if (target != dest)
6511 emit_move_insn (dest, target);
6512}
12a4e8c5 6513\f
a4f6c312
SS
6514/* This page contains routines that are used to determine what the
6515 function prologue and epilogue code will do and write them out. */
9878760c 6516
a4f6c312
SS
6517/* Return the first fixed-point register that is required to be
6518 saved. 32 if none. */
9878760c
RK
6519
6520int
6521first_reg_to_save ()
6522{
6523 int first_reg;
6524
6525 /* Find lowest numbered live register. */
6526 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
6527 if (regs_ever_live[first_reg]
6528 && (! call_used_regs[first_reg]
6529 || (first_reg == PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
6530 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
6531 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
6532 break;
6533
b5253831
DE
6534 if (profile_flag)
6535 {
6536 /* AIX must save/restore every register that contains a parameter
6537 before/after the .__mcount call plus an additional register
6538 for the static chain, if needed; use registers from 30 down to 22
6539 to do this. */
ee890fe2 6540 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
b5253831
DE
6541 {
6542 int last_parm_reg, profile_first_reg;
6543
6544 /* Figure out last used parameter register. The proper thing
6545 to do is to walk incoming args of the function. A function
6546 might have live parameter registers even if it has no
6547 incoming args. */
6548 for (last_parm_reg = 10;
6549 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
6550 last_parm_reg--)
6551 ;
6552
6553 /* Calculate first reg for saving parameter registers
6554 and static chain.
6555 Skip reg 31 which may contain the frame pointer. */
6556 profile_first_reg = (33 - last_parm_reg
6557 - (current_function_needs_context ? 1 : 0));
ee890fe2
SS
6558#if TARGET_MACHO
6559 /* Need to skip another reg to account for R31 being PICBASE
6560 (when flag_pic is set) or R30 being used as the frame
6561 pointer (when flag_pic is not set). */
6562 --profile_first_reg;
6563#endif
b5253831
DE
6564 /* Do not save frame pointer if no parameters needs to be saved. */
6565 if (profile_first_reg == 31)
6566 profile_first_reg = 32;
6567
6568 if (first_reg > profile_first_reg)
6569 first_reg = profile_first_reg;
6570 }
e165f3f0 6571
b5253831
DE
6572 /* SVR4 may need one register to preserve the static chain. */
6573 else if (current_function_needs_context)
6574 {
6575 /* Skip reg 31 which may contain the frame pointer. */
6576 if (first_reg > 30)
6577 first_reg = 30;
6578 }
6579 }
e165f3f0 6580
ee890fe2
SS
6581#if TARGET_MACHO
6582 if (flag_pic && current_function_uses_pic_offset_table &&
6583 (first_reg > PIC_OFFSET_TABLE_REGNUM))
6584 return PIC_OFFSET_TABLE_REGNUM;
6585#endif
6586
9878760c
RK
6587 return first_reg;
6588}
6589
6590/* Similar, for FP regs. */
6591
6592int
6593first_fp_reg_to_save ()
6594{
6595 int first_reg;
6596
6597 /* Find lowest numbered live register. */
6598 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
6599 if (regs_ever_live[first_reg])
6600 break;
6601
6602 return first_reg;
6603}
00b960c7
AH
6604
6605/* Similar, for AltiVec regs. */
6606
6607static int
6608first_altivec_reg_to_save ()
6609{
6610 int i;
6611
6612 /* Stack frame remains as is unless we are in AltiVec ABI. */
6613 if (! TARGET_ALTIVEC_ABI)
6614 return LAST_ALTIVEC_REGNO + 1;
6615
6616 /* Find lowest numbered live register. */
6617 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
6618 if (regs_ever_live[i])
6619 break;
6620
6621 return i;
6622}
6623
6624/* Return a 32-bit mask of the AltiVec registers we need to set in
6625 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
6626 the 32-bit word is 0. */
6627
6628static unsigned int
6629compute_vrsave_mask ()
6630{
6631 unsigned int i, mask = 0;
6632
6633 /* First, find out if we use _any_ altivec registers. */
6634 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
6635 if (regs_ever_live[i])
6636 mask |= ALTIVEC_REG_BIT (i);
6637
6638 if (mask == 0)
6639 return mask;
6640
6641 /* Next, add all registers that are call-clobbered. We do this
6642 because post-reload register optimizers such as regrename_optimize
6643 may choose to use them. They never change the register class
6644 chosen by reload, so cannot create new uses of altivec registers
6645 if there were none before, so the early exit above is safe. */
6646 /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow
6647 altivec registers not saved in the mask, which might well make the
6648 adjustments below more effective in eliding the save/restore of
6649 VRSAVE in small functions. */
6650 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
6651 if (call_used_regs[i])
6652 mask |= ALTIVEC_REG_BIT (i);
6653
6654 /* Next, remove the argument registers from the set. These must
6655 be in the VRSAVE mask set by the caller, so we don't need to add
6656 them in again. More importantly, the mask we compute here is
6657 used to generate CLOBBERs in the set_vrsave insn, and we do not
6658 wish the argument registers to die. */
6659 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
6660 mask &= ~ALTIVEC_REG_BIT (i);
6661
6662 /* Similarly, remove the return value from the set. */
6663 {
6664 bool yes = false;
6665 diddle_return_value (is_altivec_return_reg, &yes);
6666 if (yes)
6667 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
6668 }
6669
6670 return mask;
6671}
6672
6673static void
6674is_altivec_return_reg (reg, xyes)
6675 rtx reg;
6676 void *xyes;
6677{
6678 bool *yes = (bool *) xyes;
6679 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
6680 *yes = true;
6681}
6682
4697a36c
MM
6683\f
6684/* Calculate the stack information for the current function. This is
6685 complicated by having two separate calling sequences, the AIX calling
6686 sequence and the V.4 calling sequence.
6687
592696dd 6688 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 6689 32-bit 64-bit
4697a36c 6690 SP----> +---------------------------------------+
a260abc9 6691 | back chain to caller | 0 0
4697a36c 6692 +---------------------------------------+
a260abc9 6693 | saved CR | 4 8 (8-11)
4697a36c 6694 +---------------------------------------+
a260abc9 6695 | saved LR | 8 16
4697a36c 6696 +---------------------------------------+
a260abc9 6697 | reserved for compilers | 12 24
4697a36c 6698 +---------------------------------------+
a260abc9 6699 | reserved for binders | 16 32
4697a36c 6700 +---------------------------------------+
a260abc9 6701 | saved TOC pointer | 20 40
4697a36c 6702 +---------------------------------------+
a260abc9 6703 | Parameter save area (P) | 24 48
4697a36c 6704 +---------------------------------------+
a260abc9 6705 | Alloca space (A) | 24+P etc.
802a0058 6706 +---------------------------------------+
a7df97e6 6707 | Local variable space (L) | 24+P+A
4697a36c 6708 +---------------------------------------+
a7df97e6 6709 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 6710 +---------------------------------------+
00b960c7
AH
6711 | Save area for AltiVec registers (W) | 24+P+A+L+X
6712 +---------------------------------------+
6713 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
6714 +---------------------------------------+
6715 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 6716 +---------------------------------------+
00b960c7
AH
6717 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
6718 +---------------------------------------+
6719 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
6720 +---------------------------------------+
6721 old SP->| back chain to caller's caller |
6722 +---------------------------------------+
6723
5376a30c
KR
6724 The required alignment for AIX configurations is two words (i.e., 8
6725 or 16 bytes).
6726
6727
4697a36c
MM
6728 V.4 stack frames look like:
6729
6730 SP----> +---------------------------------------+
6731 | back chain to caller | 0
6732 +---------------------------------------+
5eb387b8 6733 | caller's saved LR | 4
4697a36c
MM
6734 +---------------------------------------+
6735 | Parameter save area (P) | 8
6736 +---------------------------------------+
a7df97e6
MM
6737 | Alloca space (A) | 8+P
6738 +---------------------------------------+
6739 | Varargs save area (V) | 8+P+A
6740 +---------------------------------------+
6741 | Local variable space (L) | 8+P+A+V
6742 +---------------------------------------+
6743 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 6744 +---------------------------------------+
00b960c7
AH
6745 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
6746 +---------------------------------------+
6747 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
6748 +---------------------------------------+
6749 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
6750 +---------------------------------------+
6751 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 6752 +---------------------------------------+
00b960c7 6753 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 6754 +---------------------------------------+
00b960c7 6755 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
6756 +---------------------------------------+
6757 old SP->| back chain to caller's caller |
6758 +---------------------------------------+
b6c9286a 6759
5376a30c
KR
6760 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
6761 given. (But note below and in sysv4.h that we require only 8 and
6762 may round up the size of our stack frame anyways. The historical
6763 reason is early versions of powerpc-linux which didn't properly
6764 align the stack at program startup. A happy side-effect is that
6765 -mno-eabi libraries can be used with -meabi programs.)
6766
5376a30c
KR
6767 The EABI configuration defaults to the V.4 layout, unless
6768 -mcall-aix is used, in which case the AIX layout is used. However,
6769 the stack alignment requirements may differ. If -mno-eabi is not
6770 given, the required stack alignment is 8 bytes; if -mno-eabi is
6771 given, the required alignment is 16 bytes. (But see V.4 comment
6772 above.) */
4697a36c 6773
61b2fbe7
MM
6774#ifndef ABI_STACK_BOUNDARY
6775#define ABI_STACK_BOUNDARY STACK_BOUNDARY
6776#endif
6777
4697a36c
MM
6778rs6000_stack_t *
6779rs6000_stack_info ()
6780{
6781 static rs6000_stack_t info, zero_info;
6782 rs6000_stack_t *info_ptr = &info;
9ebbca7d 6783 int reg_size = TARGET_POWERPC64 ? 8 : 4;
24d304eb 6784 enum rs6000_abi abi;
83720594 6785 int ehrd_size;
b6c9286a 6786 int total_raw_size;
4697a36c 6787
a4f6c312 6788 /* Zero all fields portably. */
4697a36c
MM
6789 info = zero_info;
6790
a4f6c312 6791 /* Select which calling sequence. */
b6c9286a 6792 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 6793
a4f6c312 6794 /* Calculate which registers need to be saved & save area size. */
4697a36c 6795 info_ptr->first_gp_reg_save = first_reg_to_save ();
906fb125
GK
6796 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
6797 even if it currently looks like we won't. */
2bfcf297 6798 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
f607bc57
ZW
6799 || (flag_pic == 1 && abi == ABI_V4)
6800 || (flag_pic && abi == ABI_DARWIN))
906fb125
GK
6801 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
6802 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
6803 else
6804 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c
MM
6805
6806 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
6807 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
6808
00b960c7
AH
6809 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
6810 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
6811 - info_ptr->first_altivec_reg_save);
6812
592696dd 6813 /* Does this function call anything? */
71f123ca
FS
6814 info_ptr->calls_p = (! current_function_is_leaf
6815 || cfun->machine->ra_needs_full_frame);
b6c9286a 6816
a4f6c312 6817 /* Determine if we need to save the link register. */
71f123ca 6818 if (rs6000_ra_ever_killed ()
38c1f2d7 6819 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4697a36c
MM
6820#ifdef TARGET_RELOCATABLE
6821 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
6822#endif
6823 || (info_ptr->first_fp_reg_save != 64
6824 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 6825 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
24d304eb 6826 || (abi == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
6827 || (DEFAULT_ABI == ABI_DARWIN
6828 && flag_pic
6829 && current_function_uses_pic_offset_table)
4697a36c
MM
6830 || info_ptr->calls_p)
6831 {
6832 info_ptr->lr_save_p = 1;
9ebbca7d 6833 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
6834 }
6835
9ebbca7d
GK
6836 /* Determine if we need to save the condition code registers. */
6837 if (regs_ever_live[CR2_REGNO]
6838 || regs_ever_live[CR3_REGNO]
6839 || regs_ever_live[CR4_REGNO])
4697a36c
MM
6840 {
6841 info_ptr->cr_save_p = 1;
f607bc57 6842 if (abi == ABI_V4)
4697a36c
MM
6843 info_ptr->cr_size = reg_size;
6844 }
6845
83720594
RH
6846 /* If the current function calls __builtin_eh_return, then we need
6847 to allocate stack space for registers that will hold data for
6848 the exception handler. */
6849 if (current_function_calls_eh_return)
6850 {
6851 unsigned int i;
6852 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
6853 continue;
6854 ehrd_size = i * UNITS_PER_WORD;
6855 }
6856 else
6857 ehrd_size = 0;
6858
592696dd 6859 /* Determine various sizes. */
4697a36c
MM
6860 info_ptr->reg_size = reg_size;
6861 info_ptr->fixed_size = RS6000_SAVE_AREA;
6862 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 6863 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
6864 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
6865 8);
00b960c7
AH
6866
6867 if (TARGET_ALTIVEC_ABI)
6868 {
6869 info_ptr->vrsave_mask = compute_vrsave_mask ();
6870 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
6871 }
6872 else
6873 {
6874 info_ptr->vrsave_mask = 0;
6875 info_ptr->vrsave_size = 0;
6876 }
b6c9286a 6877
592696dd 6878 /* Calculate the offsets. */
24d304eb 6879 switch (abi)
4697a36c 6880 {
b6c9286a 6881 case ABI_NONE:
24d304eb 6882 default:
b6c9286a
MM
6883 abort ();
6884
6885 case ABI_AIX:
6886 case ABI_AIX_NODESC:
ee890fe2 6887 case ABI_DARWIN:
b6c9286a
MM
6888 info_ptr->fp_save_offset = - info_ptr->fp_size;
6889 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
6890
6891 if (TARGET_ALTIVEC_ABI)
6892 {
6893 info_ptr->vrsave_save_offset
6894 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
6895
6896 /* Align stack so vector save area is on a quadword boundary. */
6897 if (info_ptr->altivec_size != 0)
6898 info_ptr->altivec_padding_size
6899 = 16 - (-info_ptr->vrsave_save_offset % 16);
6900 else
6901 info_ptr->altivec_padding_size = 0;
6902
6903 info_ptr->altivec_save_offset
6904 = info_ptr->vrsave_save_offset
6905 - info_ptr->altivec_padding_size
6906 - info_ptr->altivec_size;
6907
6908 /* Adjust for AltiVec case. */
6909 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
6910 }
6911 else
6912 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
6913 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
6914 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
6915 break;
6916
6917 case ABI_V4:
b6c9286a
MM
6918 info_ptr->fp_save_offset = - info_ptr->fp_size;
6919 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 6920 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7
AH
6921
6922 if (TARGET_ALTIVEC_ABI)
6923 {
6924 info_ptr->vrsave_save_offset
6925 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
6926
6927 /* Align stack so vector save area is on a quadword boundary. */
6928 if (info_ptr->altivec_size != 0)
6929 info_ptr->altivec_padding_size
6930 = 16 - (-info_ptr->vrsave_save_offset % 16);
6931 else
6932 info_ptr->altivec_padding_size = 0;
6933
6934 info_ptr->altivec_save_offset
6935 = info_ptr->vrsave_save_offset
6936 - info_ptr->altivec_padding_size
6937 - info_ptr->altivec_size;
6938
6939 /* Adjust for AltiVec case. */
6940 info_ptr->toc_save_offset
6941 = info_ptr->altivec_save_offset - info_ptr->toc_size;
6942 }
6943 else
6944 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 6945 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
6946 info_ptr->lr_save_offset = reg_size;
6947 break;
4697a36c
MM
6948 }
6949
00b960c7
AH
6950 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
6951 + info_ptr->gp_size
6952 + info_ptr->altivec_size
6953 + info_ptr->altivec_padding_size
6954 + info_ptr->vrsave_size
6955 + ehrd_size
6956 + info_ptr->cr_size
6957 + info_ptr->lr_size
6958 + info_ptr->vrsave_size
6959 + info_ptr->toc_size,
6960 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
6961 ? 16 : 8);
6962
ff381587
MM
6963 total_raw_size = (info_ptr->vars_size
6964 + info_ptr->parm_size
ff381587
MM
6965 + info_ptr->save_size
6966 + info_ptr->varargs_size
6967 + info_ptr->fixed_size);
6968
a4f6c312
SS
6969 info_ptr->total_size =
6970 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
6971
6972 /* Determine if we need to allocate any stack frame:
6973
a4f6c312
SS
6974 For AIX we need to push the stack if a frame pointer is needed
6975 (because the stack might be dynamically adjusted), if we are
6976 debugging, if we make calls, or if the sum of fp_save, gp_save,
6977 and local variables are more than the space needed to save all
6978 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
6979 + 18*8 = 288 (GPR13 reserved).
ff381587 6980
a4f6c312
SS
6981 For V.4 we don't have the stack cushion that AIX uses, but assume
6982 that the debugger can handle stackless frames. */
ff381587
MM
6983
6984 if (info_ptr->calls_p)
6985 info_ptr->push_p = 1;
6986
f607bc57 6987 else if (abi == ABI_V4)
ff381587 6988 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
9ebbca7d 6989 || info_ptr->calls_p);
ff381587
MM
6990
6991 else
6992 info_ptr->push_p = (frame_pointer_needed
ee890fe2 6993 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
ff381587 6994 || ((total_raw_size - info_ptr->fixed_size)
bfc79d3b 6995 > (TARGET_32BIT ? 220 : 288)));
ff381587 6996
a4f6c312 6997 /* Zero offsets if we're not saving those registers. */
8dda1a21 6998 if (info_ptr->fp_size == 0)
4697a36c
MM
6999 info_ptr->fp_save_offset = 0;
7000
8dda1a21 7001 if (info_ptr->gp_size == 0)
4697a36c
MM
7002 info_ptr->gp_save_offset = 0;
7003
00b960c7
AH
7004 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
7005 info_ptr->altivec_save_offset = 0;
7006
7007 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
7008 info_ptr->vrsave_save_offset = 0;
7009
c81fc13e 7010 if (! info_ptr->lr_save_p)
4697a36c
MM
7011 info_ptr->lr_save_offset = 0;
7012
c81fc13e 7013 if (! info_ptr->cr_save_p)
4697a36c
MM
7014 info_ptr->cr_save_offset = 0;
7015
c81fc13e 7016 if (! info_ptr->toc_save_p)
b6c9286a
MM
7017 info_ptr->toc_save_offset = 0;
7018
4697a36c
MM
7019 return info_ptr;
7020}
7021
7022void
7023debug_stack_info (info)
7024 rs6000_stack_t *info;
9878760c 7025{
d330fd93 7026 const char *abi_string;
24d304eb 7027
c81fc13e 7028 if (! info)
4697a36c
MM
7029 info = rs6000_stack_info ();
7030
7031 fprintf (stderr, "\nStack information for function %s:\n",
7032 ((current_function_decl && DECL_NAME (current_function_decl))
7033 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
7034 : "<unknown>"));
7035
24d304eb
RK
7036 switch (info->abi)
7037 {
b6c9286a
MM
7038 default: abi_string = "Unknown"; break;
7039 case ABI_NONE: abi_string = "NONE"; break;
f607bc57 7040 case ABI_AIX:
b6c9286a 7041 case ABI_AIX_NODESC: abi_string = "AIX"; break;
ee890fe2 7042 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 7043 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
7044 }
7045
7046 fprintf (stderr, "\tABI = %5s\n", abi_string);
7047
00b960c7
AH
7048 if (TARGET_ALTIVEC_ABI)
7049 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
7050
4697a36c
MM
7051 if (info->first_gp_reg_save != 32)
7052 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
7053
7054 if (info->first_fp_reg_save != 64)
7055 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 7056
00b960c7
AH
7057 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
7058 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
7059 info->first_altivec_reg_save);
7060
4697a36c
MM
7061 if (info->lr_save_p)
7062 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 7063
4697a36c
MM
7064 if (info->cr_save_p)
7065 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
7066
b6c9286a
MM
7067 if (info->toc_save_p)
7068 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
7069
00b960c7
AH
7070 if (info->vrsave_mask)
7071 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
7072
4697a36c
MM
7073 if (info->push_p)
7074 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
7075
7076 if (info->calls_p)
7077 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
7078
4697a36c
MM
7079 if (info->gp_save_offset)
7080 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
7081
7082 if (info->fp_save_offset)
7083 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
7084
00b960c7
AH
7085 if (info->altivec_save_offset)
7086 fprintf (stderr, "\taltivec_save_offset = %5d\n",
7087 info->altivec_save_offset);
7088
7089 if (info->vrsave_save_offset)
7090 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
7091 info->vrsave_save_offset);
7092
4697a36c
MM
7093 if (info->lr_save_offset)
7094 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
7095
7096 if (info->cr_save_offset)
7097 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
7098
b6c9286a
MM
7099 if (info->toc_save_offset)
7100 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
7101
4697a36c
MM
7102 if (info->varargs_save_offset)
7103 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
7104
7105 if (info->total_size)
7106 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
7107
7108 if (info->varargs_size)
7109 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
7110
7111 if (info->vars_size)
7112 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
7113
7114 if (info->parm_size)
7115 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
7116
7117 if (info->fixed_size)
7118 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
7119
7120 if (info->gp_size)
7121 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
7122
7123 if (info->fp_size)
7124 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
7125
00b960c7
AH
7126 if (info->altivec_size)
7127 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
7128
7129 if (info->vrsave_size)
7130 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
7131
7132 if (info->altivec_padding_size)
7133 fprintf (stderr, "\taltivec_padding_size= %5d\n",
7134 info->altivec_padding_size);
7135
a4f6c312 7136 if (info->lr_size)
ed947a96 7137 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 7138
4697a36c
MM
7139 if (info->cr_size)
7140 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
7141
a4f6c312 7142 if (info->toc_size)
b6c9286a
MM
7143 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
7144
4697a36c
MM
7145 if (info->save_size)
7146 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
7147
7148 if (info->reg_size != 4)
7149 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
7150
7151 fprintf (stderr, "\n");
9878760c 7152}
71f123ca
FS
7153
7154rtx
7155rs6000_return_addr (count, frame)
7156 int count;
7157 rtx frame;
7158{
a4f6c312
SS
7159 /* Currently we don't optimize very well between prolog and body
7160 code and for PIC code the code can be actually quite bad, so
7161 don't try to be too clever here. */
3418dd3a
FS
7162 if (count != 0
7163 || flag_pic != 0
7164 || DEFAULT_ABI == ABI_AIX
7165 || DEFAULT_ABI == ABI_AIX_NODESC)
71f123ca
FS
7166 {
7167 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
7168
7169 return
7170 gen_rtx_MEM
7171 (Pmode,
7172 memory_address
7173 (Pmode,
7174 plus_constant (copy_to_reg
7175 (gen_rtx_MEM (Pmode,
7176 memory_address (Pmode, frame))),
7177 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
7178 }
7179
9e2f7ec7 7180 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
7181}
7182
7183static int
7184rs6000_ra_ever_killed ()
7185{
7186 rtx top;
7187
7188#ifdef ASM_OUTPUT_MI_THUNK
7189 if (current_function_is_thunk)
7190 return 0;
7191#endif
9e2f7ec7
DD
7192 if (!has_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM)
7193 || cfun->machine->ra_needs_full_frame)
71f123ca
FS
7194 return regs_ever_live[LINK_REGISTER_REGNUM];
7195
7196 push_topmost_sequence ();
7197 top = get_insns ();
7198 pop_topmost_sequence ();
7199
7200 return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
7201 top, NULL_RTX);
7202}
4697a36c 7203\f
8cd8f856
GK
7204/* Add a REG_MAYBE_DEAD note to the insn. */
7205static void
7206rs6000_maybe_dead (insn)
7207 rtx insn;
7208{
7209 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
7210 const0_rtx,
7211 REG_NOTES (insn));
7212}
7213
9ebbca7d 7214/* Emit instructions needed to load the TOC register.
c7ca610e 7215 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 7216 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
7217
7218void
9ebbca7d
GK
7219rs6000_emit_load_toc_table (fromprolog)
7220 int fromprolog;
c7ca610e 7221{
9ebbca7d
GK
7222 rtx dest;
7223 dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
c7ca610e 7224
2bfcf297 7225 if (TARGET_ELF && DEFAULT_ABI != ABI_AIX)
c7ca610e 7226 {
f607bc57 7227 if (DEFAULT_ABI == ABI_V4 && flag_pic == 1)
38c1f2d7 7228 {
9ebbca7d
GK
7229 rtx temp = (fromprolog
7230 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
7231 : gen_reg_rtx (Pmode));
2bfcf297 7232 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
8cd8f856 7233 rs6000_maybe_dead (emit_move_insn (dest, temp));
38c1f2d7 7234 }
9ebbca7d
GK
7235 else if (flag_pic == 2)
7236 {
7237 char buf[30];
7238 rtx tempLR = (fromprolog
7239 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
7240 : gen_reg_rtx (Pmode));
7241 rtx temp0 = (fromprolog
7242 ? gen_rtx_REG (Pmode, 0)
7243 : gen_reg_rtx (Pmode));
7244 rtx symF;
7245
7246 /* possibly create the toc section */
7247 if (! toc_initialized)
7248 {
7249 toc_section ();
7250 function_section (current_function_decl);
7251 }
7252
7253 if (fromprolog)
7254 {
7255 rtx symL;
7256
7257 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
a8a05998 7258 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
38c1f2d7 7259
9ebbca7d 7260 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
a8a05998 7261 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
38c1f2d7 7262
8cd8f856
GK
7263 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
7264 symF)));
7265 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
7266 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
7267 symL,
7268 symF)));
9ebbca7d
GK
7269 }
7270 else
7271 {
7272 rtx tocsym;
7273 static int reload_toc_labelno = 0;
7274
b999aaeb 7275 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
38c1f2d7 7276
9ebbca7d 7277 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
a8a05998 7278 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 7279
8cd8f856
GK
7280 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
7281 symF,
7282 tocsym)));
7283 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
7284 rs6000_maybe_dead (emit_move_insn (temp0,
7285 gen_rtx_MEM (Pmode, dest)));
9ebbca7d 7286 }
8cd8f856 7287 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
9ebbca7d
GK
7288 }
7289 else if (flag_pic == 0 && TARGET_MINIMAL_TOC)
7290 {
7291 /* This is for AIX code running in non-PIC ELF. */
7292 char buf[30];
7293 rtx realsym;
38c1f2d7 7294 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
a8a05998 7295 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 7296
8cd8f856
GK
7297 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
7298 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
9ebbca7d
GK
7299 }
7300 else
a4f6c312 7301 abort ();
9ebbca7d
GK
7302 }
7303 else
7304 {
7305 if (TARGET_32BIT)
8cd8f856 7306 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
9ebbca7d 7307 else
8cd8f856 7308 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
9ebbca7d
GK
7309 }
7310}
7311
7312int
7313get_TOC_alias_set ()
7314{
7315 static int set = -1;
7316 if (set == -1)
7317 set = new_alias_set ();
7318 return set;
7319}
7320
7321/* This retuns nonzero if the current function uses the TOC. This is
7322 determined by the presence of (unspec ... 7), which is generated by
7323 the various load_toc_* patterns. */
a4f6c312 7324
9ebbca7d
GK
7325int
7326uses_TOC ()
7327{
7328 rtx insn;
38c1f2d7 7329
9ebbca7d 7330 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2c3c49de 7331 if (INSN_P (insn))
9ebbca7d
GK
7332 {
7333 rtx pat = PATTERN (insn);
7334 int i;
7335
8cd8f856 7336 if (GET_CODE (pat) == PARALLEL)
9ebbca7d
GK
7337 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
7338 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
7339 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
7340 return 1;
38c1f2d7 7341 }
9ebbca7d
GK
7342 return 0;
7343}
38c1f2d7 7344
9ebbca7d 7345rtx
a4f6c312 7346create_TOC_reference (symbol)
9ebbca7d
GK
7347 rtx symbol;
7348{
a8a05998
ZW
7349 return gen_rtx_PLUS (Pmode,
7350 gen_rtx_REG (Pmode, TOC_REGISTER),
7351 gen_rtx_CONST (Pmode,
7352 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 7353 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 7354}
38c1f2d7 7355
9ebbca7d
GK
7356#if TARGET_AIX
7357/* __throw will restore its own return address to be the same as the
7358 return address of the function that the throw is being made to.
7359 This is unfortunate, because we want to check the original
7360 return address to see if we need to restore the TOC.
7361 So we have to squirrel it away here.
7362 This is used only in compiling __throw and __rethrow.
c7ca610e 7363
9ebbca7d
GK
7364 Most of this code should be removed by CSE. */
7365static rtx insn_after_throw;
c7ca610e 7366
a4f6c312 7367/* This does the saving... */
9ebbca7d
GK
7368void
7369rs6000_aix_emit_builtin_unwind_init ()
7370{
7371 rtx mem;
7372 rtx stack_top = gen_reg_rtx (Pmode);
7373 rtx opcode_addr = gen_reg_rtx (Pmode);
7374
7375 insn_after_throw = gen_reg_rtx (SImode);
7376
7377 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
7378 emit_move_insn (stack_top, mem);
7379
7380 mem = gen_rtx_MEM (Pmode,
7381 gen_rtx_PLUS (Pmode, stack_top,
7382 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
7383 emit_move_insn (opcode_addr, mem);
7384 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
c7ca610e
RK
7385}
7386
a4f6c312
SS
7387/* Emit insns to _restore_ the TOC register, at runtime (specifically
7388 in _eh.o). Only used on AIX.
9ebbca7d
GK
7389
7390 The idea is that on AIX, function calls look like this:
7391 bl somefunction-trampoline
7392 lwz r2,20(sp)
7393
a4f6c312 7394 and later,
9ebbca7d
GK
7395 somefunction-trampoline:
7396 stw r2,20(sp)
7397 ... load function address in the count register ...
7398 bctr
7399 or like this, if the linker determines that this is not a cross-module call
7400 and so the TOC need not be restored:
7401 bl somefunction
7402 nop
7403 or like this, if the compiler could determine that this is not a
7404 cross-module call:
7405 bl somefunction
7406 now, the tricky bit here is that register 2 is saved and restored
7407 by the _linker_, so we can't readily generate debugging information
7408 for it. So we need to go back up the call chain looking at the
7409 insns at return addresses to see which calls saved the TOC register
7410 and so see where it gets restored from.
7411
7412 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
7413 just before the actual epilogue.
7414
7415 On the bright side, this incurs no space or time overhead unless an
7416 exception is thrown, except for the extra code in libgcc.a.
7417
7418 The parameter STACKSIZE is a register containing (at runtime)
7419 the amount to be popped off the stack in addition to the stack frame
7420 of this routine (which will be __throw or __rethrow, and so is
7421 guaranteed to have a stack frame). */
a4f6c312 7422
9ebbca7d
GK
7423void
7424rs6000_emit_eh_toc_restore (stacksize)
7425 rtx stacksize;
7426{
7427 rtx top_of_stack;
7428 rtx bottom_of_stack = gen_reg_rtx (Pmode);
7429 rtx tocompare = gen_reg_rtx (SImode);
7430 rtx opcode = gen_reg_rtx (SImode);
7431 rtx opcode_addr = gen_reg_rtx (Pmode);
7432 rtx mem;
7433 rtx loop_start = gen_label_rtx ();
7434 rtx no_toc_restore_needed = gen_label_rtx ();
7435 rtx loop_exit = gen_label_rtx ();
7436
7437 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
ba4828e0 7438 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7439 emit_move_insn (bottom_of_stack, mem);
7440
7441 top_of_stack = expand_binop (Pmode, add_optab,
7442 bottom_of_stack, stacksize,
7443 NULL_RTX, 1, OPTAB_WIDEN);
7444
7445 emit_move_insn (tocompare,
7446 GEN_INT (trunc_int_for_mode (TARGET_32BIT
7447 ? 0x80410014
7448 : 0xE8410028, SImode)));
7449
7450 if (insn_after_throw == NULL_RTX)
a4f6c312 7451 abort ();
9ebbca7d
GK
7452 emit_move_insn (opcode, insn_after_throw);
7453
6496a589 7454 emit_note (NULL, NOTE_INSN_LOOP_BEG);
9ebbca7d
GK
7455 emit_label (loop_start);
7456
7457 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
06f4e019 7458 SImode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
7459 no_toc_restore_needed);
7460
7461 mem = gen_rtx_MEM (Pmode,
7462 gen_rtx_PLUS (Pmode, bottom_of_stack,
7463 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
7464 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
7465
7466 emit_label (no_toc_restore_needed);
7467 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
06f4e019 7468 Pmode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
7469 loop_exit);
7470
7471 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
ba4828e0 7472 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7473 emit_move_insn (bottom_of_stack, mem);
7474
7475 mem = gen_rtx_MEM (Pmode,
7476 gen_rtx_PLUS (Pmode, bottom_of_stack,
7477 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
7478 emit_move_insn (opcode_addr, mem);
7479 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
7480
6496a589 7481 emit_note (NULL, NOTE_INSN_LOOP_CONT);
9ebbca7d 7482 emit_jump (loop_start);
6496a589 7483 emit_note (NULL, NOTE_INSN_LOOP_END);
9ebbca7d
GK
7484 emit_label (loop_exit);
7485}
7486#endif /* TARGET_AIX */
38c1f2d7 7487\f
ba4828e0
RK
7488/* This ties together stack memory (MEM with an alias set of
7489 rs6000_sr_alias_set) and the change to the stack pointer. */
7490
9ebbca7d
GK
7491static void
7492rs6000_emit_stack_tie ()
7493{
ba4828e0
RK
7494 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
7495
7496 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7497 emit_insn (gen_stack_tie (mem));
7498}
38c1f2d7 7499
9ebbca7d
GK
7500/* Emit the correct code for allocating stack space, as insns.
7501 If COPY_R12, make sure a copy of the old frame is left in r12.
7502 The generated code may use hard register 0 as a temporary. */
7503
7504static void
7505rs6000_emit_allocate_stack (size, copy_r12)
7506 HOST_WIDE_INT size;
38c1f2d7
MM
7507 int copy_r12;
7508{
9ebbca7d
GK
7509 rtx insn;
7510 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
7511 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
7512 rtx todec = GEN_INT (-size);
a157febd
GK
7513
7514 if (current_function_limit_stack)
7515 {
7516 if (REG_P (stack_limit_rtx)
7517 && REGNO (stack_limit_rtx) > 1
7518 && REGNO (stack_limit_rtx) <= 31)
7519 {
9ebbca7d
GK
7520 emit_insn (Pmode == SImode
7521 ? gen_addsi3 (tmp_reg,
7522 stack_limit_rtx,
7523 GEN_INT (size))
7524 : gen_adddi3 (tmp_reg,
7525 stack_limit_rtx,
7526 GEN_INT (size)));
7527
7528 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
7529 const0_rtx));
a157febd
GK
7530 }
7531 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 7532 && TARGET_32BIT
f607bc57 7533 && DEFAULT_ABI == ABI_V4)
a157febd 7534 {
9ebbca7d
GK
7535 rtx toload = gen_rtx_CONST (VOIDmode,
7536 gen_rtx_PLUS (Pmode,
7537 stack_limit_rtx,
7538 GEN_INT (size)));
7539
7540 emit_insn (gen_elf_high (tmp_reg, toload));
7541 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
7542 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
7543 const0_rtx));
a157febd
GK
7544 }
7545 else
7546 warning ("stack limit expression is not supported");
7547 }
7548
9ebbca7d
GK
7549 if (copy_r12 || ! TARGET_UPDATE)
7550 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
7551
38c1f2d7
MM
7552 if (TARGET_UPDATE)
7553 {
9ebbca7d 7554 if (size > 32767)
38c1f2d7 7555 {
9ebbca7d
GK
7556 /* Need a note here so that try_split doesn't get confused. */
7557 if (get_last_insn() == NULL_RTX)
7558 emit_note (0, NOTE_INSN_DELETED);
7559 insn = emit_move_insn (tmp_reg, todec);
7560 try_split (PATTERN (insn), insn, 0);
7561 todec = tmp_reg;
38c1f2d7 7562 }
9ebbca7d
GK
7563
7564 if (Pmode == SImode)
7565 insn = emit_insn (gen_movsi_update (stack_reg, stack_reg,
7566 todec, stack_reg));
7567 else
7568 insn = emit_insn (gen_movdi_update (stack_reg, stack_reg,
7569 todec, stack_reg));
38c1f2d7
MM
7570 }
7571 else
7572 {
9ebbca7d
GK
7573 if (Pmode == SImode)
7574 insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec));
38c1f2d7 7575 else
9ebbca7d
GK
7576 insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec));
7577 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
7578 gen_rtx_REG (Pmode, 12));
7579 }
7580
7581 RTX_FRAME_RELATED_P (insn) = 1;
7582 REG_NOTES (insn) =
7583 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7584 gen_rtx_SET (VOIDmode, stack_reg,
7585 gen_rtx_PLUS (Pmode, stack_reg,
7586 GEN_INT (-size))),
7587 REG_NOTES (insn));
7588}
7589
9aa86737
AH
7590/* Add a RTX_FRAME_RELATED note so that dwarf2out_frame_debug_expr
7591 knows that:
7592
7593 (mem (plus (blah) (regXX)))
7594
7595 is really:
7596
7597 (mem (plus (blah) (const VALUE_OF_REGXX))). */
7598
7599static void
7600altivec_frame_fixup (insn, reg, val)
7601 rtx insn, reg;
7602 HOST_WIDE_INT val;
7603{
7604 rtx real;
7605
7606 real = copy_rtx (PATTERN (insn));
7607
7608 real = replace_rtx (real, reg, GEN_INT (val));
7609
7610 RTX_FRAME_RELATED_P (insn) = 1;
7611 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7612 real,
7613 REG_NOTES (insn));
7614}
7615
a4f6c312
SS
7616/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
7617 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
7618 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
7619 deduce these equivalences by itself so it wasn't necessary to hold
7620 its hand so much. */
9ebbca7d
GK
7621
7622static void
7623rs6000_frame_related (insn, reg, val, reg2, rreg)
7624 rtx insn;
7625 rtx reg;
7626 HOST_WIDE_INT val;
7627 rtx reg2;
7628 rtx rreg;
7629{
7630 rtx real, temp;
7631
7632 real = copy_rtx (PATTERN (insn));
7633
7634 real = replace_rtx (real, reg,
7635 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
7636 STACK_POINTER_REGNUM),
7637 GEN_INT (val)));
7638
7639 /* We expect that 'real' is either a SET or a PARALLEL containing
7640 SETs (and possibly other stuff). In a PARALLEL, all the SETs
7641 are important so they all have to be marked RTX_FRAME_RELATED_P. */
7642
7643 if (GET_CODE (real) == SET)
7644 {
7645 rtx set = real;
7646
7647 temp = simplify_rtx (SET_SRC (set));
7648 if (temp)
7649 SET_SRC (set) = temp;
7650 temp = simplify_rtx (SET_DEST (set));
7651 if (temp)
7652 SET_DEST (set) = temp;
7653 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 7654 {
9ebbca7d
GK
7655 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
7656 if (temp)
7657 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 7658 }
38c1f2d7 7659 }
9ebbca7d
GK
7660 else if (GET_CODE (real) == PARALLEL)
7661 {
7662 int i;
7663 for (i = 0; i < XVECLEN (real, 0); i++)
7664 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
7665 {
7666 rtx set = XVECEXP (real, 0, i);
7667
7668 temp = simplify_rtx (SET_SRC (set));
7669 if (temp)
7670 SET_SRC (set) = temp;
7671 temp = simplify_rtx (SET_DEST (set));
7672 if (temp)
7673 SET_DEST (set) = temp;
7674 if (GET_CODE (SET_DEST (set)) == MEM)
7675 {
7676 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
7677 if (temp)
7678 XEXP (SET_DEST (set), 0) = temp;
7679 }
7680 RTX_FRAME_RELATED_P (set) = 1;
7681 }
7682 }
7683 else
a4f6c312 7684 abort ();
9ebbca7d
GK
7685
7686 if (reg2 != NULL_RTX)
7687 real = replace_rtx (real, reg2, rreg);
7688
7689 RTX_FRAME_RELATED_P (insn) = 1;
7690 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7691 real,
7692 REG_NOTES (insn));
38c1f2d7
MM
7693}
7694
00b960c7
AH
7695/* Returns an insn that has a vrsave set operation with the
7696 appropriate CLOBBERs. */
7697
7698static rtx
9aa86737 7699generate_set_vrsave (reg, info, epiloguep)
00b960c7
AH
7700 rtx reg;
7701 rs6000_stack_t *info;
9aa86737 7702 int epiloguep;
00b960c7
AH
7703{
7704 int nclobs, i;
7705 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
7706
7707 clobs[0] = gen_set_vrsave (reg);
7708
7709 nclobs = 1;
7710
9aa86737
AH
7711 /* We need to clobber the registers in the mask so the scheduler
7712 does not move sets to VRSAVE before sets of AltiVec registers.
7713
7714 However, if the function receives nonlocal gotos, reload will set
7715 all call saved registers live. We will end up with:
7716
7717 (set (reg 999) (mem))
7718 (parallel [ (set (reg vrsave) (unspec blah))
7719 (clobber (reg 999))])
7720
7721 The clobber will cause the store into reg 999 to be dead, and
7722 flow will attempt to delete an epilogue insn. In this case, we
7723 need an unspec use/set of the register. */
00b960c7
AH
7724
7725 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
7726 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
7727 {
7728 if (!epiloguep || call_used_regs [i])
7729 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
7730 gen_rtx_REG (V4SImode, i));
7731 else
7732 {
7733 rtx reg = gen_rtx_REG (V4SImode, i);
7734 rtvec r = rtvec_alloc (1);
7735
7736 RTVEC_ELT (r, 0) = reg;
7737
7738 clobs[nclobs++]
7739 = gen_rtx_SET (VOIDmode, reg, gen_rtx_UNSPEC (V4SImode, r, 27));
7740 }
7741 }
00b960c7
AH
7742
7743 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
7744
7745 for (i = 0; i < nclobs; ++i)
7746 XVECEXP (insn, 0, i) = clobs[i];
7747
7748 return insn;
7749}
7750
9ebbca7d
GK
7751/* Emit function prologue as insns. */
7752
9878760c 7753void
83720594 7754rs6000_emit_prologue ()
9878760c 7755{
4697a36c 7756 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
7757 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
7758 int reg_size = TARGET_POWERPC64 ? 8 : 4;
7759 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
7760 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
7761 rtx frame_reg_rtx = sp_reg_rtx;
7762 rtx cr_save_rtx = NULL;
7763 rtx insn;
7764 int saving_FPRs_inline;
7765 int using_store_multiple;
7766 HOST_WIDE_INT sp_offset = 0;
7767
7768 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
7769 && info->first_gp_reg_save < 31);
7770 saving_FPRs_inline = (info->first_fp_reg_save == 64
7771 || FP_SAVE_INLINE (info->first_fp_reg_save));
7772
7773 /* For V.4, update stack before we do any saving and set back pointer. */
f607bc57 7774 if (info->push_p && DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
7775 {
7776 if (info->total_size < 32767)
7777 sp_offset = info->total_size;
7778 else
7779 frame_reg_rtx = frame_ptr_rtx;
7780 rs6000_emit_allocate_stack (info->total_size,
7781 (frame_reg_rtx != sp_reg_rtx
7782 && (info->cr_save_p
7783 || info->lr_save_p
7784 || info->first_fp_reg_save < 64
7785 || info->first_gp_reg_save < 32
7786 )));
7787 if (frame_reg_rtx != sp_reg_rtx)
7788 rs6000_emit_stack_tie ();
7789 }
7790
9aa86737
AH
7791 /* Save AltiVec registers if needed. */
7792 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
7793 {
7794 int i;
7795
7796 /* There should be a non inline version of this, for when we
7797 are saving lots of vector registers. */
7798 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
7799 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
7800 {
7801 rtx areg, savereg, mem;
7802 int offset;
7803
7804 offset = info->altivec_save_offset + sp_offset
7805 + 16 * (i - info->first_altivec_reg_save);
7806
7807 savereg = gen_rtx_REG (V4SImode, i);
7808
7809 areg = gen_rtx_REG (Pmode, 0);
7810 emit_move_insn (areg, GEN_INT (offset));
7811
7812 /* AltiVec addressing mode is [reg+reg]. */
7813 mem = gen_rtx_MEM (V4SImode,
7814 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
7815
7816 set_mem_alias_set (mem, rs6000_sr_alias_set);
7817
7818 insn = emit_move_insn (mem, savereg);
7819
7820 altivec_frame_fixup (insn, areg, offset);
7821 }
7822 }
7823
7824 /* VRSAVE is a bit vector representing which AltiVec registers
7825 are used. The OS uses this to determine which vector
7826 registers to save on a context switch. We need to save
7827 VRSAVE on the stack frame, add whatever AltiVec registers we
7828 used in this function, and do the corresponding magic in the
7829 epilogue. */
7830
7831 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
7832 {
7833 rtx reg, mem;
7834 int offset;
7835
7836 /* Get VRSAVE onto a GPR. */
7837 reg = gen_rtx_REG (SImode, 12);
7838 emit_insn (gen_get_vrsave (reg));
7839
7840 /* Save VRSAVE. */
7841 offset = info->vrsave_save_offset + sp_offset;
7842 mem
7843 = gen_rtx_MEM (SImode,
7844 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
7845 set_mem_alias_set (mem, rs6000_sr_alias_set);
7846 insn = emit_move_insn (mem, reg);
7847
7848 /* Include the registers in the mask. */
7849 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
7850
7851 insn = emit_insn (generate_set_vrsave (reg, info, 0));
7852 }
7853
9ebbca7d
GK
7854 /* If we use the link register, get it into r0. */
7855 if (info->lr_save_p)
71f123ca 7856 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
7857 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
7858
7859 /* If we need to save CR, put it into r12. */
7860 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
7861 {
7862 cr_save_rtx = gen_rtx_REG (SImode, 12);
7863 emit_insn (gen_movesi_from_cr (cr_save_rtx));
7864 }
7865
a4f6c312
SS
7866 /* Do any required saving of fpr's. If only one or two to save, do
7867 it ourselves. Otherwise, call function. */
9ebbca7d
GK
7868 if (saving_FPRs_inline)
7869 {
7870 int i;
7871 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
7872 if ((regs_ever_live[info->first_fp_reg_save+i]
7873 && ! call_used_regs[info->first_fp_reg_save+i]))
7874 {
7875 rtx addr, reg, mem;
7876 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
7877 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
7878 GEN_INT (info->fp_save_offset
7879 + sp_offset
a4f6c312 7880 + 8 * i));
9ebbca7d 7881 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 7882 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7883
7884 insn = emit_move_insn (mem, reg);
7885 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
7886 NULL_RTX, NULL_RTX);
7887 }
7888 }
7889 else if (info->first_fp_reg_save != 64)
7890 {
7891 int i;
7892 char rname[30];
520a57c8 7893 const char *alloc_rname;
9ebbca7d
GK
7894 rtvec p;
7895 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
7896
7897 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
7898 gen_rtx_REG (Pmode,
7899 LINK_REGISTER_REGNUM));
7900 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
7901 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 7902 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
7903 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
7904 gen_rtx_SYMBOL_REF (Pmode,
7905 alloc_rname));
7906 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
7907 {
7908 rtx addr, reg, mem;
7909 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
7910 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
7911 GEN_INT (info->fp_save_offset
7912 + sp_offset + 8*i));
7913 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 7914 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7915
7916 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
7917 }
7918 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
7919 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
7920 NULL_RTX, NULL_RTX);
7921 }
b6c9286a 7922
9ebbca7d
GK
7923 /* Save GPRs. This is done as a PARALLEL if we are using
7924 the store-multiple instructions. */
7925 if (using_store_multiple)
b6c9286a 7926 {
9ebbca7d
GK
7927 rtvec p, dwarfp;
7928 int i;
7929 p = rtvec_alloc (32 - info->first_gp_reg_save);
7930 dwarfp = rtvec_alloc (32 - info->first_gp_reg_save);
7931 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
7932 {
7933 rtx addr, reg, mem;
7934 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
7935 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
7936 GEN_INT (info->gp_save_offset
7937 + sp_offset
7938 + reg_size * i));
7939 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 7940 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7941
7942 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
7943 }
7944 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
7945 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
7946 NULL_RTX, NULL_RTX);
b6c9286a
MM
7947 }
7948 else
7949 {
9ebbca7d
GK
7950 int i;
7951 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
7952 if ((regs_ever_live[info->first_gp_reg_save+i]
7953 && ! call_used_regs[info->first_gp_reg_save+i])
7954 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
7955 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
7956 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
7957 {
7958 rtx addr, reg, mem;
7959 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
7960 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
7961 GEN_INT (info->gp_save_offset
7962 + sp_offset
7963 + reg_size * i));
7964 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 7965 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
7966
7967 insn = emit_move_insn (mem, reg);
7968 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
7969 NULL_RTX, NULL_RTX);
7970 }
7971 }
7972
83720594
RH
7973 /* ??? There's no need to emit actual instructions here, but it's the
7974 easiest way to get the frame unwind information emitted. */
7975 if (current_function_calls_eh_return)
7976 {
78e1b90d
DE
7977 unsigned int i, regno;
7978
83720594
RH
7979 for (i = 0; ; ++i)
7980 {
7981 rtx addr, reg, mem;
7982
7983 regno = EH_RETURN_DATA_REGNO (i);
7984 if (regno == INVALID_REGNUM)
7985 break;
7986
7987 reg = gen_rtx_REG (reg_mode, regno);
7988 addr = plus_constant (frame_reg_rtx,
78e1b90d
DE
7989 info->ehrd_offset + sp_offset
7990 + reg_size * (int) i);
83720594 7991 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 7992 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
7993
7994 insn = emit_move_insn (mem, reg);
7995 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
7996 NULL_RTX, NULL_RTX);
7997 }
7998 }
7999
9ebbca7d
GK
8000 /* Save lr if we used it. */
8001 if (info->lr_save_p)
8002 {
8003 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8004 GEN_INT (info->lr_save_offset + sp_offset));
8005 rtx reg = gen_rtx_REG (Pmode, 0);
8006 rtx mem = gen_rtx_MEM (Pmode, addr);
8007 /* This should not be of rs6000_sr_alias_set, because of
8008 __builtin_return_address. */
8009
8010 insn = emit_move_insn (mem, reg);
8011 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
8012 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
8013 }
8014
8015 /* Save CR if we use any that must be preserved. */
8016 if (info->cr_save_p)
8017 {
8018 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8019 GEN_INT (info->cr_save_offset + sp_offset));
8020 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
8021
8022 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
8023
8024 /* If r12 was used to hold the original sp, copy cr into r0 now
8025 that it's free. */
8026 if (REGNO (frame_reg_rtx) == 12)
8027 {
8028 cr_save_rtx = gen_rtx_REG (SImode, 0);
8029 emit_insn (gen_movesi_from_cr (cr_save_rtx));
8030 }
8031 insn = emit_move_insn (mem, cr_save_rtx);
8032
8033 /* Now, there's no way that dwarf2out_frame_debug_expr is going
8034 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
8035 OK. All we have to do is specify that _one_ condition code
8036 register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
8037 will then restore all the call-saved registers.
8038 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 8039 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 8040 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
8041 }
8042
8043 /* Update stack and set back pointer unless this is V.4,
8044 for which it was done previously. */
f607bc57 8045 if (info->push_p && DEFAULT_ABI != ABI_V4)
9ebbca7d
GK
8046 rs6000_emit_allocate_stack (info->total_size, FALSE);
8047
8048 /* Set frame pointer, if needed. */
8049 if (frame_pointer_needed)
8050 {
8051 insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM),
8052 sp_reg_rtx);
8053 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 8054 }
9878760c 8055
9ebbca7d
GK
8056 /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
8057 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57
ZW
8058 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
8059 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
8060 {
8061 /* If emit_load_toc_table will use the link register, we need to save
8062 it. We use R11 for this purpose because emit_load_toc_table
8063 can use register 0. This allows us to use a plain 'blr' to return
8064 from the procedure more often. */
d5fa86ba
GK
8065 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0
8066 && ! info->lr_save_p
8067 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d
GK
8068 if (save_LR_around_toc_setup)
8069 emit_move_insn (gen_rtx_REG (Pmode, 11),
8070 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
8071
8072 rs6000_emit_load_toc_table (TRUE);
8073
8074 if (save_LR_around_toc_setup)
8075 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
8076 gen_rtx_REG (Pmode, 11));
8077 }
ee890fe2
SS
8078
8079 if (DEFAULT_ABI == ABI_DARWIN
8080 && flag_pic && current_function_uses_pic_offset_table)
8081 {
8082 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
8083
8084 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest)));
8085
8086 rs6000_maybe_dead (
8087 emit_move_insn (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM),
8088 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
8089 }
9ebbca7d
GK
8090}
8091
9ebbca7d 8092/* Write function prologue. */
a4f6c312 8093
08c148a8
NB
8094static void
8095rs6000_output_function_prologue (file, size)
9ebbca7d 8096 FILE *file;
08c148a8 8097 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9ebbca7d
GK
8098{
8099 rs6000_stack_t *info = rs6000_stack_info ();
8100
4697a36c
MM
8101 if (TARGET_DEBUG_STACK)
8102 debug_stack_info (info);
9878760c 8103
a4f6c312
SS
8104 /* Write .extern for any function we will call to save and restore
8105 fp values. */
8106 if (info->first_fp_reg_save < 64
8107 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 8108 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 8109 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
8110 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
8111 RESTORE_FP_SUFFIX);
9878760c 8112
c764f757
RK
8113 /* Write .extern for AIX common mode routines, if needed. */
8114 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
8115 {
f6709c70
JW
8116 fputs ("\t.extern __mulh\n", file);
8117 fputs ("\t.extern __mull\n", file);
8118 fputs ("\t.extern __divss\n", file);
8119 fputs ("\t.extern __divus\n", file);
8120 fputs ("\t.extern __quoss\n", file);
8121 fputs ("\t.extern __quous\n", file);
c764f757
RK
8122 common_mode_defined = 1;
8123 }
9878760c 8124
9ebbca7d 8125 if (! HAVE_prologue)
979721f8 8126 {
9ebbca7d
GK
8127 start_sequence ();
8128
a4f6c312
SS
8129 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
8130 the "toplevel" insn chain. */
9ebbca7d
GK
8131 emit_note (0, NOTE_INSN_DELETED);
8132 rs6000_emit_prologue ();
8133 emit_note (0, NOTE_INSN_DELETED);
8134
8135 if (TARGET_DEBUG_STACK)
a4f6c312
SS
8136 debug_rtx_list (get_insns (), 100);
8137 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 8138 end_sequence ();
979721f8
MM
8139 }
8140
9ebbca7d
GK
8141 rs6000_pic_labelno++;
8142}
8143
8144/* Emit function epilogue as insns.
9878760c 8145
9ebbca7d
GK
8146 At present, dwarf2out_frame_debug_expr doesn't understand
8147 register restores, so we don't bother setting RTX_FRAME_RELATED_P
8148 anywhere in the epilogue. Most of the insns below would in any case
8149 need special notes to explain where r11 is in relation to the stack. */
9878760c 8150
9ebbca7d 8151void
83720594 8152rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
8153 int sibcall;
8154{
8155 rs6000_stack_t *info;
8156 int restoring_FPRs_inline;
8157 int using_load_multiple;
8158 int using_mfcr_multiple;
8159 int use_backchain_to_restore_sp;
8160 int sp_offset = 0;
8161 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
8162 rtx frame_reg_rtx = sp_reg_rtx;
8163 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
8164 int reg_size = TARGET_POWERPC64 ? 8 : 4;
8165 int i;
8166
8167 info = rs6000_stack_info ();
8168 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
8169 && info->first_gp_reg_save < 31);
8170 restoring_FPRs_inline = (sibcall
83720594 8171 || current_function_calls_eh_return
9ebbca7d
GK
8172 || info->first_fp_reg_save == 64
8173 || FP_SAVE_INLINE (info->first_fp_reg_save));
8174 use_backchain_to_restore_sp = (frame_pointer_needed
8175 || current_function_calls_alloca
8176 || info->total_size > 32767);
8177 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
8178 || rs6000_cpu == PROCESSOR_PPC603
8179 || rs6000_cpu == PROCESSOR_PPC750
8180 || optimize_size);
8181
8182 /* If we have a frame pointer, a call to alloca, or a large stack
8183 frame, restore the old stack pointer using the backchain. Otherwise,
8184 we know what size to update it with. */
8185 if (use_backchain_to_restore_sp)
bacbde18 8186 {
9ebbca7d
GK
8187 /* Under V.4, don't reset the stack pointer until after we're done
8188 loading the saved registers. */
f607bc57 8189 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 8190 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 8191
9ebbca7d
GK
8192 emit_move_insn (frame_reg_rtx,
8193 gen_rtx_MEM (Pmode, sp_reg_rtx));
8194
bacbde18 8195 }
9ebbca7d 8196 else if (info->push_p)
85638c0d 8197 {
f607bc57 8198 if (DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
8199 sp_offset = info->total_size;
8200 else
8201 {
8202 emit_insn (TARGET_32BIT
8203 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
8204 GEN_INT (info->total_size))
8205 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
8206 GEN_INT (info->total_size)));
8207 }
85638c0d 8208 }
9ebbca7d 8209
9aa86737
AH
8210 /* Restore AltiVec registers if needed. */
8211 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
8212 {
8213 int i;
8214
8215 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
8216 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
8217 {
8218 rtx addr, areg, mem;
8219
8220 areg = gen_rtx_REG (Pmode, 0);
8221 emit_move_insn
8222 (areg, GEN_INT (info->altivec_save_offset
8223 + sp_offset
8224 + 16 * (i - info->first_altivec_reg_save)));
8225
8226 /* AltiVec addressing mode is [reg+reg]. */
8227 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
8228 mem = gen_rtx_MEM (V4SImode, addr);
8229 set_mem_alias_set (mem, rs6000_sr_alias_set);
8230
8231 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
8232 }
8233 }
8234
8235 /* Restore VRSAVE if needed. */
8236 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
8237 {
8238 rtx addr, mem, reg;
8239
8240 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8241 GEN_INT (info->vrsave_save_offset + sp_offset));
8242 mem = gen_rtx_MEM (SImode, addr);
8243 set_mem_alias_set (mem, rs6000_sr_alias_set);
8244 reg = gen_rtx_REG (SImode, 12);
8245 emit_move_insn (reg, mem);
8246
8247 emit_insn (generate_set_vrsave (reg, info, 1));
8248 }
8249
9ebbca7d
GK
8250 /* Get the old lr if we saved it. */
8251 if (info->lr_save_p)
b6c9286a 8252 {
9ebbca7d
GK
8253 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8254 GEN_INT (info->lr_save_offset + sp_offset));
8255 rtx mem = gen_rtx_MEM (Pmode, addr);
ba4828e0
RK
8256
8257 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 8258
9ebbca7d 8259 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 8260 }
9ebbca7d
GK
8261
8262 /* Get the old cr if we saved it. */
8263 if (info->cr_save_p)
8264 {
8265 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8266 GEN_INT (info->cr_save_offset + sp_offset));
8267 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
8268
8269 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 8270
9ebbca7d
GK
8271 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
8272 }
8273
8274 /* Set LR here to try to overlap restores below. */
4697a36c 8275 if (info->lr_save_p)
9ebbca7d
GK
8276 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
8277 gen_rtx_REG (Pmode, 0));
8278
83720594
RH
8279 /* Load exception handler data registers, if needed. */
8280 if (current_function_calls_eh_return)
8281 {
78e1b90d
DE
8282 unsigned int i, regno;
8283
83720594
RH
8284 for (i = 0; ; ++i)
8285 {
8286 rtx addr, mem;
8287
8288 regno = EH_RETURN_DATA_REGNO (i);
8289 if (regno == INVALID_REGNUM)
8290 break;
8291
8292 addr = plus_constant (frame_reg_rtx,
78e1b90d
DE
8293 info->ehrd_offset + sp_offset
8294 + reg_size * (int) i);
83720594 8295 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 8296 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
8297
8298 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
8299 }
8300 }
9ebbca7d
GK
8301
8302 /* Restore GPRs. This is done as a PARALLEL if we are using
8303 the load-multiple instructions. */
8304 if (using_load_multiple)
979721f8 8305 {
9ebbca7d
GK
8306 rtvec p;
8307 p = rtvec_alloc (32 - info->first_gp_reg_save);
8308 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 8309 {
9ebbca7d
GK
8310 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8311 GEN_INT (info->gp_save_offset
8312 + sp_offset
8313 + reg_size * i));
8314 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
8315
8316 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
8317
8318 RTVEC_ELT (p, i) =
8319 gen_rtx_SET (VOIDmode,
8320 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
8321 mem);
979721f8 8322 }
9ebbca7d 8323 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 8324 }
9ebbca7d
GK
8325 else
8326 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
8327 if ((regs_ever_live[info->first_gp_reg_save+i]
8328 && ! call_used_regs[info->first_gp_reg_save+i])
8329 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
8330 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
8331 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
8332 {
8333 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8334 GEN_INT (info->gp_save_offset
8335 + sp_offset
8336 + reg_size * i));
8337 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
8338
8339 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
8340
8341 emit_move_insn (gen_rtx_REG (reg_mode,
8342 info->first_gp_reg_save + i),
8343 mem);
8344 }
9878760c 8345
9ebbca7d
GK
8346 /* Restore fpr's if we need to do it without calling a function. */
8347 if (restoring_FPRs_inline)
8348 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
8349 if ((regs_ever_live[info->first_fp_reg_save+i]
8350 && ! call_used_regs[info->first_fp_reg_save+i]))
8351 {
8352 rtx addr, mem;
8353 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
8354 GEN_INT (info->fp_save_offset
8355 + sp_offset
a4f6c312 8356 + 8 * i));
9ebbca7d 8357 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 8358 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
8359
8360 emit_move_insn (gen_rtx_REG (DFmode,
8361 info->first_fp_reg_save + i),
8362 mem);
8363 }
8d30c4ee 8364
9ebbca7d
GK
8365 /* If we saved cr, restore it here. Just those that were used. */
8366 if (info->cr_save_p)
979721f8 8367 {
9ebbca7d 8368 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 8369 int count = 0;
9ebbca7d
GK
8370
8371 if (using_mfcr_multiple)
979721f8 8372 {
9ebbca7d
GK
8373 for (i = 0; i < 8; i++)
8374 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 8375 count++;
9ebbca7d 8376 if (count == 0)
e35b9579
GK
8377 abort ();
8378 }
8379
8380 if (using_mfcr_multiple && count > 1)
8381 {
8382 rtvec p;
8383 int ndx;
9ebbca7d 8384
e35b9579 8385 p = rtvec_alloc (count);
9ebbca7d 8386
e35b9579 8387 ndx = 0;
9ebbca7d
GK
8388 for (i = 0; i < 8; i++)
8389 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
8390 {
8391 rtvec r = rtvec_alloc (2);
8392 RTVEC_ELT (r, 0) = r12_rtx;
8393 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 8394 RTVEC_ELT (p, ndx) =
9ebbca7d
GK
8395 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
8396 gen_rtx_UNSPEC (CCmode, r, 20));
e35b9579 8397 ndx++;
9ebbca7d
GK
8398 }
8399 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
8400 if (ndx != count)
8401 abort ();
979721f8
MM
8402 }
8403 else
9ebbca7d
GK
8404 for (i = 0; i < 8; i++)
8405 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 8406 {
9ebbca7d
GK
8407 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
8408 CR0_REGNO+i),
8409 r12_rtx));
979721f8 8410 }
979721f8
MM
8411 }
8412
9ebbca7d
GK
8413 /* If this is V.4, unwind the stack pointer after all of the loads
8414 have been done. We need to emit a block here so that sched
8415 doesn't decide to move the sp change before the register restores
8416 (which may not have any obvious dependency on the stack). This
8417 doesn't hurt performance, because there is no scheduling that can
8418 be done after this point. */
f607bc57 8419 if (DEFAULT_ABI == ABI_V4)
b6c9286a 8420 {
9ebbca7d
GK
8421 if (frame_reg_rtx != sp_reg_rtx)
8422 rs6000_emit_stack_tie ();
b6c9286a 8423
9ebbca7d 8424 if (use_backchain_to_restore_sp)
b6c9286a 8425 {
9ebbca7d 8426 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 8427 }
9ebbca7d 8428 else if (sp_offset != 0)
13f1623b 8429 {
9ebbca7d
GK
8430 emit_insn (Pmode == SImode
8431 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
8432 GEN_INT (sp_offset))
8433 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
8434 GEN_INT (sp_offset)));
13f1623b 8435 }
9ebbca7d 8436 }
b6c9286a 8437
83720594
RH
8438 if (current_function_calls_eh_return)
8439 {
8440 rtx sa = EH_RETURN_STACKADJ_RTX;
8441 emit_insn (Pmode == SImode
8442 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
8443 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
8444 }
8445
9ebbca7d
GK
8446 if (!sibcall)
8447 {
8448 rtvec p;
8449 if (! restoring_FPRs_inline)
8450 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
8451 else
8452 p = rtvec_alloc (2);
b6c9286a 8453
e35b9579
GK
8454 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
8455 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
8456 gen_rtx_REG (Pmode,
8457 LINK_REGISTER_REGNUM));
9ebbca7d
GK
8458
8459 /* If we have to restore more than two FP registers, branch to the
8460 restore function. It will return to our caller. */
8461 if (! restoring_FPRs_inline)
8462 {
8463 int i;
8464 char rname[30];
520a57c8 8465 const char *alloc_rname;
979721f8 8466
9ebbca7d
GK
8467 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
8468 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 8469 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
8470 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
8471 gen_rtx_SYMBOL_REF (Pmode,
8472 alloc_rname));
b6c9286a 8473
9ebbca7d
GK
8474 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
8475 {
8476 rtx addr, mem;
8477 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
8478 GEN_INT (info->fp_save_offset + 8*i));
8479 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 8480 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
8481
8482 RTVEC_ELT (p, i+3) =
8483 gen_rtx_SET (VOIDmode,
8484 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
8485 mem);
b6c9286a
MM
8486 }
8487 }
9ebbca7d
GK
8488
8489 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 8490 }
9878760c
RK
8491}
8492
8493/* Write function epilogue. */
8494
08c148a8
NB
8495static void
8496rs6000_output_function_epilogue (file, size)
9878760c 8497 FILE *file;
08c148a8 8498 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9878760c 8499{
4697a36c 8500 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 8501
9ebbca7d 8502 if (! HAVE_epilogue)
9878760c 8503 {
9ebbca7d
GK
8504 rtx insn = get_last_insn ();
8505 /* If the last insn was a BARRIER, we don't have to write anything except
8506 the trace table. */
8507 if (GET_CODE (insn) == NOTE)
8508 insn = prev_nonnote_insn (insn);
8509 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 8510 {
9ebbca7d
GK
8511 /* This is slightly ugly, but at least we don't have two
8512 copies of the epilogue-emitting code. */
8513 start_sequence ();
8514
8515 /* A NOTE_INSN_DELETED is supposed to be at the start
8516 and end of the "toplevel" insn chain. */
8517 emit_note (0, NOTE_INSN_DELETED);
8518 rs6000_emit_epilogue (FALSE);
8519 emit_note (0, NOTE_INSN_DELETED);
8520
8521 if (TARGET_DEBUG_STACK)
a4f6c312
SS
8522 debug_rtx_list (get_insns (), 100);
8523 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 8524 end_sequence ();
4697a36c 8525 }
9878760c 8526 }
b4ac57ab 8527
9b30bae2 8528 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
8529 on its format.
8530
8531 We don't output a traceback table if -finhibit-size-directive was
8532 used. The documentation for -finhibit-size-directive reads
8533 ``don't output a @code{.size} assembler directive, or anything
8534 else that would cause trouble if the function is split in the
8535 middle, and the two halves are placed at locations far apart in
8536 memory.'' The traceback table has this property, since it
8537 includes the offset from the start of the function to the
4d30c363
MM
8538 traceback table itself.
8539
8540 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a
MM
8541 different traceback table. */
8542 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
9b30bae2 8543 {
3cce094d 8544 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3ac88239 8545 const char *language_string = lang_hooks.name;
314fc5a9
ILT
8546 int fixed_parms, float_parms, parm_info;
8547 int i;
8548
b6c9286a
MM
8549 while (*fname == '.') /* V.4 encodes . in the name */
8550 fname++;
8551
314fc5a9
ILT
8552 /* Need label immediately before tbtab, so we can compute its offset
8553 from the function start. */
8554 if (*fname == '*')
8555 ++fname;
8556 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
8557 ASM_OUTPUT_LABEL (file, fname);
8558
8559 /* The .tbtab pseudo-op can only be used for the first eight
8560 expressions, since it can't handle the possibly variable
8561 length fields that follow. However, if you omit the optional
8562 fields, the assembler outputs zeros for all optional fields
8563 anyways, giving each variable length field is minimum length
8564 (as defined in sys/debug.h). Thus we can not use the .tbtab
8565 pseudo-op at all. */
8566
8567 /* An all-zero word flags the start of the tbtab, for debuggers
8568 that have to find it by searching forward from the entry
8569 point or from the current pc. */
19d2d16f 8570 fputs ("\t.long 0\n", file);
314fc5a9
ILT
8571
8572 /* Tbtab format type. Use format type 0. */
19d2d16f 8573 fputs ("\t.byte 0,", file);
314fc5a9
ILT
8574
8575 /* Language type. Unfortunately, there doesn't seem to be any
8576 official way to get this info, so we use language_string. C
8577 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 8578 value for C for now. There is no official value for Java,
6f573ff9 8579 although IBM appears to be using 13. There is no official value
f710504c 8580 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 8581 if (! strcmp (language_string, "GNU C")
e2c953b6 8582 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
8583 i = 0;
8584 else if (! strcmp (language_string, "GNU F77"))
8585 i = 1;
8586 else if (! strcmp (language_string, "GNU Ada"))
8587 i = 3;
8b83775b 8588 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
8589 i = 2;
8590 else if (! strcmp (language_string, "GNU C++"))
8591 i = 9;
9517ead8
AG
8592 else if (! strcmp (language_string, "GNU Java"))
8593 i = 13;
6f573ff9
JL
8594 else if (! strcmp (language_string, "GNU CHILL"))
8595 i = 44;
314fc5a9
ILT
8596 else
8597 abort ();
8598 fprintf (file, "%d,", i);
8599
8600 /* 8 single bit fields: global linkage (not set for C extern linkage,
8601 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
8602 from start of procedure stored in tbtab, internal function, function
8603 has controlled storage, function has no toc, function uses fp,
8604 function logs/aborts fp operations. */
8605 /* Assume that fp operations are used if any fp reg must be saved. */
4697a36c 8606 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
8607
8608 /* 6 bitfields: function is interrupt handler, name present in
8609 proc table, function calls alloca, on condition directives
8610 (controls stack walks, 3 bits), saves condition reg, saves
8611 link reg. */
8612 /* The `function calls alloca' bit seems to be set whenever reg 31 is
8613 set up as a frame pointer, even when there is no alloca call. */
8614 fprintf (file, "%d,",
8615 ((1 << 6) | (frame_pointer_needed << 5)
4697a36c 8616 | (info->cr_save_p << 1) | (info->lr_save_p)));
314fc5a9
ILT
8617
8618 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
8619 (6 bits). */
8620 fprintf (file, "%d,",
4697a36c 8621 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
8622
8623 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
8624 fprintf (file, "%d,", (32 - first_reg_to_save ()));
8625
8626 {
8627 /* Compute the parameter info from the function decl argument
8628 list. */
8629 tree decl;
8630 int next_parm_info_bit;
8631
8632 next_parm_info_bit = 31;
8633 parm_info = 0;
8634 fixed_parms = 0;
8635 float_parms = 0;
8636
8637 for (decl = DECL_ARGUMENTS (current_function_decl);
8638 decl; decl = TREE_CHAIN (decl))
8639 {
8640 rtx parameter = DECL_INCOMING_RTL (decl);
8641 enum machine_mode mode = GET_MODE (parameter);
8642
8643 if (GET_CODE (parameter) == REG)
8644 {
8645 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8646 {
8647 int bits;
8648
8649 float_parms++;
8650
8651 if (mode == SFmode)
8652 bits = 0x2;
8653 else if (mode == DFmode)
8654 bits = 0x3;
8655 else
8656 abort ();
8657
8658 /* If only one bit will fit, don't or in this entry. */
8659 if (next_parm_info_bit > 0)
8660 parm_info |= (bits << (next_parm_info_bit - 1));
8661 next_parm_info_bit -= 2;
8662 }
8663 else
8664 {
8665 fixed_parms += ((GET_MODE_SIZE (mode)
8666 + (UNITS_PER_WORD - 1))
8667 / UNITS_PER_WORD);
8668 next_parm_info_bit -= 1;
8669 }
8670 }
8671 }
8672 }
8673
8674 /* Number of fixed point parameters. */
8675 /* This is actually the number of words of fixed point parameters; thus
8676 an 8 byte struct counts as 2; and thus the maximum value is 8. */
8677 fprintf (file, "%d,", fixed_parms);
8678
8679 /* 2 bitfields: number of floating point parameters (7 bits), parameters
8680 all on stack. */
8681 /* This is actually the number of fp registers that hold parameters;
8682 and thus the maximum value is 13. */
8683 /* Set parameters on stack bit if parameters are not in their original
8684 registers, regardless of whether they are on the stack? Xlc
8685 seems to set the bit when not optimizing. */
8686 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
8687
8688 /* Optional fields follow. Some are variable length. */
8689
8690 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
8691 11 double float. */
8692 /* There is an entry for each parameter in a register, in the order that
8693 they occur in the parameter list. Any intervening arguments on the
8694 stack are ignored. If the list overflows a long (max possible length
8695 34 bits) then completely leave off all elements that don't fit. */
8696 /* Only emit this long if there was at least one parameter. */
8697 if (fixed_parms || float_parms)
8698 fprintf (file, "\t.long %d\n", parm_info);
8699
8700 /* Offset from start of code to tb table. */
19d2d16f 8701 fputs ("\t.long ", file);
314fc5a9 8702 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
8703#if TARGET_AIX
8704 RS6000_OUTPUT_BASENAME (file, fname);
8705#else
9ebbca7d 8706 assemble_name (file, fname);
54ee9799 8707#endif
19d2d16f 8708 fputs ("-.", file);
54ee9799
DE
8709#if TARGET_AIX
8710 RS6000_OUTPUT_BASENAME (file, fname);
8711#else
9ebbca7d 8712 assemble_name (file, fname);
54ee9799 8713#endif
19d2d16f 8714 putc ('\n', file);
314fc5a9
ILT
8715
8716 /* Interrupt handler mask. */
8717 /* Omit this long, since we never set the interrupt handler bit
8718 above. */
8719
8720 /* Number of CTL (controlled storage) anchors. */
8721 /* Omit this long, since the has_ctl bit is never set above. */
8722
8723 /* Displacement into stack of each CTL anchor. */
8724 /* Omit this list of longs, because there are no CTL anchors. */
8725
8726 /* Length of function name. */
296b8152 8727 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
8728
8729 /* Function name. */
8730 assemble_string (fname, strlen (fname));
8731
8732 /* Register for alloca automatic storage; this is always reg 31.
8733 Only emit this if the alloca bit was set above. */
8734 if (frame_pointer_needed)
19d2d16f 8735 fputs ("\t.byte 31\n", file);
9b30bae2 8736 }
9878760c 8737}
17167fd8 8738\f
a4f6c312
SS
8739/* A C compound statement that outputs the assembler code for a thunk
8740 function, used to implement C++ virtual function calls with
8741 multiple inheritance. The thunk acts as a wrapper around a virtual
8742 function, adjusting the implicit object parameter before handing
8743 control off to the real function.
8744
8745 First, emit code to add the integer DELTA to the location that
8746 contains the incoming first argument. Assume that this argument
8747 contains a pointer, and is the one used to pass the `this' pointer
8748 in C++. This is the incoming argument *before* the function
8749 prologue, e.g. `%o0' on a sparc. The addition must preserve the
8750 values of all other incoming arguments.
17167fd8
MM
8751
8752 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
8753 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
8754 not touch the return address. Hence returning from FUNCTION will
8755 return to whoever called the current `thunk'.
17167fd8 8756
a4f6c312
SS
8757 The effect must be as if FUNCTION had been called directly with the
8758 adjusted first argument. This macro is responsible for emitting
8759 all of the code for a thunk function; output_function_prologue()
8760 and output_function_epilogue() are not invoked.
17167fd8 8761
a4f6c312
SS
8762 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
8763 been extracted from it.) It might possibly be useful on some
8764 targets, but probably not.
17167fd8 8765
a4f6c312
SS
8766 If you do not define this macro, the target-independent code in the
8767 C++ frontend will generate a less efficient heavyweight thunk that
8768 calls FUNCTION instead of jumping to it. The generic approach does
8769 not support varargs. */
17167fd8
MM
8770
8771void
8772output_mi_thunk (file, thunk_fndecl, delta, function)
8773 FILE *file;
d330fd93 8774 tree thunk_fndecl ATTRIBUTE_UNUSED;
17167fd8
MM
8775 int delta;
8776 tree function;
8777{
a4f6c312
SS
8778 const char *this_reg =
8779 reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
d330fd93 8780 const char *prefix;
3cce094d 8781 const char *fname;
d330fd93 8782 const char *r0 = reg_names[0];
d330fd93
KG
8783 const char *toc = reg_names[2];
8784 const char *schain = reg_names[11];
8785 const char *r12 = reg_names[12];
17167fd8
MM
8786 char buf[512];
8787 static int labelno = 0;
8788
a4f6c312 8789 /* Small constants that can be done by one add instruction. */
17167fd8
MM
8790 if (delta >= -32768 && delta <= 32767)
8791 {
22b4a3b0 8792 if (! TARGET_NEW_MNEMONICS)
17167fd8
MM
8793 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
8794 else
8795 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
8796 }
8797
a4f6c312 8798 /* Large constants that can be done by one addis instruction. */
17167fd8
MM
8799 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
8800 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
8801 delta >> 16);
8802
8803 /* 32-bit constants that can be done by an add and addis instruction. */
8804 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
8805 {
a4f6c312
SS
8806 /* Break into two pieces, propagating the sign bit from the low
8807 word to the upper word. */
17167fd8
MM
8808 int delta_high = delta >> 16;
8809 int delta_low = delta & 0xffff;
8810 if ((delta_low & 0x8000) != 0)
8811 {
8812 delta_high++;
8813 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
8814 }
8815
8816 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
8817 delta_high);
8818
22b4a3b0 8819 if (! TARGET_NEW_MNEMONICS)
17167fd8
MM
8820 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
8821 else
8822 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
8823 }
8824
8825 /* 64-bit constants, fixme */
8826 else
8827 abort ();
8828
8829 /* Get the prefix in front of the names. */
8830 switch (DEFAULT_ABI)
8831 {
8832 default:
8833 abort ();
8834
8835 case ABI_AIX:
8836 prefix = ".";
8837 break;
8838
8839 case ABI_V4:
8840 case ABI_AIX_NODESC:
17167fd8
MM
8841 prefix = "";
8842 break;
17167fd8
MM
8843 }
8844
8845 /* If the function is compiled in this module, jump to it directly.
8846 Otherwise, load up its address and jump to it. */
8847
8848 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
42820a49 8849
9ebbca7d 8850 if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode)
22b4a3b0
FS
8851 && ! lookup_attribute ("longcall",
8852 TYPE_ATTRIBUTES (TREE_TYPE (function))))
17167fd8
MM
8853 {
8854 fprintf (file, "\tb %s", prefix);
8855 assemble_name (file, fname);
22b4a3b0 8856 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
949ea356 8857 putc ('\n', file);
17167fd8
MM
8858 }
8859
8860 else
8861 {
8862 switch (DEFAULT_ABI)
8863 {
8864 default:
17167fd8
MM
8865 abort ();
8866
8867 case ABI_AIX:
8868 /* Set up a TOC entry for the function. */
8869 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
8870 toc_section ();
8871 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
8872 labelno++;
8873
fa9b5c6b
DE
8874 if (TARGET_MINIMAL_TOC)
8875 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
8876 else
8877 {
8878 fputs ("\t.tc ", file);
8879 assemble_name (file, fname);
8880 fputs ("[TC],", file);
8881 }
8882 assemble_name (file, fname);
17167fd8
MM
8883 putc ('\n', file);
8884 text_section ();
468e8dba
DE
8885 if (TARGET_MINIMAL_TOC)
8886 asm_fprintf (file, (TARGET_32BIT)
8887 ? "\t{l|lwz} %s,%s(%s)\n" : "\tld %s,%s(%s)\n", r12,
8888 TARGET_ELF ? ".LCTOC0@toc" : ".LCTOC..1", toc);
d2574c50 8889 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s,", r12);
17167fd8 8890 assemble_name (file, buf);
468e8dba
DE
8891 if (TARGET_ELF && TARGET_MINIMAL_TOC)
8892 fputs ("-(.LCTOC1)", file);
8893 asm_fprintf (file, "(%s)\n", TARGET_MINIMAL_TOC ? r12 : toc);
17167fd8
MM
8894 asm_fprintf (file,
8895 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
8896 r0, r12);
8897
8898 asm_fprintf (file,
8899 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
8900 toc, r12);
8901
8902 asm_fprintf (file, "\tmtctr %s\n", r0);
8903 asm_fprintf (file,
8904 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
8905 schain, r12);
8906
8907 asm_fprintf (file, "\tbctr\n");
8908 break;
8909
9ebbca7d 8910 case ABI_AIX_NODESC:
17167fd8 8911 case ABI_V4:
22b4a3b0
FS
8912 fprintf (file, "\tb %s", prefix);
8913 assemble_name (file, fname);
8914 if (flag_pic) fputs ("@plt", file);
949ea356 8915 putc ('\n', file);
22b4a3b0 8916 break;
ee890fe2
SS
8917
8918#if TARGET_MACHO
8919 case ABI_DARWIN:
8920 fprintf (file, "\tb %s", prefix);
8921 if (flag_pic && !machopic_name_defined_p (fname))
8922 assemble_name (file, machopic_stub_name (fname));
8923 else
8924 assemble_name (file, fname);
8925 putc ('\n', file);
8926 break;
8927#endif
9ebbca7d
GK
8928 }
8929 }
8930}
42820a49 8931
9ebbca7d
GK
8932\f
8933/* A quick summary of the various types of 'constant-pool tables'
8934 under PowerPC:
8935
8936 Target Flags Name One table per
8937 AIX (none) AIX TOC object file
8938 AIX -mfull-toc AIX TOC object file
8939 AIX -mminimal-toc AIX minimal TOC translation unit
8940 SVR4/EABI (none) SVR4 SDATA object file
8941 SVR4/EABI -fpic SVR4 pic object file
8942 SVR4/EABI -fPIC SVR4 PIC translation unit
8943 SVR4/EABI -mrelocatable EABI TOC function
8944 SVR4/EABI -maix AIX TOC object file
8945 SVR4/EABI -maix -mminimal-toc
8946 AIX minimal TOC translation unit
8947
8948 Name Reg. Set by entries contains:
8949 made by addrs? fp? sum?
8950
8951 AIX TOC 2 crt0 as Y option option
8952 AIX minimal TOC 30 prolog gcc Y Y option
8953 SVR4 SDATA 13 crt0 gcc N Y N
8954 SVR4 pic 30 prolog ld Y not yet N
8955 SVR4 PIC 30 prolog gcc Y option option
8956 EABI TOC 30 prolog gcc Y option option
8957
8958*/
8959
8960/* Hash table stuff for keeping track of TOC entries. */
8961
8962struct toc_hash_struct
8963{
8964 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
8965 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
8966 rtx key;
a9098fd0 8967 enum machine_mode key_mode;
9ebbca7d
GK
8968 int labelno;
8969};
17167fd8 8970
9ebbca7d
GK
8971static htab_t toc_hash_table;
8972
8973/* Hash functions for the hash table. */
8974
8975static unsigned
8976rs6000_hash_constant (k)
8977 rtx k;
8978{
a9098fd0 8979 unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k);
9ebbca7d
GK
8980 const char *format = GET_RTX_FORMAT (GET_CODE (k));
8981 int flen = strlen (format);
8982 int fidx;
8983
8984 if (GET_CODE (k) == LABEL_REF)
832ea3b3 8985 return result * 1231 + X0INT (XEXP (k, 0), 3);
9ebbca7d
GK
8986
8987 if (GET_CODE (k) == CONST_DOUBLE)
592bf28c 8988 fidx = 1;
9ebbca7d
GK
8989 else if (GET_CODE (k) == CODE_LABEL)
8990 fidx = 3;
8991 else
8992 fidx = 0;
8993
8994 for (; fidx < flen; fidx++)
8995 switch (format[fidx])
8996 {
8997 case 's':
8998 {
8999 unsigned i, len;
9000 const char *str = XSTR (k, fidx);
9001 len = strlen (str);
9002 result = result * 613 + len;
9003 for (i = 0; i < len; i++)
9004 result = result * 613 + (unsigned) str[i];
17167fd8
MM
9005 break;
9006 }
9ebbca7d
GK
9007 case 'u':
9008 case 'e':
9009 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
9010 break;
9011 case 'i':
9012 case 'n':
9013 result = result * 613 + (unsigned) XINT (k, fidx);
9014 break;
9015 case 'w':
9016 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
9017 result = result * 613 + (unsigned) XWINT (k, fidx);
9018 else
9019 {
9020 size_t i;
9021 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
9022 result = result * 613 + (unsigned) (XWINT (k, fidx)
9023 >> CHAR_BIT * i);
9024 }
9025 break;
9026 default:
a4f6c312 9027 abort ();
9ebbca7d
GK
9028 }
9029 return result;
9030}
9031
9032static unsigned
9033toc_hash_function (hash_entry)
9034 const void * hash_entry;
9035{
a9098fd0
GK
9036 const struct toc_hash_struct *thc =
9037 (const struct toc_hash_struct *) hash_entry;
9038 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
9039}
9040
9041/* Compare H1 and H2 for equivalence. */
9042
9043static int
9044toc_hash_eq (h1, h2)
9045 const void * h1;
9046 const void * h2;
9047{
9048 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
9049 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
9050
a9098fd0
GK
9051 if (((const struct toc_hash_struct *) h1)->key_mode
9052 != ((const struct toc_hash_struct *) h2)->key_mode)
9053 return 0;
9054
9ebbca7d
GK
9055 /* Gotcha: One of these const_doubles will be in memory.
9056 The other may be on the constant-pool chain.
a4f6c312 9057 So rtx_equal_p will think they are different... */
9ebbca7d
GK
9058 if (r1 == r2)
9059 return 1;
9060 if (GET_CODE (r1) != GET_CODE (r2)
9061 || GET_MODE (r1) != GET_MODE (r2))
9062 return 0;
9063 if (GET_CODE (r1) == CONST_DOUBLE)
9064 {
9065 int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE));
9066 int i;
592bf28c 9067 for (i = 1; i < format_len; i++)
9ebbca7d
GK
9068 if (XWINT (r1, i) != XWINT (r2, i))
9069 return 0;
9070
9071 return 1;
17167fd8 9072 }
9ebbca7d 9073 else if (GET_CODE (r1) == LABEL_REF)
e4a0656f
GK
9074 return (CODE_LABEL_NUMBER (XEXP (r1, 0))
9075 == CODE_LABEL_NUMBER (XEXP (r2, 0)));
9ebbca7d
GK
9076 else
9077 return rtx_equal_p (r1, r2);
9078}
9079
9080/* Mark the hash table-entry HASH_ENTRY. */
9081
9082static int
9083toc_hash_mark_entry (hash_slot, unused)
2eba1afa 9084 void ** hash_slot;
9ebbca7d
GK
9085 void * unused ATTRIBUTE_UNUSED;
9086{
9087 const struct toc_hash_struct * hash_entry =
9088 *(const struct toc_hash_struct **) hash_slot;
9089 rtx r = hash_entry->key;
9090 ggc_set_mark (hash_entry);
a4f6c312 9091 /* For CODE_LABELS, we don't want to drag in the whole insn chain... */
9ebbca7d
GK
9092 if (GET_CODE (r) == LABEL_REF)
9093 {
9094 ggc_set_mark (r);
9095 ggc_set_mark (XEXP (r, 0));
9096 }
9097 else
9098 ggc_mark_rtx (r);
9099 return 1;
9100}
9101
9102/* Mark all the elements of the TOC hash-table *HT. */
9103
9104static void
9105toc_hash_mark_table (vht)
9106 void *vht;
9107{
9108 htab_t *ht = vht;
9109
9110 htab_traverse (*ht, toc_hash_mark_entry, (void *)0);
17167fd8
MM
9111}
9112
28e510bd
MM
9113/* These are the names given by the C++ front-end to vtables, and
9114 vtable-like objects. Ideally, this logic should not be here;
9115 instead, there should be some programmatic way of inquiring as
9116 to whether or not an object is a vtable. */
9117
9118#define VTABLE_NAME_P(NAME) \
9119 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
9120 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
9121 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
9122 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
9123
9124void
9125rs6000_output_symbol_ref (file, x)
9126 FILE *file;
9127 rtx x;
9128{
9129 /* Currently C++ toc references to vtables can be emitted before it
9130 is decided whether the vtable is public or private. If this is
9131 the case, then the linker will eventually complain that there is
9132 a reference to an unknown section. Thus, for vtables only,
9133 we emit the TOC reference to reference the symbol and not the
9134 section. */
9135 const char *name = XSTR (x, 0);
54ee9799
DE
9136
9137 if (VTABLE_NAME_P (name))
9138 {
9139 RS6000_OUTPUT_BASENAME (file, name);
9140 }
9141 else
9142 assemble_name (file, name);
28e510bd
MM
9143}
9144
a4f6c312
SS
9145/* Output a TOC entry. We derive the entry name from what is being
9146 written. */
9878760c
RK
9147
9148void
a9098fd0 9149output_toc (file, x, labelno, mode)
9878760c
RK
9150 FILE *file;
9151 rtx x;
9152 int labelno;
a9098fd0 9153 enum machine_mode mode;
9878760c
RK
9154{
9155 char buf[256];
3cce094d 9156 const char *name = buf;
ec940faa 9157 const char *real_name;
9878760c
RK
9158 rtx base = x;
9159 int offset = 0;
9160
4697a36c
MM
9161 if (TARGET_NO_TOC)
9162 abort ();
9163
9ebbca7d
GK
9164 /* When the linker won't eliminate them, don't output duplicate
9165 TOC entries (this happens on AIX if there is any kind of TOC,
1f8f4a0b
MM
9166 and on SVR4 under -fPIC or -mrelocatable). */
9167 if (TARGET_TOC)
9ebbca7d
GK
9168 {
9169 struct toc_hash_struct *h;
9170 void * * found;
9171
9172 h = ggc_alloc (sizeof (*h));
9173 h->key = x;
a9098fd0 9174 h->key_mode = mode;
9ebbca7d
GK
9175 h->labelno = labelno;
9176
9177 found = htab_find_slot (toc_hash_table, h, 1);
9178 if (*found == NULL)
9179 *found = h;
9180 else /* This is indeed a duplicate.
9181 Set this label equal to that label. */
9182 {
9183 fputs ("\t.set ", file);
9184 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
9185 fprintf (file, "%d,", labelno);
9186 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
9187 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9188 found)->labelno));
9189 return;
9190 }
9191 }
9192
9193 /* If we're going to put a double constant in the TOC, make sure it's
9194 aligned properly when strict alignment is on. */
ff1720ed
RK
9195 if (GET_CODE (x) == CONST_DOUBLE
9196 && STRICT_ALIGNMENT
a9098fd0 9197 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
9198 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
9199 ASM_OUTPUT_ALIGN (file, 3);
9200 }
9201
9ebbca7d 9202 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
9878760c 9203
37c37a57
RK
9204 /* Handle FP constants specially. Note that if we have a minimal
9205 TOC, things we put here aren't actually in the TOC, so we can allow
9206 FP constants. */
a9098fd0 9207 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 9208 {
042259f2
DE
9209 REAL_VALUE_TYPE rv;
9210 long k[2];
0adc764e 9211
042259f2
DE
9212 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
9213 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 9214
13ded975
DE
9215 if (TARGET_64BIT)
9216 {
9217 if (TARGET_MINIMAL_TOC)
2bfcf297 9218 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 9219 else
2bfcf297
DB
9220 fprintf (file, "\t.tc FD_%lx_%lx[TC],", k[0], k[1]);
9221 fprintf (file, "0x%lx%08lx\n", k[0], k[1]);
13ded975
DE
9222 return;
9223 }
1875cc88 9224 else
13ded975
DE
9225 {
9226 if (TARGET_MINIMAL_TOC)
2bfcf297 9227 fputs ("\t.long ", file);
13ded975 9228 else
2bfcf297
DB
9229 fprintf (file, "\t.tc FD_%lx_%lx[TC],", k[0], k[1]);
9230 fprintf (file, "0x%lx,0x%lx\n", k[0], k[1]);
13ded975
DE
9231 return;
9232 }
9878760c 9233 }
a9098fd0 9234 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 9235 {
042259f2
DE
9236 REAL_VALUE_TYPE rv;
9237 long l;
9878760c 9238
042259f2
DE
9239 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
9240 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9241
31bfaa0b
DE
9242 if (TARGET_64BIT)
9243 {
9244 if (TARGET_MINIMAL_TOC)
2bfcf297 9245 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 9246 else
2bfcf297
DB
9247 fprintf (file, "\t.tc FS_%lx[TC],", l);
9248 fprintf (file, "0x%lx00000000\n", l);
31bfaa0b
DE
9249 return;
9250 }
042259f2 9251 else
31bfaa0b
DE
9252 {
9253 if (TARGET_MINIMAL_TOC)
2bfcf297 9254 fputs ("\t.long ", file);
31bfaa0b 9255 else
2bfcf297
DB
9256 fprintf (file, "\t.tc FS_%lx[TC],", l);
9257 fprintf (file, "0x%lx\n", l);
31bfaa0b
DE
9258 return;
9259 }
042259f2 9260 }
f176e826 9261 else if (GET_MODE (x) == VOIDmode
a9098fd0 9262 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 9263 {
e2c953b6 9264 unsigned HOST_WIDE_INT low;
042259f2
DE
9265 HOST_WIDE_INT high;
9266
9267 if (GET_CODE (x) == CONST_DOUBLE)
9268 {
9269 low = CONST_DOUBLE_LOW (x);
9270 high = CONST_DOUBLE_HIGH (x);
9271 }
9272 else
9273#if HOST_BITS_PER_WIDE_INT == 32
9274 {
9275 low = INTVAL (x);
0858c623 9276 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
9277 }
9278#else
9279 {
0858c623 9280 low = INTVAL (x) & 0xffffffff;
042259f2
DE
9281 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
9282 }
9283#endif
9878760c 9284
a9098fd0
GK
9285 /* TOC entries are always Pmode-sized, but since this
9286 is a bigendian machine then if we're putting smaller
9287 integer constants in the TOC we have to pad them.
9288 (This is still a win over putting the constants in
9289 a separate constant pool, because then we'd have
02a4ec28
FS
9290 to have both a TOC entry _and_ the actual constant.)
9291
9292 For a 32-bit target, CONST_INT values are loaded and shifted
9293 entirely within `low' and can be stored in one TOC entry. */
9294
9295 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 9296 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
9297
9298 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
a9098fd0
GK
9299 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
9300 POINTER_SIZE, &low, &high, 0);
9301
13ded975
DE
9302 if (TARGET_64BIT)
9303 {
9304 if (TARGET_MINIMAL_TOC)
2bfcf297 9305 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 9306 else
2bfcf297
DB
9307 fprintf (file, "\t.tc ID_%lx_%lx[TC],", (long)high, (long)low);
9308 fprintf (file, "0x%lx%08lx\n", (long) high, (long) low);
13ded975
DE
9309 return;
9310 }
1875cc88 9311 else
13ded975 9312 {
02a4ec28
FS
9313 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
9314 {
9315 if (TARGET_MINIMAL_TOC)
2bfcf297 9316 fputs ("\t.long ", file);
02a4ec28 9317 else
2bfcf297
DB
9318 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
9319 (long)high, (long)low);
9320 fprintf (file, "0x%lx,0x%lx\n", (long) high, (long) low);
02a4ec28 9321 }
13ded975 9322 else
02a4ec28
FS
9323 {
9324 if (TARGET_MINIMAL_TOC)
2bfcf297 9325 fputs ("\t.long ", file);
02a4ec28 9326 else
2bfcf297
DB
9327 fprintf (file, "\t.tc IS_%lx[TC],", (long) low);
9328 fprintf (file, "0x%lx\n", (long) low);
02a4ec28 9329 }
13ded975
DE
9330 return;
9331 }
9878760c
RK
9332 }
9333
9334 if (GET_CODE (x) == CONST)
9335 {
2bfcf297
DB
9336 if (GET_CODE (XEXP (x, 0)) != PLUS)
9337 abort ();
9338
9878760c
RK
9339 base = XEXP (XEXP (x, 0), 0);
9340 offset = INTVAL (XEXP (XEXP (x, 0), 1));
9341 }
9342
9343 if (GET_CODE (base) == SYMBOL_REF)
9344 name = XSTR (base, 0);
9345 else if (GET_CODE (base) == LABEL_REF)
9346 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
9347 else if (GET_CODE (base) == CODE_LABEL)
9348 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
9349 else
9350 abort ();
9351
2e4eb9b0 9352 STRIP_NAME_ENCODING (real_name, name);
1875cc88 9353 if (TARGET_MINIMAL_TOC)
2bfcf297 9354 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
9355 else
9356 {
b6c9286a 9357 fprintf (file, "\t.tc %s", real_name);
9878760c 9358
1875cc88
JW
9359 if (offset < 0)
9360 fprintf (file, ".N%d", - offset);
9361 else if (offset)
9362 fprintf (file, ".P%d", offset);
9878760c 9363
19d2d16f 9364 fputs ("[TC],", file);
1875cc88 9365 }
581bc4de
MM
9366
9367 /* Currently C++ toc references to vtables can be emitted before it
9368 is decided whether the vtable is public or private. If this is
9369 the case, then the linker will eventually complain that there is
9370 a TOC reference to an unknown section. Thus, for vtables only,
9371 we emit the TOC reference to reference the symbol and not the
9372 section. */
28e510bd 9373 if (VTABLE_NAME_P (name))
581bc4de 9374 {
54ee9799 9375 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
9376 if (offset < 0)
9377 fprintf (file, "%d", offset);
9378 else if (offset > 0)
9379 fprintf (file, "+%d", offset);
9380 }
9381 else
9382 output_addr_const (file, x);
19d2d16f 9383 putc ('\n', file);
9878760c
RK
9384}
9385\f
9386/* Output an assembler pseudo-op to write an ASCII string of N characters
9387 starting at P to FILE.
9388
9389 On the RS/6000, we have to do this using the .byte operation and
9390 write out special characters outside the quoted string.
9391 Also, the assembler is broken; very long strings are truncated,
a4f6c312 9392 so we must artificially break them up early. */
9878760c
RK
9393
9394void
9395output_ascii (file, p, n)
9396 FILE *file;
d330fd93 9397 const char *p;
9878760c
RK
9398 int n;
9399{
9400 char c;
9401 int i, count_string;
d330fd93
KG
9402 const char *for_string = "\t.byte \"";
9403 const char *for_decimal = "\t.byte ";
9404 const char *to_close = NULL;
9878760c
RK
9405
9406 count_string = 0;
9407 for (i = 0; i < n; i++)
9408 {
9409 c = *p++;
9410 if (c >= ' ' && c < 0177)
9411 {
9412 if (for_string)
9413 fputs (for_string, file);
9414 putc (c, file);
9415
9416 /* Write two quotes to get one. */
9417 if (c == '"')
9418 {
9419 putc (c, file);
9420 ++count_string;
9421 }
9422
9423 for_string = NULL;
9424 for_decimal = "\"\n\t.byte ";
9425 to_close = "\"\n";
9426 ++count_string;
9427
9428 if (count_string >= 512)
9429 {
9430 fputs (to_close, file);
9431
9432 for_string = "\t.byte \"";
9433 for_decimal = "\t.byte ";
9434 to_close = NULL;
9435 count_string = 0;
9436 }
9437 }
9438 else
9439 {
9440 if (for_decimal)
9441 fputs (for_decimal, file);
9442 fprintf (file, "%d", c);
9443
9444 for_string = "\n\t.byte \"";
9445 for_decimal = ", ";
9446 to_close = "\n";
9447 count_string = 0;
9448 }
9449 }
9450
9451 /* Now close the string if we have written one. Then end the line. */
9452 if (to_close)
9ebbca7d 9453 fputs (to_close, file);
9878760c
RK
9454}
9455\f
9456/* Generate a unique section name for FILENAME for a section type
9457 represented by SECTION_DESC. Output goes into BUF.
9458
9459 SECTION_DESC can be any string, as long as it is different for each
9460 possible section type.
9461
9462 We name the section in the same manner as xlc. The name begins with an
9463 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
9464 names) with the last period replaced by the string SECTION_DESC. If
9465 FILENAME does not contain a period, SECTION_DESC is appended to the end of
9466 the name. */
9878760c
RK
9467
9468void
9469rs6000_gen_section_name (buf, filename, section_desc)
9470 char **buf;
9ebbca7d
GK
9471 const char *filename;
9472 const char *section_desc;
9878760c 9473{
9ebbca7d 9474 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
9475 char *p;
9476 int len;
9878760c
RK
9477
9478 after_last_slash = filename;
9479 for (q = filename; *q; q++)
11e5fe42
RK
9480 {
9481 if (*q == '/')
9482 after_last_slash = q + 1;
9483 else if (*q == '.')
9484 last_period = q;
9485 }
9878760c 9486
11e5fe42 9487 len = strlen (after_last_slash) + strlen (section_desc) + 2;
9878760c
RK
9488 *buf = (char *) permalloc (len);
9489
9490 p = *buf;
9491 *p++ = '_';
9492
9493 for (q = after_last_slash; *q; q++)
9494 {
11e5fe42 9495 if (q == last_period)
9878760c
RK
9496 {
9497 strcpy (p, section_desc);
9498 p += strlen (section_desc);
9878760c
RK
9499 }
9500
e9a780ec 9501 else if (ISALNUM (*q))
9878760c
RK
9502 *p++ = *q;
9503 }
9504
11e5fe42 9505 if (last_period == 0)
9878760c
RK
9506 strcpy (p, section_desc);
9507 else
9508 *p = '\0';
9509}
e165f3f0 9510\f
a4f6c312 9511/* Emit profile function. */
411707f4 9512
411707f4
CC
9513void
9514output_profile_hook (labelno)
9515 int labelno;
9516{
8480e480
CC
9517 if (DEFAULT_ABI == ABI_AIX)
9518 {
9519 char buf[30];
40501e5f 9520 const char *label_name;
8480e480 9521 rtx fun;
411707f4 9522
8480e480 9523 labelno += 1;
411707f4 9524
8480e480
CC
9525 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
9526 STRIP_NAME_ENCODING (label_name, ggc_strdup (buf));
9527 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 9528
8480e480
CC
9529 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
9530 fun, Pmode);
9531 }
ee890fe2
SS
9532 else if (DEFAULT_ABI == ABI_DARWIN)
9533 {
d5fa86ba 9534 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
9535 int caller_addr_regno = LINK_REGISTER_REGNUM;
9536
9537 /* Be conservative and always set this, at least for now. */
9538 current_function_uses_pic_offset_table = 1;
9539
9540#if TARGET_MACHO
9541 /* For PIC code, set up a stub and collect the caller's address
9542 from r0, which is where the prologue puts it. */
9543 if (flag_pic)
9544 {
9545 mcount_name = machopic_stub_name (mcount_name);
9546 if (current_function_uses_pic_offset_table)
9547 caller_addr_regno = 0;
9548 }
9549#endif
9550 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
9551 0, VOIDmode, 1,
9552 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
9553 }
411707f4
CC
9554}
9555
a4f6c312 9556/* Write function profiler code. */
e165f3f0
RK
9557
9558void
9559output_function_profiler (file, labelno)
9560 FILE *file;
9561 int labelno;
9562{
3daf36a4 9563 char buf[100];
e165f3f0 9564
3daf36a4 9565 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 9566 switch (DEFAULT_ABI)
3daf36a4 9567 {
38c1f2d7
MM
9568 default:
9569 abort ();
9570
9571 case ABI_V4:
38c1f2d7
MM
9572 case ABI_AIX_NODESC:
9573 fprintf (file, "\tmflr %s\n", reg_names[0]);
9574 if (flag_pic == 1)
9575 {
dfdfa60f
DE
9576 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
9577 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
9578 reg_names[0], reg_names[1]);
17167fd8 9579 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 9580 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 9581 assemble_name (file, buf);
17167fd8 9582 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 9583 }
9ebbca7d 9584 else if (flag_pic > 1)
38c1f2d7 9585 {
dfdfa60f
DE
9586 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
9587 reg_names[0], reg_names[1]);
9ebbca7d
GK
9588 /* Now, we need to get the address of the label. */
9589 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 9590 assemble_name (file, buf);
9ebbca7d
GK
9591 fputs ("-.\n1:", file);
9592 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
9593 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9594 reg_names[0], reg_names[11]);
9595 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
9596 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 9597 }
38c1f2d7
MM
9598 else
9599 {
17167fd8 9600 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 9601 assemble_name (file, buf);
dfdfa60f 9602 fputs ("@ha\n", file);
b5253831
DE
9603 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
9604 reg_names[0], reg_names[1]);
a260abc9 9605 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 9606 assemble_name (file, buf);
17167fd8 9607 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
9608 }
9609
b5253831
DE
9610 if (current_function_needs_context)
9611 asm_fprintf (file, "\tmr %s,%s\n",
9612 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
38c1f2d7 9613 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
b5253831
DE
9614 if (current_function_needs_context)
9615 asm_fprintf (file, "\tmr %s,%s\n",
9616 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
38c1f2d7
MM
9617 break;
9618
9619 case ABI_AIX:
ee890fe2 9620 case ABI_DARWIN:
a4f6c312 9621 /* Don't do anything, done in output_profile_hook (). */
38c1f2d7 9622 break;
411707f4 9623
38c1f2d7 9624 }
e165f3f0 9625}
a251ffd0
TG
9626
9627/* Adjust the cost of a scheduling dependency. Return the new cost of
9628 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
9629
c237e94a 9630static int
a06faf84 9631rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
9632 rtx insn;
9633 rtx link;
296b8152 9634 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
9635 int cost;
9636{
9637 if (! recog_memoized (insn))
9638 return 0;
9639
9640 if (REG_NOTE_KIND (link) != 0)
9641 return 0;
9642
9643 if (REG_NOTE_KIND (link) == 0)
9644 {
ed947a96
DJ
9645 /* Data dependency; DEP_INSN writes a register that INSN reads
9646 some cycles later. */
9647 switch (get_attr_type (insn))
9648 {
9649 case TYPE_JMPREG:
9650 /* Tell the first scheduling pass about the latency between
9651 a mtctr and bctr (and mtlr and br/blr). The first
9652 scheduling pass will not know about this latency since
9653 the mtctr instruction, which has the latency associated
9654 to it, will be generated by reload. */
9655 return TARGET_POWER ? 5 : 4;
9656 case TYPE_BRANCH:
9657 /* Leave some extra cycles between a compare and its
9658 dependent branch, to inhibit expensive mispredicts. */
9659 if ((rs6000_cpu_attr == CPU_PPC750
9660 || rs6000_cpu_attr == CPU_PPC7400
9661 || rs6000_cpu_attr == CPU_PPC7450)
9662 && recog_memoized (dep_insn)
9663 && (INSN_CODE (dep_insn) >= 0)
9664 && (get_attr_type (dep_insn) == TYPE_COMPARE
9665 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9666 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
9667 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL))
9668 return cost + 2;
9669 default:
9670 break;
9671 }
a251ffd0
TG
9672 /* Fall out to return default cost. */
9673 }
9674
9675 return cost;
9676}
b6c9286a 9677
a4f6c312
SS
9678/* A C statement (sans semicolon) to update the integer scheduling
9679 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
9680 INSN earlier, increase the priority to execute INSN later. Do not
9681 define this macro if you do not need to adjust the scheduling
9682 priorities of insns. */
bef84347 9683
c237e94a 9684static int
bef84347 9685rs6000_adjust_priority (insn, priority)
d330fd93 9686 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
9687 int priority;
9688{
a4f6c312
SS
9689 /* On machines (like the 750) which have asymmetric integer units,
9690 where one integer unit can do multiply and divides and the other
9691 can't, reduce the priority of multiply/divide so it is scheduled
9692 before other integer operations. */
bef84347
VM
9693
9694#if 0
2c3c49de 9695 if (! INSN_P (insn))
bef84347
VM
9696 return priority;
9697
9698 if (GET_CODE (PATTERN (insn)) == USE)
9699 return priority;
9700
9701 switch (rs6000_cpu_attr) {
9702 case CPU_PPC750:
9703 switch (get_attr_type (insn))
9704 {
9705 default:
9706 break;
9707
9708 case TYPE_IMUL:
9709 case TYPE_IDIV:
3cb999d8
DE
9710 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
9711 priority, priority);
bef84347
VM
9712 if (priority >= 0 && priority < 0x01000000)
9713 priority >>= 3;
9714 break;
9715 }
9716 }
9717#endif
9718
9719 return priority;
9720}
9721
a4f6c312
SS
9722/* Return how many instructions the machine can issue per cycle. */
9723
c237e94a
ZW
9724static int
9725rs6000_issue_rate ()
b6c9286a
MM
9726{
9727 switch (rs6000_cpu_attr) {
3cb999d8
DE
9728 case CPU_RIOS1: /* ? */
9729 case CPU_RS64A:
9730 case CPU_PPC601: /* ? */
ed947a96 9731 case CPU_PPC7450:
3cb999d8 9732 return 3;
b6c9286a 9733 case CPU_PPC603:
bef84347 9734 case CPU_PPC750:
ed947a96 9735 case CPU_PPC7400:
bef84347 9736 return 2;
3cb999d8 9737 case CPU_RIOS2:
b6c9286a 9738 case CPU_PPC604:
19684119 9739 case CPU_PPC604E:
b6c9286a 9740 case CPU_PPC620:
3cb999d8 9741 case CPU_PPC630:
b6c9286a
MM
9742 return 4;
9743 default:
9744 return 1;
9745 }
9746}
9747
b6c9286a 9748\f
b6c9286a
MM
9749/* Length in units of the trampoline for entering a nested function. */
9750
9751int
9752rs6000_trampoline_size ()
9753{
9754 int ret = 0;
9755
9756 switch (DEFAULT_ABI)
9757 {
9758 default:
9759 abort ();
9760
9761 case ABI_AIX:
8f802bfb 9762 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
9763 break;
9764
4dabc42d 9765 case ABI_DARWIN:
b6c9286a
MM
9766 case ABI_V4:
9767 case ABI_AIX_NODESC:
03a7e1a5 9768 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 9769 break;
b6c9286a
MM
9770 }
9771
9772 return ret;
9773}
9774
9775/* Emit RTL insns to initialize the variable parts of a trampoline.
9776 FNADDR is an RTX for the address of the function's pure code.
9777 CXT is an RTX for the static chain value for the function. */
9778
9779void
9780rs6000_initialize_trampoline (addr, fnaddr, cxt)
9781 rtx addr;
9782 rtx fnaddr;
9783 rtx cxt;
9784{
ac2a93a1 9785 enum machine_mode pmode = Pmode;
8bd04c56
MM
9786 int regsize = (TARGET_32BIT) ? 4 : 8;
9787 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
9788
9789 switch (DEFAULT_ABI)
9790 {
9791 default:
9792 abort ();
9793
8bd04c56 9794/* Macros to shorten the code expansions below. */
39403d82 9795#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
9796#define MEM_PLUS(addr,offset) \
9797 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 9798
b6c9286a
MM
9799 /* Under AIX, just build the 3 word function descriptor */
9800 case ABI_AIX:
8bd04c56
MM
9801 {
9802 rtx fn_reg = gen_reg_rtx (pmode);
9803 rtx toc_reg = gen_reg_rtx (pmode);
9804 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 9805 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
9806 emit_move_insn (MEM_DEREF (addr), fn_reg);
9807 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
9808 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
9809 }
b6c9286a
MM
9810 break;
9811
4dabc42d
TC
9812 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
9813 case ABI_DARWIN:
b6c9286a
MM
9814 case ABI_V4:
9815 case ABI_AIX_NODESC:
39403d82 9816 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
9817 FALSE, VOIDmode, 4,
9818 addr, pmode,
9819 GEN_INT (rs6000_trampoline_size ()), SImode,
9820 fnaddr, pmode,
9821 ctx_reg, pmode);
b6c9286a 9822 break;
b6c9286a
MM
9823 }
9824
9825 return;
9826}
7509c759
MM
9827
9828\f
91d231cb 9829/* Table of valid machine attributes. */
a4f6c312 9830
91d231cb 9831const struct attribute_spec rs6000_attribute_table[] =
7509c759 9832{
91d231cb
JM
9833 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
9834 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
9835 { NULL, 0, 0, false, false, false, NULL }
9836};
7509c759 9837
a4f6c312
SS
9838/* Handle a "longcall" attribute; arguments as in struct
9839 attribute_spec.handler. */
9840
91d231cb
JM
9841static tree
9842rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs)
9843 tree *node;
9844 tree name;
9845 tree args ATTRIBUTE_UNUSED;
9846 int flags ATTRIBUTE_UNUSED;
9847 bool *no_add_attrs;
9848{
9849 if (TREE_CODE (*node) != FUNCTION_TYPE
9850 && TREE_CODE (*node) != FIELD_DECL
9851 && TREE_CODE (*node) != TYPE_DECL)
9852 {
9853 warning ("`%s' attribute only applies to functions",
9854 IDENTIFIER_POINTER (name));
9855 *no_add_attrs = true;
9856 }
6a4cee5f 9857
91d231cb 9858 return NULL_TREE;
7509c759
MM
9859}
9860
3cb999d8
DE
9861/* Return a reference suitable for calling a function with the
9862 longcall attribute. */
a4f6c312 9863
6a4cee5f
MM
9864struct rtx_def *
9865rs6000_longcall_ref (call_ref)
9866 rtx call_ref;
9867{
d330fd93 9868 const char *call_name;
6a4cee5f
MM
9869 tree node;
9870
9871 if (GET_CODE (call_ref) != SYMBOL_REF)
9872 return call_ref;
9873
9874 /* System V adds '.' to the internal name, so skip them. */
9875 call_name = XSTR (call_ref, 0);
9876 if (*call_name == '.')
9877 {
9878 while (*call_name == '.')
9879 call_name++;
9880
9881 node = get_identifier (call_name);
39403d82 9882 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
9883 }
9884
9885 return force_reg (Pmode, call_ref);
9886}
9887
7509c759
MM
9888\f
9889/* A C statement or statements to switch to the appropriate section
9890 for output of RTX in mode MODE. You can assume that RTX is some
9891 kind of constant in RTL. The argument MODE is redundant except in
9892 the case of a `const_int' rtx. Select the section by calling
9893 `text_section' or one of the alternatives for other sections.
9894
9895 Do not define this macro if you put all constants in the read-only
9896 data section. */
9897
b91da81f 9898#ifdef USING_ELFOS_H
7509c759
MM
9899
9900void
9901rs6000_select_rtx_section (mode, x)
a9098fd0 9902 enum machine_mode mode;
7509c759
MM
9903 rtx x;
9904{
a9098fd0 9905 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 9906 toc_section ();
7509c759
MM
9907 else
9908 const_section ();
9909}
9910
9911/* A C statement or statements to switch to the appropriate
9912 section for output of DECL. DECL is either a `VAR_DECL' node
9913 or a constant of some sort. RELOC indicates whether forming
9914 the initial value of DECL requires link-time relocations. */
9915
9916void
9917rs6000_select_section (decl, reloc)
9918 tree decl;
9919 int reloc;
9920{
9921 int size = int_size_in_bytes (TREE_TYPE (decl));
63019373
GK
9922 int needs_sdata;
9923 int readonly;
9924 static void (* const sec_funcs[4]) PARAMS ((void)) = {
9925 &const_section,
9926 &sdata2_section,
9927 &data_section,
9928 &sdata_section
9929 };
9930
9931 needs_sdata = (size > 0
9932 && size <= g_switch_value
9933 && rs6000_sdata != SDATA_NONE
9934 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7509c759
MM
9935
9936 if (TREE_CODE (decl) == STRING_CST)
63019373 9937 readonly = ! flag_writable_strings;
a9098fd0 9938 else if (TREE_CODE (decl) == VAR_DECL)
63019373
GK
9939 readonly = (! (flag_pic && reloc)
9940 && TREE_READONLY (decl)
9941 && ! TREE_SIDE_EFFECTS (decl)
9942 && DECL_INITIAL (decl)
9943 && DECL_INITIAL (decl) != error_mark_node
9944 && TREE_CONSTANT (DECL_INITIAL (decl)));
ac4f7ad9
GK
9945 else if (TREE_CODE (decl) == CONSTRUCTOR)
9946 readonly = (! (flag_pic && reloc)
ac4f7ad9 9947 && ! TREE_SIDE_EFFECTS (decl)
f3afc192 9948 && TREE_CONSTANT (decl));
7509c759 9949 else
63019373
GK
9950 readonly = 1;
9951 if (needs_sdata && rs6000_sdata != SDATA_EABI)
9952 readonly = 0;
9953
9954 (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])();
9955}
9956
9957/* A C statement to build up a unique section name, expressed as a
9958 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
9959 RELOC indicates whether the initial value of EXP requires
9960 link-time relocations. If you do not define this macro, GCC will use
9961 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 9962 macro can now be called for uninitialized data items as well as
63019373
GK
9963 initialised data and functions. */
9964
9965void
9966rs6000_unique_section (decl, reloc)
9967 tree decl;
9968 int reloc;
9969{
63019373
GK
9970 int len;
9971 int sec;
9972 const char *name;
9973 char *string;
9974 const char *prefix;
9975
9976 static const char *const prefixes[7][2] =
9977 {
63019373
GK
9978 { ".rodata.", ".gnu.linkonce.r." },
9979 { ".sdata2.", ".gnu.linkonce.s2." },
9980 { ".data.", ".gnu.linkonce.d." },
9981 { ".sdata.", ".gnu.linkonce.s." },
9982 { ".bss.", ".gnu.linkonce.b." },
5b8c2356
AM
9983 { ".sbss.", ".gnu.linkonce.sb." },
9984 { ".text.", ".gnu.linkonce.t." }
63019373 9985 };
63019373 9986
5b8c2356
AM
9987 if (TREE_CODE (decl) == FUNCTION_DECL)
9988 sec = 6;
63019373 9989 else
5b8c2356
AM
9990 {
9991 int readonly;
9992 int needs_sdata;
9993 int size;
9994
9995 readonly = 1;
9996 if (TREE_CODE (decl) == STRING_CST)
9997 readonly = ! flag_writable_strings;
9998 else if (TREE_CODE (decl) == VAR_DECL)
9999 readonly = (! (flag_pic && reloc)
10000 && TREE_READONLY (decl)
10001 && ! TREE_SIDE_EFFECTS (decl)
10002 && TREE_CONSTANT (DECL_INITIAL (decl)));
10003
10004 size = int_size_in_bytes (TREE_TYPE (decl));
10005 needs_sdata = (size > 0
10006 && size <= g_switch_value
10007 && rs6000_sdata != SDATA_NONE
10008 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
10009
10010 if (DECL_INITIAL (decl) == 0
10011 || DECL_INITIAL (decl) == error_mark_node)
10012 sec = 4;
10013 else if (! readonly)
10014 sec = 2;
10015 else
10016 sec = 0;
63019373 10017
5b8c2356
AM
10018 if (needs_sdata)
10019 {
10020 /* .sdata2 is only for EABI. */
10021 if (sec == 0 && rs6000_sdata != SDATA_EABI)
10022 sec = 2;
10023 sec += 1;
10024 }
10025 }
63019373 10026
e6978109 10027 STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
63019373
GK
10028 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
10029 len = strlen (name) + strlen (prefix);
10030 string = alloca (len + 1);
10031
10032 sprintf (string, "%s%s", prefix, name);
10033
10034 DECL_SECTION_NAME (decl) = build_string (len, string);
7509c759 10035}
d9407988
MM
10036
10037\f
d9407988
MM
10038/* If we are referencing a function that is static or is known to be
10039 in this file, make the SYMBOL_REF special. We can use this to indicate
10040 that we can branch to this function without emitting a no-op after the
9ebbca7d 10041 call. For real AIX calling sequences, we also replace the
d9407988
MM
10042 function name with the real name (1 or 2 leading .'s), rather than
10043 the function descriptor name. This saves a lot of overriding code
a260abc9 10044 to read the prefixes. */
d9407988
MM
10045
10046void
10047rs6000_encode_section_info (decl)
10048 tree decl;
10049{
10050 if (TREE_CODE (decl) == FUNCTION_DECL)
10051 {
10052 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
8f1b829e 10053 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
c81fc13e 10054 && ! DECL_WEAK (decl))
d9407988
MM
10055 SYMBOL_REF_FLAG (sym_ref) = 1;
10056
9ebbca7d 10057 if (DEFAULT_ABI == ABI_AIX)
d9407988 10058 {
ff669a6c
RH
10059 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
10060 size_t len2 = strlen (XSTR (sym_ref, 0));
520a57c8 10061 char *str = alloca (len1 + len2 + 1);
ff669a6c
RH
10062 str[0] = '.';
10063 str[1] = '.';
10064 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
10065
520a57c8 10066 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
d9407988
MM
10067 }
10068 }
10069 else if (rs6000_sdata != SDATA_NONE
f607bc57 10070 && DEFAULT_ABI == ABI_V4
d9407988
MM
10071 && TREE_CODE (decl) == VAR_DECL)
10072 {
10073 int size = int_size_in_bytes (TREE_TYPE (decl));
10074 tree section_name = DECL_SECTION_NAME (decl);
d330fd93 10075 const char *name = (char *)0;
d9407988
MM
10076 int len = 0;
10077
10078 if (section_name)
10079 {
10080 if (TREE_CODE (section_name) == STRING_CST)
10081 {
10082 name = TREE_STRING_POINTER (section_name);
10083 len = TREE_STRING_LENGTH (section_name);
10084 }
10085 else
10086 abort ();
10087 }
10088
10089 if ((size > 0 && size <= g_switch_value)
10090 || (name
5f59ecb7 10091 && ((len == sizeof (".sdata") - 1
3cb999d8 10092 && strcmp (name, ".sdata") == 0)
5f59ecb7 10093 || (len == sizeof (".sdata2") - 1
3cb999d8 10094 && strcmp (name, ".sdata2") == 0)
5f59ecb7 10095 || (len == sizeof (".sbss") - 1
3cb999d8 10096 && strcmp (name, ".sbss") == 0)
5f59ecb7 10097 || (len == sizeof (".sbss2") - 1
3cb999d8 10098 && strcmp (name, ".sbss2") == 0)
5f59ecb7 10099 || (len == sizeof (".PPC.EMB.sdata0") - 1
3cb999d8 10100 && strcmp (name, ".PPC.EMB.sdata0") == 0)
5f59ecb7 10101 || (len == sizeof (".PPC.EMB.sbss0") - 1
3cb999d8 10102 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
d9407988
MM
10103 {
10104 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
ff669a6c 10105 size_t len = strlen (XSTR (sym_ref, 0));
88c1e412 10106 char *str = alloca (len + 2);
ff669a6c 10107
ff669a6c
RH
10108 str[0] = '@';
10109 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
88c1e412 10110 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988
MM
10111 }
10112 }
10113}
10114
b91da81f 10115#endif /* USING_ELFOS_H */
000034eb 10116
a6c2a102 10117\f
000034eb 10118/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
10119 ADDR can be effectively incremented by incrementing REG.
10120
10121 r0 is special and we must not select it as an address
10122 register by this routine since our caller will try to
10123 increment the returned register via an "la" instruction. */
000034eb
DE
10124
10125struct rtx_def *
10126find_addr_reg (addr)
10127 rtx addr;
10128{
10129 while (GET_CODE (addr) == PLUS)
10130 {
02441cd6
JL
10131 if (GET_CODE (XEXP (addr, 0)) == REG
10132 && REGNO (XEXP (addr, 0)) != 0)
000034eb 10133 addr = XEXP (addr, 0);
02441cd6
JL
10134 else if (GET_CODE (XEXP (addr, 1)) == REG
10135 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
10136 addr = XEXP (addr, 1);
10137 else if (CONSTANT_P (XEXP (addr, 0)))
10138 addr = XEXP (addr, 1);
10139 else if (CONSTANT_P (XEXP (addr, 1)))
10140 addr = XEXP (addr, 0);
10141 else
10142 abort ();
10143 }
02441cd6 10144 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
10145 return addr;
10146 abort ();
10147}
10148
a6c2a102
DE
10149void
10150rs6000_fatal_bad_address (op)
10151 rtx op;
10152{
10153 fatal_insn ("bad address", op);
10154}
c8023011
MM
10155
10156/* Called to register all of our global variables with the garbage
10157 collector. */
10158
10159static void
10160rs6000_add_gc_roots ()
10161{
10162 ggc_add_rtx_root (&rs6000_compare_op0, 1);
10163 ggc_add_rtx_root (&rs6000_compare_op1, 1);
9ebbca7d
GK
10164
10165 toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL);
10166 ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table),
10167 toc_hash_mark_table);
ee890fe2
SS
10168
10169#if TARGET_MACHO
10170 machopic_add_gc_roots ();
10171#endif
10172}
10173
10174#if TARGET_MACHO
10175
10176#if 0
10177/* Returns 1 if OP is either a symbol reference or a sum of a symbol
10178 reference and a constant. */
10179
10180int
10181symbolic_operand (op)
592696dd 10182 rtx op;
ee890fe2
SS
10183{
10184 switch (GET_CODE (op))
10185 {
10186 case SYMBOL_REF:
10187 case LABEL_REF:
10188 return 1;
10189 case CONST:
10190 op = XEXP (op, 0);
10191 return (GET_CODE (op) == SYMBOL_REF ||
10192 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
10193 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
10194 && GET_CODE (XEXP (op, 1)) == CONST_INT);
10195 default:
10196 return 0;
10197 }
c8023011 10198}
ee890fe2
SS
10199#endif
10200
10201#ifdef RS6000_LONG_BRANCH
10202
10203static tree stub_list = 0;
10204
10205/* ADD_COMPILER_STUB adds the compiler generated stub for handling
10206 procedure calls to the linked list. */
10207
10208void
10209add_compiler_stub (label_name, function_name, line_number)
10210 tree label_name;
10211 tree function_name;
10212 int line_number;
10213{
10214 tree stub = build_tree_list (function_name, label_name);
10215 TREE_TYPE (stub) = build_int_2 (line_number, 0);
10216 TREE_CHAIN (stub) = stub_list;
10217 stub_list = stub;
10218}
10219
10220#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
10221#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
10222#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
10223
a4f6c312
SS
10224/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
10225 handling procedure calls from the linked list and initializes the
10226 linked list. */
ee890fe2 10227
a4f6c312
SS
10228void
10229output_compiler_stub ()
ee890fe2
SS
10230{
10231 char tmp_buf[256];
10232 char label_buf[256];
10233 char *label;
10234 tree tmp_stub, stub;
10235
10236 if (!flag_pic)
10237 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
10238 {
10239 fprintf (asm_out_file,
10240 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
10241
10242#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
10243 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
10244 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
10245#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
10246
10247 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
10248 strcpy (label_buf,
10249 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
10250 else
10251 {
10252 label_buf[0] = '_';
10253 strcpy (label_buf+1,
10254 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
10255 }
10256
10257 strcpy (tmp_buf, "lis r12,hi16(");
10258 strcat (tmp_buf, label_buf);
10259 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
10260 strcat (tmp_buf, label_buf);
10261 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
10262 output_asm_insn (tmp_buf, 0);
10263
10264#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
10265 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
10266 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
10267#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
10268 }
10269
10270 stub_list = 0;
10271}
10272
10273/* NO_PREVIOUS_DEF checks in the link list whether the function name is
10274 already there or not. */
10275
a4f6c312
SS
10276int
10277no_previous_def (function_name)
ee890fe2
SS
10278 tree function_name;
10279{
10280 tree stub;
10281 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
10282 if (function_name == STUB_FUNCTION_NAME (stub))
10283 return 0;
10284 return 1;
10285}
10286
10287/* GET_PREV_LABEL gets the label name from the previous definition of
10288 the function. */
10289
a4f6c312
SS
10290tree
10291get_prev_label (function_name)
ee890fe2
SS
10292 tree function_name;
10293{
10294 tree stub;
10295 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
10296 if (function_name == STUB_FUNCTION_NAME (stub))
10297 return STUB_LABEL_NAME (stub);
10298 return 0;
10299}
10300
10301/* INSN is either a function call or a millicode call. It may have an
10302 unconditional jump in its delay slot.
10303
10304 CALL_DEST is the routine we are calling. */
10305
10306char *
10307output_call (insn, call_dest, operand_number)
10308 rtx insn;
10309 rtx call_dest;
10310 int operand_number;
10311{
10312 static char buf[256];
10313 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
10314 {
10315 tree labelname;
10316 tree funname = get_identifier (XSTR (call_dest, 0));
10317
10318 if (no_previous_def (funname))
10319 {
10320 int line_number;
10321 rtx label_rtx = gen_label_rtx ();
10322 char *label_buf, temp_buf[256];
10323 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
10324 CODE_LABEL_NUMBER (label_rtx));
10325 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
10326 labelname = get_identifier (label_buf);
10327 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
10328 if (insn)
10329 line_number = NOTE_LINE_NUMBER (insn);
10330 add_compiler_stub (labelname, funname, line_number);
10331 }
10332 else
10333 labelname = get_prev_label (funname);
10334
10335 sprintf (buf, "jbsr %%z%d,%.246s",
10336 operand_number, IDENTIFIER_POINTER (labelname));
10337 return buf;
10338 }
10339 else
10340 {
10341 sprintf (buf, "bl %%z%d", operand_number);
10342 return buf;
10343 }
10344}
10345
10346#endif /* RS6000_LONG_BRANCH */
10347
10348#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
10349 do { \
83182544 10350 const char *const symbol_ = (SYMBOL); \
ee890fe2
SS
10351 char *buffer_ = (BUF); \
10352 if (symbol_[0] == '"') \
10353 { \
10354 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
10355 } \
10356 else if (name_needs_quotes(symbol_)) \
10357 { \
10358 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
10359 } \
10360 else \
10361 { \
10362 sprintf(buffer_, "L%d$%s", (N), symbol_); \
10363 } \
10364 } while (0)
10365
10366
10367/* Generate PIC and indirect symbol stubs. */
10368
10369void
10370machopic_output_stub (file, symb, stub)
10371 FILE *file;
10372 const char *symb, *stub;
10373{
10374 unsigned int length;
a4f6c312
SS
10375 char *symbol_name, *lazy_ptr_name;
10376 char *local_label_0;
ee890fe2
SS
10377 static int label = 0;
10378
df56a27f
SS
10379 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
10380 STRIP_NAME_ENCODING (symb, symb);
10381
ee890fe2
SS
10382 label += 1;
10383
ee890fe2
SS
10384 length = strlen (symb);
10385 symbol_name = alloca (length + 32);
10386 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
10387
10388 lazy_ptr_name = alloca (length + 32);
10389 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
10390
10391 local_label_0 = alloca (length + 32);
10392 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
10393
ee890fe2
SS
10394 if (flag_pic == 2)
10395 machopic_picsymbol_stub_section ();
10396 else
10397 machopic_symbol_stub_section ();
10398
10399 fprintf (file, "%s:\n", stub);
10400 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
10401
10402 if (flag_pic == 2)
10403 {
10404 fprintf (file, "\tmflr r0\n");
10405 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
10406 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
10407 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
10408 lazy_ptr_name, local_label_0);
10409 fprintf (file, "\tmtlr r0\n");
10410 fprintf (file, "\tlwz r12,lo16(%s-%s)(r11)\n",
10411 lazy_ptr_name, local_label_0);
10412 fprintf (file, "\tmtctr r12\n");
10413 fprintf (file, "\taddi r11,r11,lo16(%s-%s)\n",
10414 lazy_ptr_name, local_label_0);
10415 fprintf (file, "\tbctr\n");
10416 }
10417 else
10418 fprintf (file, "non-pure not supported\n");
10419
10420 machopic_lazy_symbol_ptr_section ();
10421 fprintf (file, "%s:\n", lazy_ptr_name);
10422 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
10423 fprintf (file, "\t.long dyld_stub_binding_helper\n");
10424}
10425
10426/* Legitimize PIC addresses. If the address is already
10427 position-independent, we return ORIG. Newly generated
10428 position-independent addresses go into a reg. This is REG if non
10429 zero, otherwise we allocate register(s) as necessary. */
10430
c859cda6 10431#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
10432
10433rtx
10434rs6000_machopic_legitimize_pic_address (orig, mode, reg)
10435 rtx orig;
10436 enum machine_mode mode;
10437 rtx reg;
10438{
10439 rtx base, offset;
10440
10441 if (reg == NULL && ! reload_in_progress && ! reload_completed)
10442 reg = gen_reg_rtx (Pmode);
10443
10444 if (GET_CODE (orig) == CONST)
10445 {
10446 if (GET_CODE (XEXP (orig, 0)) == PLUS
10447 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
10448 return orig;
10449
10450 if (GET_CODE (XEXP (orig, 0)) == PLUS)
10451 {
a4f6c312
SS
10452 base =
10453 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
10454 Pmode, reg);
10455 offset =
10456 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
10457 Pmode, reg);
ee890fe2
SS
10458 }
10459 else
10460 abort ();
10461
10462 if (GET_CODE (offset) == CONST_INT)
10463 {
10464 if (SMALL_INT (offset))
ed8908e7 10465 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
10466 else if (! reload_in_progress && ! reload_completed)
10467 offset = force_reg (Pmode, offset);
10468 else
c859cda6
DJ
10469 {
10470 rtx mem = force_const_mem (Pmode, orig);
10471 return machopic_legitimize_pic_address (mem, Pmode, reg);
10472 }
ee890fe2
SS
10473 }
10474 return gen_rtx (PLUS, Pmode, base, offset);
10475 }
10476
10477 /* Fall back on generic machopic code. */
10478 return machopic_legitimize_pic_address (orig, mode, reg);
10479}
10480
10481/* This is just a placeholder to make linking work without having to
10482 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
10483 ever needed for Darwin (not too likely!) this would have to get a
10484 real definition. */
10485
10486void
10487toc_section ()
10488{
10489}
10490
10491#endif /* TARGET_MACHO */
7c262518
RH
10492
10493#if TARGET_ELF
10494static unsigned int
10495rs6000_elf_section_type_flags (decl, name, reloc)
10496 tree decl;
10497 const char *name;
10498 int reloc;
10499{
10500 unsigned int flags = default_section_type_flags (decl, name, reloc);
10501
270fc29b
RH
10502 if (TARGET_RELOCATABLE)
10503 flags |= SECTION_WRITE;
7c262518 10504
d0101753 10505 return flags;
7c262518 10506}
d9f6800d
RH
10507
10508/* Record an element in the table of global constructors. SYMBOL is
10509 a SYMBOL_REF of the function to be called; PRIORITY is a number
10510 between 0 and MAX_INIT_PRIORITY.
10511
10512 This differs from default_named_section_asm_out_constructor in
10513 that we have special handling for -mrelocatable. */
10514
10515static void
10516rs6000_elf_asm_out_constructor (symbol, priority)
10517 rtx symbol;
10518 int priority;
10519{
10520 const char *section = ".ctors";
10521 char buf[16];
10522
10523 if (priority != DEFAULT_INIT_PRIORITY)
10524 {
10525 sprintf (buf, ".ctors.%.5u",
10526 /* Invert the numbering so the linker puts us in the proper
10527 order; constructors are run from right to left, and the
10528 linker sorts in increasing order. */
10529 MAX_INIT_PRIORITY - priority);
10530 section = buf;
10531 }
10532
715bdd29
RH
10533 named_section_flags (section, SECTION_WRITE);
10534 assemble_align (POINTER_SIZE);
d9f6800d
RH
10535
10536 if (TARGET_RELOCATABLE)
10537 {
10538 fputs ("\t.long (", asm_out_file);
10539 output_addr_const (asm_out_file, symbol);
10540 fputs (")@fixup\n", asm_out_file);
10541 }
10542 else
c8af3574 10543 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
10544}
10545
10546static void
10547rs6000_elf_asm_out_destructor (symbol, priority)
10548 rtx symbol;
10549 int priority;
10550{
10551 const char *section = ".dtors";
10552 char buf[16];
10553
10554 if (priority != DEFAULT_INIT_PRIORITY)
10555 {
10556 sprintf (buf, ".dtors.%.5u",
10557 /* Invert the numbering so the linker puts us in the proper
10558 order; constructors are run from right to left, and the
10559 linker sorts in increasing order. */
10560 MAX_INIT_PRIORITY - priority);
10561 section = buf;
10562 }
10563
715bdd29
RH
10564 named_section_flags (section, SECTION_WRITE);
10565 assemble_align (POINTER_SIZE);
d9f6800d
RH
10566
10567 if (TARGET_RELOCATABLE)
10568 {
10569 fputs ("\t.long (", asm_out_file);
10570 output_addr_const (asm_out_file, symbol);
10571 fputs (")@fixup\n", asm_out_file);
10572 }
10573 else
c8af3574 10574 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 10575}
7c262518
RH
10576#endif
10577
10578#ifdef OBJECT_FORMAT_COFF
10579static void
715bdd29 10580xcoff_asm_named_section (name, flags)
7c262518
RH
10581 const char *name;
10582 unsigned int flags ATTRIBUTE_UNUSED;
7c262518
RH
10583{
10584 fprintf (asm_out_file, "\t.csect %s\n", name);
10585}
10586#endif