]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* config-lang.in (lang_dirs): Add in zlib.
[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"
2a430ec1 37#include "except.h"
a7df97e6 38#include "function.h"
296b8152
KG
39#include "output.h"
40#include "toplev.h"
c8023011 41#include "ggc.h"
9ebbca7d
GK
42#include "hashtab.h"
43#include "tm_p.h"
9b30bae2 44
7509c759
MM
45#ifndef TARGET_NO_PROTOTYPE
46#define TARGET_NO_PROTOTYPE 0
47#endif
48
5248c961 49extern int profile_block_flag;
9878760c
RK
50
51#define min(A,B) ((A) < (B) ? (A) : (B))
52#define max(A,B) ((A) > (B) ? (A) : (B))
53
5248c961
RK
54/* Target cpu type */
55
56enum processor_type rs6000_cpu;
8e3f41e7
MM
57struct rs6000_cpu_select rs6000_select[3] =
58{
815cdc52
MM
59 /* switch name, tune arch */
60 { (const char *)0, "--with-cpu=", 1, 1 },
61 { (const char *)0, "-mcpu=", 1, 1 },
62 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 63};
5248c961 64
c764f757
RK
65/* Set to non-zero once AIX common-mode calls have been defined. */
66static int common_mode_defined;
c81bebd7 67
9878760c
RK
68/* Save information from a "cmpxx" operation until the branch or scc is
69 emitted. */
9878760c
RK
70rtx rs6000_compare_op0, rs6000_compare_op1;
71int rs6000_compare_fp_p;
874a0744 72
874a0744
MM
73/* Label number of label created for -mrelocatable, to call to so we can
74 get the address of the GOT section */
75int rs6000_pic_labelno;
c81bebd7 76
9ebbca7d 77#ifdef USING_SVR4_H
c81bebd7 78/* Which abi to adhere to */
815cdc52 79const char *rs6000_abi_name = RS6000_ABI_NAME;
d9407988
MM
80
81/* Semantics of the small data area */
82enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
83
84/* Which small data model to use */
815cdc52 85const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
86
87/* Counter for labels which are to be placed in .fixup. */
88int fixuplabelno = 0;
874a0744 89#endif
4697a36c 90
b6c9286a
MM
91/* ABI enumeration available for subtarget to use. */
92enum rs6000_abi rs6000_current_abi;
93
38c1f2d7 94/* Debug flags */
815cdc52 95const char *rs6000_debug_name;
38c1f2d7
MM
96int rs6000_debug_stack; /* debug stack applications */
97int rs6000_debug_arg; /* debug argument handling */
98
99/* Flag to say the TOC is initialized */
100int toc_initialized;
9ebbca7d 101char toc_label_name[10];
38c1f2d7 102
9ebbca7d
GK
103/* Alias set for saves and restores from the rs6000 stack. */
104static int rs6000_sr_alias_set;
c8023011 105
9ebbca7d
GK
106static void rs6000_add_gc_roots PARAMS ((void));
107static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
108static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx));
39a10a29
GK
109static void validate_condition_mode
110 PARAMS ((enum rtx_code, enum machine_mode));
111static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
e50f5f3d 112static void rs6000_maybe_dead PARAMS ((rtx));
9ebbca7d
GK
113static void rs6000_emit_stack_tie PARAMS ((void));
114static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
115static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
116static unsigned rs6000_hash_constant PARAMS ((rtx));
117static unsigned toc_hash_function PARAMS ((const void *));
118static int toc_hash_eq PARAMS ((const void *, const void *));
2eba1afa 119static int toc_hash_mark_entry PARAMS ((void **, void *));
9ebbca7d
GK
120static void toc_hash_mark_table PARAMS ((void *));
121static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
6fee9e99
NC
122static void rs6000_free_machine_status PARAMS ((struct function *));
123static void rs6000_init_machine_status PARAMS ((struct function *));
71f123ca
FS
124static void rs6000_mark_machine_status PARAMS ((struct function *));
125static int rs6000_ra_ever_killed PARAMS ((void));
c81bebd7
MM
126\f
127/* Default register names. */
128char rs6000_reg_names[][8] =
129{
802a0058
MM
130 "0", "1", "2", "3", "4", "5", "6", "7",
131 "8", "9", "10", "11", "12", "13", "14", "15",
132 "16", "17", "18", "19", "20", "21", "22", "23",
133 "24", "25", "26", "27", "28", "29", "30", "31",
134 "0", "1", "2", "3", "4", "5", "6", "7",
135 "8", "9", "10", "11", "12", "13", "14", "15",
136 "16", "17", "18", "19", "20", "21", "22", "23",
137 "24", "25", "26", "27", "28", "29", "30", "31",
138 "mq", "lr", "ctr","ap",
139 "0", "1", "2", "3", "4", "5", "6", "7",
9ebbca7d 140 "xer"
c81bebd7
MM
141};
142
143#ifdef TARGET_REGNAMES
144static char alt_reg_names[][8] =
145{
802a0058
MM
146 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
147 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
148 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
149 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
150 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
151 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
152 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
153 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
154 "mq", "lr", "ctr", "ap",
155 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
9ebbca7d 156 "xer"
c81bebd7
MM
157};
158#endif
9878760c 159\f
daf11973
MM
160#ifndef MASK_STRICT_ALIGN
161#define MASK_STRICT_ALIGN 0
162#endif
163
5248c961
RK
164/* Override command line options. Mostly we process the processor
165 type and sometimes adjust other TARGET_ options. */
166
167void
8e3f41e7 168rs6000_override_options (default_cpu)
d330fd93 169 const char *default_cpu;
5248c961 170{
c4d38ccb 171 size_t i, j;
8e3f41e7 172 struct rs6000_cpu_select *ptr;
5248c961 173
85638c0d
RK
174 /* Simplify the entries below by making a mask for any POWER
175 variant and any PowerPC variant. */
176
938937d8 177#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
178#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
179 | MASK_PPC_GFXOPT | MASK_POWERPC64)
180#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 181
5248c961
RK
182 static struct ptt
183 {
d330fd93 184 const char *name; /* Canonical processor name. */
5248c961
RK
185 enum processor_type processor; /* Processor type enum value. */
186 int target_enable; /* Target flags to enable. */
187 int target_disable; /* Target flags to disable. */
188 } processor_target_table[]
cf27b467
MM
189 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
190 POWER_MASKS | POWERPC_MASKS},
db7f1e43 191 {"power", PROCESSOR_POWER,
938937d8 192 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 193 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
194 {"power2", PROCESSOR_POWER,
195 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
196 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
197 {"power3", PROCESSOR_PPC630,
198 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
199 POWER_MASKS | MASK_PPC_GPOPT},
db7f1e43
RK
200 {"powerpc", PROCESSOR_POWERPC,
201 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 202 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
203 {"powerpc64", PROCESSOR_POWERPC64,
204 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
205 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 206 {"rios", PROCESSOR_RIOS1,
938937d8 207 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
208 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
209 {"rios1", PROCESSOR_RIOS1,
938937d8 210 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
211 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
212 {"rsc", PROCESSOR_PPC601,
938937d8 213 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
214 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
215 {"rsc1", PROCESSOR_PPC601,
938937d8 216 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
217 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
218 {"rios2", PROCESSOR_RIOS2,
938937d8 219 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 220 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
221 {"rs64a", PROCESSOR_RS64A,
222 MASK_POWERPC | MASK_NEW_MNEMONICS,
223 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
224 {"401", PROCESSOR_PPC403,
225 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
226 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 227 {"403", PROCESSOR_PPC403,
daf11973 228 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 229 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
230 {"505", PROCESSOR_MPCCORE,
231 MASK_POWERPC | MASK_NEW_MNEMONICS,
232 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 233 {"601", PROCESSOR_PPC601,
938937d8 234 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 235 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 236 {"602", PROCESSOR_PPC603,
cf27b467
MM
237 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
238 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 239 {"603", PROCESSOR_PPC603,
68c49ffa
RK
240 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
241 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
242 {"603e", PROCESSOR_PPC603,
243 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
244 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 245 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
246 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
247 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 248 {"604", PROCESSOR_PPC604,
b6c9286a
MM
249 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
250 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 251 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
252 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
253 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 254 {"620", PROCESSOR_PPC620,
68c49ffa 255 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a260abc9 256 POWER_MASKS | MASK_PPC_GPOPT},
3cb999d8
DE
257 {"630", PROCESSOR_PPC630,
258 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
259 POWER_MASKS | MASK_PPC_GPOPT},
bef84347
VM
260 {"740", PROCESSOR_PPC750,
261 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
262 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
263 {"750", PROCESSOR_PPC750,
264 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
265 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
266 {"801", PROCESSOR_MPCCORE,
267 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
268 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
269 {"821", PROCESSOR_MPCCORE,
270 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
271 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
272 {"823", PROCESSOR_MPCCORE,
273 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
274 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
275 {"860", PROCESSOR_MPCCORE,
276 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
277 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 278
c4d38ccb 279 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
5248c961 280
8a61d227 281 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
938937d8 282 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
8a61d227 283
5248c961
RK
284 profile_block_flag = 0;
285
286 /* Identify the processor type */
8e3f41e7 287 rs6000_select[0].string = default_cpu;
3cb999d8 288 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 289
b6a1cbae 290 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 291 {
8e3f41e7
MM
292 ptr = &rs6000_select[i];
293 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 294 {
8e3f41e7
MM
295 for (j = 0; j < ptt_size; j++)
296 if (! strcmp (ptr->string, processor_target_table[j].name))
297 {
298 if (ptr->set_tune_p)
299 rs6000_cpu = processor_target_table[j].processor;
300
301 if (ptr->set_arch_p)
302 {
303 target_flags |= processor_target_table[j].target_enable;
304 target_flags &= ~processor_target_table[j].target_disable;
305 }
306 break;
307 }
308
4406229e 309 if (j == ptt_size)
8e3f41e7 310 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
311 }
312 }
8a61d227 313
ef792183
MM
314 /* If we are optimizing big endian systems for space, use the
315 store multiple instructions. */
316 if (BYTES_BIG_ENDIAN && optimize_size)
317 target_flags |= MASK_MULTIPLE;
318
8a61d227
MM
319 /* If -mmultiple or -mno-multiple was explicitly used, don't
320 override with the processor default */
321 if (TARGET_MULTIPLE_SET)
322 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 323
938937d8
MM
324 /* If -mstring or -mno-string was explicitly used, don't
325 override with the processor default */
326 if (TARGET_STRING_SET)
1f5515bf 327 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 328
bef84347
VM
329 /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu
330 is a 750, because the hardware doesn't support the instructions used in
331 little endian mode, and causes an alignment trap. The 750 does not cause
332 an alignment trap (except when the target is unaligned). */
333
bfc79d3b 334 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
335 {
336 if (TARGET_MULTIPLE)
337 {
338 target_flags &= ~MASK_MULTIPLE;
339 if (TARGET_MULTIPLE_SET)
340 warning ("-mmultiple is not supported on little endian systems");
341 }
342
343 if (TARGET_STRING)
344 {
345 target_flags &= ~MASK_STRING;
938937d8
MM
346 if (TARGET_STRING_SET)
347 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
348 }
349 }
3933e0e1 350
a260abc9
DE
351 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
352 {
353 warning ("-f%s ignored for AIX (all code is position independent)",
354 (flag_pic > 1) ? "PIC" : "pic");
355 flag_pic = 0;
356 }
357
9861b0c9
DE
358 if (flag_function_sections && (write_symbols != NO_DEBUG)
359 && (DEFAULT_ABI == ABI_AIX))
360 {
361 warning ("-ffunction-sections disabled on AIX when debugging");
362 flag_function_sections = 0;
363 }
364
365 if (flag_data_sections && (DEFAULT_ABI == ABI_AIX))
366 {
367 warning ("-fdata-sections not supported on AIX");
368 flag_data_sections = 0;
369 }
370
38c1f2d7
MM
371 /* Set debug flags */
372 if (rs6000_debug_name)
373 {
bfc79d3b 374 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 375 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 376 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 377 rs6000_debug_stack = 1;
bfc79d3b 378 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
379 rs6000_debug_arg = 1;
380 else
381 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
382 }
383
c81bebd7
MM
384#ifdef TARGET_REGNAMES
385 /* If the user desires alternate register names, copy in the alternate names
386 now. */
387 if (TARGET_REGNAMES)
4e135bdd 388 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
389#endif
390
3933e0e1
MM
391#ifdef SUBTARGET_OVERRIDE_OPTIONS
392 SUBTARGET_OVERRIDE_OPTIONS;
393#endif
c8023011
MM
394
395 /* Register global variables with the garbage collector. */
396 rs6000_add_gc_roots ();
9ebbca7d
GK
397
398 /* Allocate an alias set for register saves & restores from stack. */
399 rs6000_sr_alias_set = new_alias_set ();
400
401 if (TARGET_TOC)
402 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca
FS
403
404 /* Arrange to save and restore machine status around nested functions. */
405 init_machine_status = rs6000_init_machine_status;
406 mark_machine_status = rs6000_mark_machine_status;
407 free_machine_status = rs6000_free_machine_status;
5248c961 408}
5accd822
DE
409
410void
411optimization_options (level, size)
e2c953b6 412 int level ATTRIBUTE_UNUSED;
5accd822
DE
413 int size ATTRIBUTE_UNUSED;
414{
5accd822 415}
3cfa4909
MM
416\f
417/* Do anything needed at the start of the asm file. */
418
419void
420rs6000_file_start (file, default_cpu)
421 FILE *file;
d330fd93 422 const char *default_cpu;
3cfa4909 423{
c4d38ccb 424 size_t i;
3cfa4909 425 char buffer[80];
d330fd93 426 const char *start = buffer;
3cfa4909
MM
427 struct rs6000_cpu_select *ptr;
428
429 if (flag_verbose_asm)
430 {
431 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
432 rs6000_select[0].string = default_cpu;
433
b6a1cbae 434 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
435 {
436 ptr = &rs6000_select[i];
437 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
438 {
439 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
440 start = "";
441 }
442 }
443
444#ifdef USING_SVR4_H
445 switch (rs6000_sdata)
446 {
447 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
448 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
449 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
450 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
451 }
452
453 if (rs6000_sdata && g_switch_value)
454 {
455 fprintf (file, "%s -G %d", start, g_switch_value);
456 start = "";
457 }
458#endif
459
460 if (*start == '\0')
949ea356 461 putc ('\n', file);
3cfa4909
MM
462 }
463}
464
24d304eb
RK
465\f
466/* Create a CONST_DOUBLE from a string. */
467
468struct rtx_def *
469rs6000_float_const (string, mode)
d330fd93 470 const char *string;
24d304eb
RK
471 enum machine_mode mode;
472{
ca5adc63
GK
473 REAL_VALUE_TYPE value;
474 value = REAL_VALUE_ATOF (string, mode);
24d304eb
RK
475 return immed_real_const_1 (value, mode);
476}
5248c961 477\f
9878760c
RK
478/* Return non-zero if this function is known to have a null epilogue. */
479
480int
481direct_return ()
482{
4697a36c
MM
483 if (reload_completed)
484 {
485 rs6000_stack_t *info = rs6000_stack_info ();
486
487 if (info->first_gp_reg_save == 32
488 && info->first_fp_reg_save == 64
c81fc13e
DE
489 && ! info->lr_save_p
490 && ! info->cr_save_p
491 && ! info->push_p)
4697a36c
MM
492 return 1;
493 }
494
495 return 0;
9878760c
RK
496}
497
498/* Returns 1 always. */
499
500int
501any_operand (op, mode)
296b8152
KG
502 register rtx op ATTRIBUTE_UNUSED;
503 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
504{
505 return 1;
506}
507
b6c9286a 508/* Returns 1 if op is the count register */
38c1f2d7
MM
509int
510count_register_operand(op, mode)
b6c9286a 511 register rtx op;
296b8152 512 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
513{
514 if (GET_CODE (op) != REG)
515 return 0;
516
517 if (REGNO (op) == COUNT_REGISTER_REGNUM)
518 return 1;
519
520 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
521 return 1;
522
523 return 0;
524}
525
38c1f2d7 526int
9ebbca7d 527xer_operand(op, mode)
802a0058 528 register rtx op;
296b8152 529 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
530{
531 if (GET_CODE (op) != REG)
532 return 0;
533
9ebbca7d 534 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
535 return 1;
536
802a0058
MM
537 return 0;
538}
539
9878760c
RK
540/* Return 1 if OP is a constant that can fit in a D field. */
541
542int
543short_cint_operand (op, mode)
544 register rtx op;
296b8152 545 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 546{
5f59ecb7
DE
547 return (GET_CODE (op) == CONST_INT
548 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
549}
550
551/* Similar for a unsigned D field. */
552
553int
554u_short_cint_operand (op, mode)
555 register rtx op;
296b8152 556 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 557{
19684119 558 return (GET_CODE (op) == CONST_INT
5f59ecb7 559 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
9878760c
RK
560}
561
dcfedcd0
RK
562/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
563
564int
565non_short_cint_operand (op, mode)
566 register rtx op;
296b8152 567 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
568{
569 return (GET_CODE (op) == CONST_INT
a7653a2c 570 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
571}
572
9878760c
RK
573/* Returns 1 if OP is a register that is not special (i.e., not MQ,
574 ctr, or lr). */
575
576int
cd2b37d9 577gpc_reg_operand (op, mode)
9878760c
RK
578 register rtx op;
579 enum machine_mode mode;
580{
581 return (register_operand (op, mode)
802a0058 582 && (GET_CODE (op) != REG
9ebbca7d
GK
583 || (REGNO (op) >= ARG_POINTER_REGNUM
584 && !XER_REGNO_P (REGNO (op)))
585 || REGNO (op) < MQ_REGNO));
9878760c
RK
586}
587
588/* Returns 1 if OP is either a pseudo-register or a register denoting a
589 CR field. */
590
591int
592cc_reg_operand (op, mode)
593 register rtx op;
594 enum machine_mode mode;
595{
596 return (register_operand (op, mode)
597 && (GET_CODE (op) != REG
598 || REGNO (op) >= FIRST_PSEUDO_REGISTER
599 || CR_REGNO_P (REGNO (op))));
600}
601
815cdc52
MM
602/* Returns 1 if OP is either a pseudo-register or a register denoting a
603 CR field that isn't CR0. */
604
605int
606cc_reg_not_cr0_operand (op, mode)
607 register rtx op;
608 enum machine_mode mode;
609{
610 return (register_operand (op, mode)
611 && (GET_CODE (op) != REG
612 || REGNO (op) >= FIRST_PSEUDO_REGISTER
613 || CR_REGNO_NOT_CR0_P (REGNO (op))));
614}
615
9878760c
RK
616/* Returns 1 if OP is either a constant integer valid for a D-field or a
617 non-special register. If a register, it must be in the proper mode unless
618 MODE is VOIDmode. */
619
620int
621reg_or_short_operand (op, mode)
622 register rtx op;
623 enum machine_mode mode;
624{
f5a28898 625 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
626}
627
628/* Similar, except check if the negation of the constant would be valid for
629 a D-field. */
630
631int
632reg_or_neg_short_operand (op, mode)
633 register rtx op;
634 enum machine_mode mode;
635{
636 if (GET_CODE (op) == CONST_INT)
637 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
638
cd2b37d9 639 return gpc_reg_operand (op, mode);
9878760c
RK
640}
641
642/* Return 1 if the operand is either a register or an integer whose high-order
643 16 bits are zero. */
644
645int
646reg_or_u_short_operand (op, mode)
647 register rtx op;
648 enum machine_mode mode;
649{
e675f625 650 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
651}
652
653/* Return 1 is the operand is either a non-special register or ANY
654 constant integer. */
655
656int
657reg_or_cint_operand (op, mode)
658 register rtx op;
659 enum machine_mode mode;
660{
f6bf7de2
DE
661 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
662}
663
664/* Return 1 is the operand is either a non-special register or ANY
665 32-bit signed constant integer. */
666
667int
668reg_or_arith_cint_operand (op, mode)
669 register rtx op;
670 enum machine_mode mode;
671{
672 return (gpc_reg_operand (op, mode)
673 || (GET_CODE (op) == CONST_INT
674#if HOST_BITS_PER_WIDE_INT != 32
675 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
676 < 0x100000000u)
677#endif
678 ));
9878760c
RK
679}
680
9ebbca7d
GK
681/* Return 1 is the operand is either a non-special register or ANY
682 32-bit unsigned constant integer. */
683
684int
1d328b19 685reg_or_logical_cint_operand (op, mode)
9ebbca7d
GK
686 register rtx op;
687 enum machine_mode mode;
688{
1d328b19
GK
689 if (GET_CODE (op) == CONST_INT)
690 {
691 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
692 {
693 if (GET_MODE_BITSIZE (mode) <= 32)
694 abort();
695
696 if (INTVAL (op) < 0)
697 return 0;
698 }
699
700 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 701 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
702 }
703 else if (GET_CODE (op) == CONST_DOUBLE)
704 {
705 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
706 || mode != DImode)
707 abort();
708
709 return CONST_DOUBLE_HIGH (op) == 0;
710 }
711 else
712 return gpc_reg_operand (op, mode);
9ebbca7d
GK
713}
714
766a866c
MM
715/* Return 1 if the operand is an operand that can be loaded via the GOT */
716
717int
718got_operand (op, mode)
719 register rtx op;
296b8152 720 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
721{
722 return (GET_CODE (op) == SYMBOL_REF
723 || GET_CODE (op) == CONST
724 || GET_CODE (op) == LABEL_REF);
725}
726
38c1f2d7
MM
727/* Return 1 if the operand is a simple references that can be loaded via
728 the GOT (labels involving addition aren't allowed). */
729
730int
731got_no_const_operand (op, mode)
732 register rtx op;
296b8152 733 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
734{
735 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
736}
737
4e74d8ec
MM
738/* Return the number of instructions it takes to form a constant in an
739 integer register. */
740
741static int
742num_insns_constant_wide (value)
743 HOST_WIDE_INT value;
744{
745 /* signed constant loadable with {cal|addi} */
5f59ecb7 746 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
747 return 1;
748
4e74d8ec 749 /* constant loadable with {cau|addis} */
5f59ecb7 750 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
751 return 1;
752
5f59ecb7 753#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 754 else if (TARGET_POWERPC64)
4e74d8ec 755 {
0858c623 756 unsigned HOST_WIDE_INT low = value & 0xffffffff;
4e74d8ec
MM
757 HOST_WIDE_INT high = value >> 32;
758
0858c623 759 if (high == 0 && (low & 0x80000000) == 0)
4e74d8ec
MM
760 return 2;
761
0858c623 762 else if (high == -1 && (low & 0x80000000) != 0)
4e74d8ec
MM
763 return 2;
764
c81fc13e 765 else if (! low)
4e74d8ec
MM
766 return num_insns_constant_wide (high) + 1;
767
768 else
769 return (num_insns_constant_wide (high)
e396202a 770 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
771 }
772#endif
773
774 else
775 return 2;
776}
777
778int
779num_insns_constant (op, mode)
780 rtx op;
781 enum machine_mode mode;
782{
4e74d8ec
MM
783 if (GET_CODE (op) == CONST_INT)
784 return num_insns_constant_wide (INTVAL (op));
785
6fc48950
MM
786 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
787 {
788 long l;
789 REAL_VALUE_TYPE rv;
790
791 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
792 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
793 return num_insns_constant_wide ((HOST_WIDE_INT)l);
794 }
795
47ad8c61 796 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 797 {
47ad8c61
MM
798 HOST_WIDE_INT low;
799 HOST_WIDE_INT high;
800 long l[2];
801 REAL_VALUE_TYPE rv;
802 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 803
47ad8c61
MM
804 if (mode == VOIDmode || mode == DImode)
805 {
806 high = CONST_DOUBLE_HIGH (op);
807 low = CONST_DOUBLE_LOW (op);
808 }
809 else
810 {
811 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
812 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
813 high = l[endian];
814 low = l[1 - endian];
815 }
4e74d8ec 816
47ad8c61
MM
817 if (TARGET_32BIT)
818 return (num_insns_constant_wide (low)
819 + num_insns_constant_wide (high));
4e74d8ec
MM
820
821 else
47ad8c61 822 {
0858c623 823 if (high == 0 && (low & 0x80000000) == 0)
47ad8c61
MM
824 return num_insns_constant_wide (low);
825
0858c623 826 else if (high == -1 && (low & 0x80000000) != 0)
47ad8c61
MM
827 return num_insns_constant_wide (low);
828
a260abc9
DE
829 else if (mask64_operand (op, mode))
830 return 2;
831
47ad8c61
MM
832 else if (low == 0)
833 return num_insns_constant_wide (high) + 1;
834
835 else
836 return (num_insns_constant_wide (high)
837 + num_insns_constant_wide (low) + 1);
838 }
4e74d8ec
MM
839 }
840
841 else
842 abort ();
843}
844
6f2f8311
RK
845/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
846 with one instruction per word. We only do this if we can safely read
847 CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
848
849int
850easy_fp_constant (op, mode)
851 register rtx op;
852 register enum machine_mode mode;
853{
9878760c
RK
854 if (GET_CODE (op) != CONST_DOUBLE
855 || GET_MODE (op) != mode
4e74d8ec 856 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
857 return 0;
858
b6c9286a 859 /* Consider all constants with -msoft-float to be easy */
4e74d8ec 860 if (TARGET_SOFT_FLOAT && mode != DImode)
b6c9286a
MM
861 return 1;
862
a7273471
MM
863 /* If we are using V.4 style PIC, consider all constants to be hard */
864 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
865 return 0;
866
5ae4759c
MM
867#ifdef TARGET_RELOCATABLE
868 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
869 if (TARGET_RELOCATABLE)
870 return 0;
871#endif
872
042259f2
DE
873 if (mode == DFmode)
874 {
875 long k[2];
876 REAL_VALUE_TYPE rv;
877
878 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
879 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 880
4e74d8ec
MM
881 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
882 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
042259f2 883 }
4e74d8ec
MM
884
885 else if (mode == SFmode)
042259f2
DE
886 {
887 long l;
888 REAL_VALUE_TYPE rv;
889
890 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
891 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 892
4e74d8ec 893 return num_insns_constant_wide (l) == 1;
042259f2 894 }
4e74d8ec 895
a260abc9 896 else if (mode == DImode)
c81fc13e 897 return ((TARGET_POWERPC64
a260abc9
DE
898 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
899 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 900
a9098fd0
GK
901 else if (mode == SImode)
902 return 1;
4e74d8ec
MM
903 else
904 abort ();
9878760c 905}
8f75773e 906
b6c9286a
MM
907/* Return 1 if the operand is in volatile memory. Note that during the
908 RTL generation phase, memory_operand does not return TRUE for
909 volatile memory references. So this function allows us to
910 recognize volatile references where its safe. */
911
912int
913volatile_mem_operand (op, mode)
914 register rtx op;
915 enum machine_mode mode;
916{
917 if (GET_CODE (op) != MEM)
918 return 0;
919
920 if (!MEM_VOLATILE_P (op))
921 return 0;
922
923 if (mode != GET_MODE (op))
924 return 0;
925
926 if (reload_completed)
927 return memory_operand (op, mode);
928
929 if (reload_in_progress)
930 return strict_memory_address_p (mode, XEXP (op, 0));
931
932 return memory_address_p (mode, XEXP (op, 0));
933}
934
97f6e72f 935/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
936
937int
97f6e72f 938offsettable_mem_operand (op, mode)
914c2e77
RK
939 register rtx op;
940 enum machine_mode mode;
941{
97f6e72f 942 return ((GET_CODE (op) == MEM)
677a9668 943 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 944 mode, XEXP (op, 0)));
914c2e77
RK
945}
946
9878760c
RK
947/* Return 1 if the operand is either an easy FP constant (see above) or
948 memory. */
949
950int
951mem_or_easy_const_operand (op, mode)
952 register rtx op;
953 enum machine_mode mode;
954{
955 return memory_operand (op, mode) || easy_fp_constant (op, mode);
956}
957
958/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 959 that can be used as the operand of a `mode' add insn. */
9878760c
RK
960
961int
962add_operand (op, mode)
963 register rtx op;
964 enum machine_mode mode;
965{
966 return (reg_or_short_operand (op, mode)
19684119 967 || (GET_CODE (op) == CONST_INT
5f59ecb7 968 && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')));
9878760c
RK
969}
970
dcfedcd0
RK
971/* Return 1 if OP is a constant but not a valid add_operand. */
972
973int
974non_add_cint_operand (op, mode)
975 register rtx op;
296b8152 976 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
977{
978 return (GET_CODE (op) == CONST_INT
a7653a2c 979 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
5f59ecb7 980 && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'));
dcfedcd0
RK
981}
982
9878760c
RK
983/* Return 1 if the operand is a non-special register or a constant that
984 can be used as the operand of an OR or XOR insn on the RS/6000. */
985
986int
987logical_operand (op, mode)
988 register rtx op;
989 enum machine_mode mode;
990{
1d328b19
GK
991 /* an unsigned representation of 'op'. */
992 unsigned HOST_WIDE_INT opl, oph;
993
dfbdccdb
GK
994 if (gpc_reg_operand (op, mode))
995 return 1;
1d328b19 996
dfbdccdb
GK
997 if (GET_CODE (op) == CONST_INT)
998 {
1d328b19
GK
999 opl = INTVAL (op) & GET_MODE_MASK (mode);
1000 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1001 oph = 0;
1002 else
1003 oph = INTVAL (op) >> (HOST_BITS_PER_WIDE_INT - 1);
dfbdccdb
GK
1004 }
1005 else if (GET_CODE (op) == CONST_DOUBLE)
1006 {
1d328b19
GK
1007 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1008 abort();
1009
1010 opl = CONST_DOUBLE_LOW (op);
1011 oph = CONST_DOUBLE_HIGH (op);
dfbdccdb
GK
1012 }
1013 else
1014 return 0;
1d328b19
GK
1015
1016 return (oph == 0
1017 && ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
0858c623 1018 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0));
9878760c
RK
1019}
1020
dcfedcd0 1021/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1022 above), but could be split into one. */
dcfedcd0
RK
1023
1024int
1025non_logical_cint_operand (op, mode)
1026 register rtx op;
5f59ecb7 1027 enum machine_mode mode;
dcfedcd0 1028{
dfbdccdb 1029 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1030 && ! logical_operand (op, mode)
1031 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1032}
1033
19ba8161 1034/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1035 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1036 Reject all ones and all zeros, since these should have been optimized
1037 away and confuse the making of MB and ME. */
1038
1039int
19ba8161
DE
1040mask_operand (op, mode)
1041 register rtx op;
1042 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1043{
19ba8161 1044 HOST_WIDE_INT c;
9878760c
RK
1045 int i;
1046 int last_bit_value;
1047 int transitions = 0;
1048
19ba8161
DE
1049 if (GET_CODE (op) != CONST_INT)
1050 return 0;
1051
1052 c = INTVAL (op);
1053
9878760c
RK
1054 if (c == 0 || c == ~0)
1055 return 0;
1056
1057 last_bit_value = c & 1;
1058
1059 for (i = 1; i < 32; i++)
1060 if (((c >>= 1) & 1) != last_bit_value)
1061 last_bit_value ^= 1, transitions++;
1062
1063 return transitions <= 2;
1064}
1065
a260abc9
DE
1066/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1067 It is if there are no more than one 1->0 or 0->1 transitions.
1068 Reject all ones and all zeros, since these should have been optimized
1069 away and confuse the making of MB and ME. */
9878760c
RK
1070
1071int
a260abc9
DE
1072mask64_operand (op, mode)
1073 register rtx op;
1074 enum machine_mode mode;
1075{
1076 if (GET_CODE (op) == CONST_INT)
1077 {
1078 HOST_WIDE_INT c = INTVAL (op);
1079 int i;
1080 int last_bit_value;
1081 int transitions = 0;
1082
1083 if (c == 0 || c == ~0)
1084 return 0;
1085
1086 last_bit_value = c & 1;
1087
1088 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1089 if (((c >>= 1) & 1) != last_bit_value)
1090 last_bit_value ^= 1, transitions++;
1091
e2c953b6
DE
1092 return transitions <= 1;
1093 }
1094 else if (GET_CODE (op) == CONST_DOUBLE
1095 && (mode == VOIDmode || mode == DImode))
1096 {
1097 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1098#if HOST_BITS_PER_WIDE_INT == 32
1099 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1100#endif
1101 int i;
1102 int last_bit_value;
1103 int transitions = 0;
1104
1105 if ((low == 0
1106#if HOST_BITS_PER_WIDE_INT == 32
1107 && high == 0
1108#endif
1109 )
1110 || (low == ~0
1111#if HOST_BITS_PER_WIDE_INT == 32
1112 && high == ~0
1113#endif
1114 ))
1115 return 0;
1116
1117 last_bit_value = low & 1;
1118
1119 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1120 if (((low >>= 1) & 1) != last_bit_value)
1121 last_bit_value ^= 1, transitions++;
1122
a238cd8b 1123#if HOST_BITS_PER_WIDE_INT == 32
e2c953b6
DE
1124 if ((high & 1) != last_bit_value)
1125 last_bit_value ^= 1, transitions++;
1126
1127 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1128 if (((high >>= 1) & 1) != last_bit_value)
1129 last_bit_value ^= 1, transitions++;
a260abc9
DE
1130#endif
1131
1132 return transitions <= 1;
1133 }
e2c953b6
DE
1134 else
1135 return 0;
1136}
1137
1138/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1139 It is if there are no more than two 1->0 or 0->1 transitions.
1140 Reject all ones and all zeros, since these should have been optimized
1141 away and confuse the making of MB and ME. */
1142
1143int
1144rldic_operand (op, mode)
1145 register rtx op;
1146 enum machine_mode mode;
1147{
1148 if (GET_CODE (op) == CONST_INT)
1149 {
1150 HOST_WIDE_INT c = INTVAL (op);
1151 int i;
1152 int last_bit_value;
1153 int transitions = 0;
1154
1155 if (c == 0 || c == ~0)
1156 return 0;
1157
1158 last_bit_value = c & 1;
1159
1160 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1161 if (((c >>= 1) & 1) != last_bit_value)
1162 last_bit_value ^= 1, transitions++;
1163
1164 return transitions <= 2;
1165 }
a260abc9
DE
1166 else if (GET_CODE (op) == CONST_DOUBLE
1167 && (mode == VOIDmode || mode == DImode))
1168 {
1169 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
a238cd8b 1170#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
1171 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1172#endif
1173 int i;
1174 int last_bit_value;
1175 int transitions = 0;
1176
1177 if ((low == 0
a238cd8b 1178#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
1179 && high == 0
1180#endif
1181 )
1182 || (low == ~0
a238cd8b 1183#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
1184 && high == ~0
1185#endif
1186 ))
1187 return 0;
1188
1189 last_bit_value = low & 1;
1190
1191 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1192 if (((low >>= 1) & 1) != last_bit_value)
1193 last_bit_value ^= 1, transitions++;
1194
a238cd8b 1195#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
1196 if ((high & 1) != last_bit_value)
1197 last_bit_value ^= 1, transitions++;
1198
1199 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1200 if (((high >>= 1) & 1) != last_bit_value)
1201 last_bit_value ^= 1, transitions++;
1202#endif
1203
e2c953b6 1204 return transitions <= 2;
a260abc9
DE
1205 }
1206 else
1207 return 0;
1208}
1209
1210/* Return 1 if the operand is either a non-special register or a constant
1211 that can be used as the operand of a PowerPC64 logical AND insn. */
1212
1213int
1214and64_operand (op, mode)
9878760c
RK
1215 register rtx op;
1216 enum machine_mode mode;
1217{
9ebbca7d 1218 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1219 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1220
1221 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
1222}
1223
a260abc9
DE
1224/* Return 1 if the operand is either a non-special register or a
1225 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1226
1227int
a260abc9
DE
1228and_operand (op, mode)
1229 register rtx op;
1230 enum machine_mode mode;
dcfedcd0 1231{
9ebbca7d 1232 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1233 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1234
1235 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
1236}
1237
9878760c
RK
1238/* Return 1 if the operand is a general register or memory operand. */
1239
1240int
1241reg_or_mem_operand (op, mode)
1242 register rtx op;
1243 register enum machine_mode mode;
1244{
b6c9286a
MM
1245 return (gpc_reg_operand (op, mode)
1246 || memory_operand (op, mode)
1247 || volatile_mem_operand (op, mode));
9878760c
RK
1248}
1249
a7a813f7 1250/* Return 1 if the operand is a general register or memory operand without
3cb999d8 1251 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
1252 instruction. */
1253
1254int
1255lwa_operand (op, mode)
1256 register rtx op;
1257 register enum machine_mode mode;
1258{
1259 rtx inner = op;
1260
1261 if (reload_completed && GET_CODE (inner) == SUBREG)
1262 inner = SUBREG_REG (inner);
1263
1264 return gpc_reg_operand (inner, mode)
1265 || (memory_operand (inner, mode)
1266 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1267 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1268}
1269
9878760c
RK
1270/* Return 1 if the operand, used inside a MEM, is a valid first argument
1271 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1272 forced to lr. */
1273
1274int
1275call_operand (op, mode)
1276 register rtx op;
1277 enum machine_mode mode;
1278{
1279 if (mode != VOIDmode && GET_MODE (op) != mode)
1280 return 0;
1281
1282 return (GET_CODE (op) == SYMBOL_REF
1283 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1284}
1285
2af3d377
RK
1286
1287/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
8f1b829e 1288 this file and the function is not weakly defined. */
2af3d377
RK
1289
1290int
1291current_file_function_operand (op, mode)
1292 register rtx op;
296b8152 1293 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1294{
1295 return (GET_CODE (op) == SYMBOL_REF
1296 && (SYMBOL_REF_FLAG (op)
8f1b829e 1297 || (op == XEXP (DECL_RTL (current_function_decl), 0)
c81fc13e 1298 && ! DECL_WEAK (current_function_decl))));
2af3d377
RK
1299}
1300
1301
9878760c
RK
1302/* Return 1 if this operand is a valid input for a move insn. */
1303
1304int
1305input_operand (op, mode)
1306 register rtx op;
1307 enum machine_mode mode;
1308{
eb4e8003 1309 /* Memory is always valid. */
9878760c
RK
1310 if (memory_operand (op, mode))
1311 return 1;
1312
34792e82 1313 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 1314 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
1315 return 1;
1316
eb4e8003
RK
1317 /* For floating-point, easy constants are valid. */
1318 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1319 && CONSTANT_P (op)
1320 && easy_fp_constant (op, mode))
1321 return 1;
1322
4e74d8ec
MM
1323 /* Allow any integer constant. */
1324 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 1325 && (GET_CODE (op) == CONST_INT
e675f625 1326 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1327 return 1;
1328
eb4e8003
RK
1329 /* For floating-point or multi-word mode, the only remaining valid type
1330 is a register. */
9878760c
RK
1331 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1332 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1333 return register_operand (op, mode);
9878760c 1334
88fe15a1
RK
1335 /* The only cases left are integral modes one word or smaller (we
1336 do not get called for MODE_CC values). These can be in any
1337 register. */
1338 if (register_operand (op, mode))
a8b3aeda 1339 return 1;
88fe15a1 1340
84cf9dda 1341 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 1342 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
1343 return 1;
1344
9ebbca7d
GK
1345 /* A constant pool expression (relative to the TOC) is valid */
1346 if (TOC_RELATIVE_EXPR_P (op))
b6c9286a
MM
1347 return 1;
1348
88228c4b
MM
1349 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1350 to be valid. */
c81bebd7 1351 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
88228c4b
MM
1352 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1353 && small_data_operand (op, Pmode))
1354 return 1;
1355
042259f2 1356 return 0;
9878760c 1357}
7509c759
MM
1358
1359/* Return 1 for an operand in small memory on V.4/eabi */
1360
1361int
1362small_data_operand (op, mode)
296b8152
KG
1363 rtx op ATTRIBUTE_UNUSED;
1364 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 1365{
38c1f2d7 1366#if TARGET_ELF
5f59ecb7 1367 rtx sym_ref;
7509c759 1368
d9407988 1369 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 1370 return 0;
a54d04b7 1371
5b9d9a0c 1372 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
7509c759
MM
1373 return 0;
1374
88228c4b
MM
1375 if (GET_CODE (op) == SYMBOL_REF)
1376 sym_ref = op;
1377
1378 else if (GET_CODE (op) != CONST
1379 || GET_CODE (XEXP (op, 0)) != PLUS
1380 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1381 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
1382 return 0;
1383
88228c4b 1384 else
dbf55e53
MM
1385 {
1386 rtx sum = XEXP (op, 0);
1387 HOST_WIDE_INT summand;
1388
1389 /* We have to be careful here, because it is the referenced address
1390 that must be 32k from _SDA_BASE_, not just the symbol. */
1391 summand = INTVAL (XEXP (sum, 1));
1392 if (summand < 0 || summand > g_switch_value)
1393 return 0;
1394
1395 sym_ref = XEXP (sum, 0);
1396 }
88228c4b
MM
1397
1398 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
1399 return 0;
1400
1401 return 1;
d9407988
MM
1402
1403#else
1404 return 0;
1405#endif
7509c759 1406}
9ebbca7d
GK
1407\f
1408static int
1409constant_pool_expr_1 (op, have_sym, have_toc)
1410 rtx op;
1411 int *have_sym;
1412 int *have_toc;
1413{
1414 switch (GET_CODE(op))
1415 {
1416 case SYMBOL_REF:
1417 if (CONSTANT_POOL_ADDRESS_P (op))
1418 {
a9098fd0 1419 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
9ebbca7d
GK
1420 {
1421 *have_sym = 1;
1422 return 1;
1423 }
1424 else
1425 return 0;
1426 }
1427 else if (! strcmp (XSTR (op, 0), toc_label_name))
1428 {
1429 *have_toc = 1;
1430 return 1;
1431 }
1432 else
1433 return 0;
1434 case PLUS:
1435 case MINUS:
1436 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) &&
1437 constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc);
1438 case CONST:
1439 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
1440 case CONST_INT:
1441 return 1;
1442 default:
1443 return 0;
1444 }
1445}
1446
1447int
1448constant_pool_expr_p (op)
1449 rtx op;
1450{
1451 int have_sym = 0;
1452 int have_toc = 0;
1453 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
1454}
1455
1456int
1457toc_relative_expr_p (op)
1458 rtx op;
1459{
1460 int have_sym = 0;
1461 int have_toc = 0;
1462 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
1463}
1464
1465/* Try machine-dependent ways of modifying an illegitimate address
1466 to be legitimate. If we find one, return the new, valid address.
1467 This is used from only one place: `memory_address' in explow.c.
1468
1469 OLDX is the address as it was before break_out_memory_refs was called.
1470 In some cases it is useful to look at this to decide what needs to be done.
1471
1472 MODE is passed so that this macro can use GO_IF_LEGITIMATE_ADDRESS.
1473
1474 It is always safe for this macro to do nothing. It exists to recognize
1475 opportunities to optimize the output.
1476
1477 On RS/6000, first check for the sum of a register with a constant
1478 integer that is out of range. If so, generate code to add the
1479 constant with the low-order 16 bits masked to the register and force
1480 this result into another register (this can be done with `cau').
1481 Then generate an address of REG+(CONST&0xffff), allowing for the
1482 possibility of bit 16 being a one.
1483
1484 Then check for the sum of a register and something not constant, try to
1485 load the other things into a register and return the sum. */
1486rtx
1487rs6000_legitimize_address (x, oldx, mode)
1488 rtx x;
1489 rtx oldx ATTRIBUTE_UNUSED;
1490 enum machine_mode mode;
1491{
1492 if (GET_CODE (x) == PLUS
1493 && GET_CODE (XEXP (x, 0)) == REG
1494 && GET_CODE (XEXP (x, 1)) == CONST_INT
1495 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
1496 {
1497 HOST_WIDE_INT high_int, low_int;
1498 rtx sum;
1499 high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff);
1500 low_int = INTVAL (XEXP (x, 1)) & 0xffff;
1501 if (low_int & 0x8000)
1502 high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
1503 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
1504 GEN_INT (high_int)), 0);
1505 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
1506 }
1507 else if (GET_CODE (x) == PLUS
1508 && GET_CODE (XEXP (x, 0)) == REG
1509 && GET_CODE (XEXP (x, 1)) != CONST_INT
1510 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1511 && (TARGET_POWERPC64 || mode != DImode)
1512 && mode != TImode)
1513 {
1514 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
1515 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
1516 }
1517 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
1518 && GET_CODE (x) != CONST_INT
1519 && GET_CODE (x) != CONST_DOUBLE
1520 && CONSTANT_P (x)
1521 && (TARGET_HARD_FLOAT || mode != DFmode)
1522 && mode != DImode
1523 && mode != TImode)
1524 {
1525 rtx reg = gen_reg_rtx (Pmode);
1526 emit_insn (gen_elf_high (reg, (x)));
1527 return gen_rtx_LO_SUM (Pmode, reg, (x));
1528 }
ee890fe2
SS
1529 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
1530 && ! flag_pic
1531 && GET_CODE (x) != CONST_INT
1532 && GET_CODE (x) != CONST_DOUBLE
1533 && CONSTANT_P (x)
1534 && (TARGET_HARD_FLOAT || mode != DFmode)
1535 && mode != DImode
1536 && mode != TImode)
1537 {
1538 rtx reg = gen_reg_rtx (Pmode);
1539 emit_insn (gen_macho_high (reg, (x)));
1540 return gen_rtx_LO_SUM (Pmode, reg, (x));
1541 }
9ebbca7d
GK
1542 else if (TARGET_TOC
1543 && CONSTANT_POOL_EXPR_P (x)
a9098fd0 1544 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
1545 {
1546 return create_TOC_reference (x);
1547 }
1548 else
1549 return NULL_RTX;
1550}
fb4d4348
GK
1551\f
1552/* Emit a move from SOURCE to DEST in mode MODE. */
1553void
1554rs6000_emit_move (dest, source, mode)
1555 rtx dest;
1556 rtx source;
1557 enum machine_mode mode;
1558{
1559 rtx operands[2];
1560 operands[0] = dest;
1561 operands[1] = source;
1562
1563 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
1564 if (GET_CODE (operands[1]) == CONST_DOUBLE
1565 && ! FLOAT_MODE_P (mode)
1566 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1567 {
1568 /* FIXME. This should never happen. */
1569 /* Since it seems that it does, do the safe thing and convert
1570 to a CONST_INT. */
1571 operands[1] =
1572 GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode));
1573 }
1574 if (GET_CODE (operands[1]) == CONST_DOUBLE
1575 && ! FLOAT_MODE_P (mode)
1576 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
1577 && CONST_DOUBLE_LOW (operands[1]) >= 0)
1578 || (CONST_DOUBLE_HIGH (operands[1]) == -1
1579 && CONST_DOUBLE_LOW (operands[1]) < 0)))
1580 abort ();
1581
1582 if (! no_new_pseudos && GET_CODE (operands[0]) != REG)
1583 operands[1] = force_reg (mode, operands[1]);
a9098fd0 1584
ffc14f31
GK
1585 if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT
1586 && GET_CODE (operands[0]) == MEM)
fb4d4348 1587 {
ffc14f31
GK
1588 int regnum;
1589
1590 if (reload_in_progress || reload_completed)
1591 regnum = true_regnum (operands[1]);
1592 else if (GET_CODE (operands[1]) == REG)
1593 regnum = REGNO (operands[1]);
1594 else
1595 regnum = -1;
fb4d4348
GK
1596
1597 /* If operands[1] is a register, on POWER it may have
1598 double-precision data in it, so truncate it to single
1599 precision. */
1600 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
1601 {
1602 rtx newreg;
1603 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
1604 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
1605 operands[1] = newreg;
1606 }
1607 }
1608
a9098fd0
GK
1609 /* Handle the case where reload calls us with an invalid address;
1610 and the case of CONSTANT_P_RTX. */
1611 if (! general_operand (operands[1], mode)
1612 || ! nonimmediate_operand (operands[0], mode)
1613 || GET_CODE (operands[1]) == CONSTANT_P_RTX)
fb4d4348
GK
1614 {
1615 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1616 return;
1617 }
a9098fd0 1618
fb4d4348
GK
1619 /* FIXME: In the long term, this switch statement should go away
1620 and be replaced by a sequence of tests based on things like
1621 mode == Pmode. */
1622 switch (mode)
1623 {
1624 case HImode:
1625 case QImode:
1626 if (CONSTANT_P (operands[1])
1627 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 1628 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
1629 break;
1630
1631 case DFmode:
1632 case SFmode:
1633 if (CONSTANT_P (operands[1])
1634 && ! easy_fp_constant (operands[1], mode))
a9098fd0 1635 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
1636 break;
1637
1638 case SImode:
a9098fd0 1639 case DImode:
fb4d4348
GK
1640 /* Use default pattern for address of ELF small data */
1641 if (TARGET_ELF
a9098fd0 1642 && mode == Pmode
fb4d4348 1643 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
a9098fd0
GK
1644 && (GET_CODE (operands[1]) == SYMBOL_REF
1645 || GET_CODE (operands[1]) == CONST)
1646 && small_data_operand (operands[1], mode))
fb4d4348
GK
1647 {
1648 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1649 return;
1650 }
1651
1652 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
a9098fd0
GK
1653 && mode == Pmode && mode == SImode
1654 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
1655 {
1656 emit_insn (gen_movsi_got (operands[0], operands[1]));
1657 return;
1658 }
1659
ee890fe2
SS
1660 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
1661 && TARGET_NO_TOC && ! flag_pic
a9098fd0 1662 && mode == Pmode
fb4d4348
GK
1663 && CONSTANT_P (operands[1])
1664 && GET_CODE (operands[1]) != HIGH
1665 && GET_CODE (operands[1]) != CONST_INT)
1666 {
a9098fd0 1667 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
1668
1669 /* If this is a function address on -mcall-aixdesc,
1670 convert it to the address of the descriptor. */
1671 if (DEFAULT_ABI == ABI_AIX
1672 && GET_CODE (operands[1]) == SYMBOL_REF
1673 && XSTR (operands[1], 0)[0] == '.')
1674 {
1675 const char *name = XSTR (operands[1], 0);
1676 rtx new_ref;
1677 while (*name == '.')
1678 name++;
1679 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
1680 CONSTANT_POOL_ADDRESS_P (new_ref)
1681 = CONSTANT_POOL_ADDRESS_P (operands[1]);
1682 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
1683 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
1684 operands[1] = new_ref;
1685 }
7509c759 1686
ee890fe2
SS
1687 if (DEFAULT_ABI == ABI_DARWIN)
1688 {
1689 emit_insn (gen_macho_high (target, operands[1]));
1690 emit_insn (gen_macho_low (operands[0], target, operands[1]));
1691 return;
1692 }
1693
fb4d4348
GK
1694 emit_insn (gen_elf_high (target, operands[1]));
1695 emit_insn (gen_elf_low (operands[0], target, operands[1]));
1696 return;
1697 }
1698
a9098fd0
GK
1699 /* If this is a SYMBOL_REF that refers to a constant pool entry,
1700 and we have put it in the TOC, we just need to make a TOC-relative
1701 reference to it. */
1702 if (TARGET_TOC
1703 && GET_CODE (operands[1]) == SYMBOL_REF
1704 && CONSTANT_POOL_EXPR_P (operands[1])
1705 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
1706 get_pool_mode (operands[1])))
fb4d4348 1707 {
a9098fd0 1708 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 1709 }
a9098fd0
GK
1710 else if (mode == Pmode
1711 && CONSTANT_P (operands[1])
1712 && (((HOST_BITS_PER_WIDE_INT != 32
1713 || GET_CODE (operands[1]) != CONST_INT)
1714 && ! easy_fp_constant (operands[1], mode))
1715 || (GET_CODE (operands[0]) == REG
1716 && FP_REGNO_P (REGNO (operands[0]))))
1717 && GET_CODE (operands[1]) != HIGH
1718 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
1719 && ! TOC_RELATIVE_EXPR_P (operands[1]))
fb4d4348 1720 {
a9098fd0
GK
1721 int special_constant_p = 0;
1722
fb4d4348
GK
1723 /* Emit a USE operation so that the constant isn't deleted if
1724 expensive optimizations are turned on because nobody
1725 references it. This should only be done for operands that
1726 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
1727 This should not be done for operands that contain LABEL_REFs.
1728 For now, we just handle the obvious case. */
1729 if (GET_CODE (operands[1]) != LABEL_REF)
1730 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
1731
ee890fe2
SS
1732 /* Darwin uses a special PIC legitimizer. */
1733 if (DEFAULT_ABI == ABI_DARWIN && flag_pic)
1734 {
1735 rtx temp_reg = ((reload_in_progress || reload_completed)
1736 ? operands[0] : NULL);
1737
1738#if TARGET_MACHO
1739 operands[1] =
1740 rs6000_machopic_legitimize_pic_address (operands[1], mode,
1741 temp_reg);
1742#endif
1743 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1744 return;
1745 }
1746
fb4d4348
GK
1747 /* If we are to limit the number of things we put in the TOC and
1748 this is a symbol plus a constant we can add in one insn,
1749 just put the symbol in the TOC and add the constant. Don't do
1750 this if reload is in progress. */
1751 if (GET_CODE (operands[1]) == CONST
1752 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
1753 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 1754 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
1755 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
1756 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
1757 && ! side_effects_p (operands[0]))
1758 {
a9098fd0 1759 rtx sym = force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
1760 rtx other = XEXP (XEXP (operands[1], 0), 1);
1761
a9098fd0
GK
1762 sym = force_reg (mode, sym);
1763 if (mode == SImode)
1764 emit_insn (gen_addsi3 (operands[0], sym, other));
1765 else
1766 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
1767 return;
1768 }
1769
a9098fd0 1770 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
1771
1772 if (TARGET_TOC
a9098fd0 1773 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0)))
fb4d4348 1774 {
a9098fd0
GK
1775 rtx constant;
1776 enum machine_mode cmode;
fb4d4348 1777
a9098fd0
GK
1778 constant = get_pool_constant (XEXP (operands[1], 0));
1779 cmode = get_pool_mode (XEXP (operands[1], 0));
1780 special_constant_p =
1781 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (constant, cmode);
1782 }
1783
1784 if (special_constant_p)
1785 {
1786 operands[1] = gen_rtx_MEM (mode,
1787 create_TOC_reference (XEXP (operands[1], 0)));
fb4d4348
GK
1788 MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set ();
1789 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 1790 }
fb4d4348
GK
1791 }
1792 break;
a9098fd0 1793
fb4d4348
GK
1794 case TImode:
1795 if (GET_CODE (operands[0]) == MEM
1796 && GET_CODE (XEXP (operands[0], 0)) != REG
1797 && ! reload_in_progress)
1798 operands[0] = change_address (operands[0], TImode,
1799 copy_addr_to_reg (XEXP (operands[0], 0)));
1800
1801 if (GET_CODE (operands[1]) == MEM
1802 && GET_CODE (XEXP (operands[1], 0)) != REG
1803 && ! reload_in_progress)
1804 operands[1] = change_address (operands[1], TImode,
1805 copy_addr_to_reg (XEXP (operands[1], 0)));
1806 break;
1807
1808 default:
1809 abort ();
1810 }
1811
a9098fd0
GK
1812 /* Above, we may have called force_const_mem which may have returned
1813 an invalid address. If we can, fix this up; otherwise, reload will
1814 have to deal with it. */
1815 if (GET_CODE (operands[1]) == MEM
1816 && ! memory_address_p (mode, XEXP (operands[1], 0))
1817 && ! reload_in_progress)
1818 operands[1] = change_address (operands[1], mode,
1819 XEXP (operands[1], 0));
1820
fb4d4348 1821 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
02a4ec28 1822 return;
fb4d4348 1823}
4697a36c
MM
1824\f
1825/* Initialize a variable CUM of type CUMULATIVE_ARGS
1826 for a call to a function whose data type is FNTYPE.
1827 For a library call, FNTYPE is 0.
1828
1829 For incoming args we set the number of arguments in the prototype large
1c20ae99 1830 so we never return a PARALLEL. */
4697a36c
MM
1831
1832void
1833init_cumulative_args (cum, fntype, libname, incoming)
1834 CUMULATIVE_ARGS *cum;
1835 tree fntype;
296b8152 1836 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
1837 int incoming;
1838{
1839 static CUMULATIVE_ARGS zero_cumulative;
1840
1841 *cum = zero_cumulative;
1842 cum->words = 0;
1843 cum->fregno = FP_ARG_MIN_REG;
1844 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 1845 cum->call_cookie = CALL_NORMAL;
4cc833b7 1846 cum->sysv_gregno = GP_ARG_MIN_REG;
4697a36c
MM
1847
1848 if (incoming)
bd227acc 1849 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
1850
1851 else if (cum->prototype)
1852 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1853 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1854 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1855
1856 else
1857 cum->nargs_prototype = 0;
1858
1859 cum->orig_nargs = cum->nargs_prototype;
7509c759 1860
9ebbca7d
GK
1861 /* Check for longcall's */
1862 if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
1863 cum->call_cookie = CALL_LONG;
1864
4697a36c
MM
1865 if (TARGET_DEBUG_ARG)
1866 {
1867 fprintf (stderr, "\ninit_cumulative_args:");
1868 if (fntype)
1869 {
1870 tree ret_type = TREE_TYPE (fntype);
1871 fprintf (stderr, " ret code = %s,",
1872 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1873 }
1874
6a4cee5f
MM
1875 if (cum->call_cookie & CALL_LONG)
1876 fprintf (stderr, " longcall,");
1877
4697a36c
MM
1878 fprintf (stderr, " proto = %d, nargs = %d\n",
1879 cum->prototype, cum->nargs_prototype);
1880 }
1881}
1882\f
c229cba9
DE
1883/* If defined, a C expression which determines whether, and in which
1884 direction, to pad out an argument with extra space. The value
1885 should be of type `enum direction': either `upward' to pad above
1886 the argument, `downward' to pad below, or `none' to inhibit
1887 padding.
1888
1889 For the AIX ABI structs are always stored left shifted in their
1890 argument slot. */
1891
9ebbca7d 1892enum direction
c229cba9
DE
1893function_arg_padding (mode, type)
1894 enum machine_mode mode;
1895 tree type;
1896{
c85f7c16 1897 if (type != 0 && AGGREGATE_TYPE_P (type))
9ebbca7d 1898 return upward;
c229cba9
DE
1899
1900 /* This is the default definition. */
1901 return (! BYTES_BIG_ENDIAN
9ebbca7d 1902 ? upward
c229cba9
DE
1903 : ((mode == BLKmode
1904 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1905 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1906 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
9ebbca7d 1907 ? downward : upward));
c229cba9
DE
1908}
1909
b6c9286a
MM
1910/* If defined, a C expression that gives the alignment boundary, in bits,
1911 of an argument with the specified mode and type. If it is not defined,
1912 PARM_BOUNDARY is used for all arguments.
1913
2310f99a 1914 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
1915
1916int
1917function_arg_boundary (mode, type)
1918 enum machine_mode mode;
9ebbca7d 1919 tree type ATTRIBUTE_UNUSED;
b6c9286a 1920{
4cc833b7
RH
1921 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1922 && (mode == DImode || mode == DFmode))
e1f83b4d 1923 return 64;
9ebbca7d 1924 else
b6c9286a 1925 return PARM_BOUNDARY;
b6c9286a
MM
1926}
1927\f
4697a36c
MM
1928/* Update the data in CUM to advance over an argument
1929 of mode MODE and data type TYPE.
1930 (TYPE is null for libcalls where that information may not be available.) */
1931
1932void
1933function_arg_advance (cum, mode, type, named)
1934 CUMULATIVE_ARGS *cum;
1935 enum machine_mode mode;
1936 tree type;
1937 int named;
1938{
1939 cum->nargs_prototype--;
1940
c81bebd7 1941 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c 1942 {
4cc833b7
RH
1943 if (TARGET_HARD_FLOAT
1944 && (mode == SFmode || mode == DFmode))
4697a36c 1945 {
4cc833b7
RH
1946 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1947 cum->fregno++;
1948 else
1949 {
1950 if (mode == DFmode)
1951 cum->words += cum->words & 1;
1952 cum->words += RS6000_ARG_SIZE (mode, type, 1);
1953 }
4697a36c 1954 }
4cc833b7
RH
1955 else
1956 {
1957 int n_words;
1958 int gregno = cum->sysv_gregno;
1959
1960 /* Aggregates and IEEE quad get passed by reference. */
1961 if ((type && AGGREGATE_TYPE_P (type))
1962 || mode == TFmode)
1963 n_words = 1;
1964 else
1965 n_words = RS6000_ARG_SIZE (mode, type, 1);
1966
1967 /* Long long is put in odd registers. */
1968 if (n_words == 2 && (gregno & 1) == 0)
1969 gregno += 1;
1970
1971 /* Long long is not split between registers and stack. */
1972 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
1973 {
1974 /* Long long is aligned on the stack. */
1975 if (n_words == 2)
1976 cum->words += cum->words & 1;
1977 cum->words += n_words;
1978 }
4697a36c 1979
4cc833b7
RH
1980 /* Note: continuing to accumulate gregno past when we've started
1981 spilling to the stack indicates the fact that we've started
1982 spilling to the stack to expand_builtin_saveregs. */
1983 cum->sysv_gregno = gregno + n_words;
1984 }
4697a36c 1985
4cc833b7
RH
1986 if (TARGET_DEBUG_ARG)
1987 {
1988 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1989 cum->words, cum->fregno);
1990 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
1991 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
1992 fprintf (stderr, "mode = %4s, named = %d\n",
1993 GET_MODE_NAME (mode), named);
1994 }
4697a36c
MM
1995 }
1996 else
4cc833b7
RH
1997 {
1998 int align = (TARGET_32BIT && (cum->words & 1) != 0
1999 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2000 cum->words += align;
4697a36c 2001
4cc833b7
RH
2002 if (named)
2003 {
2004 cum->words += RS6000_ARG_SIZE (mode, type, named);
2005 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
2006 cum->fregno++;
2007 }
2008
2009 if (TARGET_DEBUG_ARG)
2010 {
2011 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
2012 cum->words, cum->fregno);
2013 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
2014 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
2015 fprintf (stderr, "named = %d, align = %d\n", named, align);
2016 }
2017 }
4697a36c
MM
2018}
2019\f
2020/* Determine where to put an argument to a function.
2021 Value is zero to push the argument on the stack,
2022 or a hard register in which to store the argument.
2023
2024 MODE is the argument's machine mode.
2025 TYPE is the data type of the argument (as a tree).
2026 This is null for libcalls where that information may
2027 not be available.
2028 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2029 the preceding args and about the function being called.
2030 NAMED is nonzero if this argument is a named parameter
2031 (otherwise it is an extra parameter matching an ellipsis).
2032
2033 On RS/6000 the first eight words of non-FP are normally in registers
2034 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
2035 Under V.4, the first 8 FP args are in registers.
2036
2037 If this is floating-point and no prototype is specified, we use
2038 both an FP and integer register (or possibly FP reg and stack). Library
2039 functions (when TYPE is zero) always have the proper types for args,
2040 so we can pass the FP value just in one register. emit_library_function
1c20ae99 2041 doesn't support PARALLEL anyway. */
4697a36c
MM
2042
2043struct rtx_def *
2044function_arg (cum, mode, type, named)
2045 CUMULATIVE_ARGS *cum;
2046 enum machine_mode mode;
2047 tree type;
2048 int named;
2049{
4cc833b7 2050 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 2051
4cc833b7
RH
2052 /* Return a marker to indicate whether CR1 needs to set or clear the bit
2053 that V.4 uses to say fp args were passed in registers. Assume that we
2054 don't need the marker for software floating point, or compiler generated
2055 library calls. */
4697a36c
MM
2056 if (mode == VOIDmode)
2057 {
c81bebd7 2058 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
7509c759
MM
2059 && TARGET_HARD_FLOAT
2060 && cum->nargs_prototype < 0
4697a36c 2061 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 2062 {
6a4cee5f
MM
2063 return GEN_INT (cum->call_cookie
2064 | ((cum->fregno == FP_ARG_MIN_REG)
2065 ? CALL_V4_SET_FP_ARGS
2066 : CALL_V4_CLEAR_FP_ARGS));
7509c759 2067 }
4697a36c 2068
7509c759 2069 return GEN_INT (cum->call_cookie);
4697a36c
MM
2070 }
2071
4cc833b7 2072 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4697a36c 2073 {
4cc833b7
RH
2074 if (TARGET_HARD_FLOAT
2075 && (mode == SFmode || mode == DFmode))
2076 {
2077 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2078 return gen_rtx_REG (mode, cum->fregno);
2079 else
2080 return NULL;
2081 }
2082 else
2083 {
2084 int n_words;
2085 int gregno = cum->sysv_gregno;
2086
2087 /* Aggregates and IEEE quad get passed by reference. */
2088 if ((type && AGGREGATE_TYPE_P (type))
2089 || mode == TFmode)
2090 n_words = 1;
2091 else
2092 n_words = RS6000_ARG_SIZE (mode, type, 1);
2093
2094 /* Long long is put in odd registers. */
2095 if (n_words == 2 && (gregno & 1) == 0)
2096 gregno += 1;
2097
2098 /* Long long is not split between registers and stack. */
2099 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
2100 return gen_rtx_REG (mode, gregno);
2101 else
2102 return NULL;
2103 }
4697a36c 2104 }
4cc833b7
RH
2105 else
2106 {
2107 int align = (TARGET_32BIT && (cum->words & 1) != 0
2108 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2109 int align_words = cum->words + align;
4697a36c 2110
c81fc13e 2111 if (! named)
4cc833b7 2112 return NULL_RTX;
4697a36c 2113
4cc833b7
RH
2114 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2115 return NULL_RTX;
2116
2117 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2118 {
2119 if (! type
2120 || ((cum->nargs_prototype > 0)
2121 /* IBM AIX extended its linkage convention definition always
2122 to require FP args after register save area hole on the
2123 stack. */
2124 && (DEFAULT_ABI != ABI_AIX
2125 || ! TARGET_XL_CALL
2126 || (align_words < GP_ARG_NUM_REG))))
2127 return gen_rtx_REG (mode, cum->fregno);
2128
2129 return gen_rtx_PARALLEL (mode,
2130 gen_rtvec (2,
39403d82 2131 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
2132 ((align_words >= GP_ARG_NUM_REG)
2133 ? NULL_RTX
2134 : (align_words
2135 + RS6000_ARG_SIZE (mode, type, named)
2136 > GP_ARG_NUM_REG
2137 /* If this is partially on the stack, then
2138 we only include the portion actually
2139 in registers here. */
39403d82 2140 ? gen_rtx_REG (SImode,
1c20ae99 2141 GP_ARG_MIN_REG + align_words)
39403d82 2142 : gen_rtx_REG (mode,
1c20ae99
JW
2143 GP_ARG_MIN_REG + align_words))),
2144 const0_rtx),
39403d82
DE
2145 gen_rtx_EXPR_LIST (VOIDmode,
2146 gen_rtx_REG (mode, cum->fregno),
1c20ae99 2147 const0_rtx)));
4cc833b7
RH
2148 }
2149 else if (align_words < GP_ARG_NUM_REG)
2150 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
2151 else
2152 return NULL_RTX;
4697a36c 2153 }
4697a36c
MM
2154}
2155\f
2156/* For an arg passed partly in registers and partly in memory,
2157 this is the number of registers used.
2158 For args passed entirely in registers or entirely in memory, zero. */
2159
2160int
2161function_arg_partial_nregs (cum, mode, type, named)
2162 CUMULATIVE_ARGS *cum;
2163 enum machine_mode mode;
2164 tree type;
2165 int named;
2166{
2167 if (! named)
2168 return 0;
2169
c81bebd7 2170 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c 2171 return 0;
4697a36c
MM
2172
2173 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2174 {
2175 if (cum->nargs_prototype >= 0)
2176 return 0;
2177 }
2178
2179 if (cum->words < GP_ARG_NUM_REG
2180 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
2181 {
2182 int ret = GP_ARG_NUM_REG - cum->words;
2183 if (ret && TARGET_DEBUG_ARG)
2184 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2185
2186 return ret;
2187 }
2188
2189 return 0;
2190}
2191\f
2192/* A C expression that indicates when an argument must be passed by
2193 reference. If nonzero for an argument, a copy of that argument is
2194 made in memory and a pointer to the argument is passed instead of
2195 the argument itself. The pointer is passed in whatever way is
2196 appropriate for passing a pointer to that type.
2197
2198 Under V.4, structures and unions are passed by reference. */
2199
2200int
2201function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
2202 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2203 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 2204 tree type;
296b8152 2205 int named ATTRIBUTE_UNUSED;
4697a36c 2206{
c81bebd7 2207 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4cc833b7
RH
2208 && ((type && AGGREGATE_TYPE_P (type))
2209 || mode == TFmode))
4697a36c
MM
2210 {
2211 if (TARGET_DEBUG_ARG)
2212 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
2213
2214 return 1;
2215 }
4697a36c
MM
2216
2217 return 0;
2218}
4697a36c
MM
2219\f
2220/* Perform any needed actions needed for a function that is receiving a
2221 variable number of arguments.
2222
2223 CUM is as above.
2224
2225 MODE and TYPE are the mode and type of the current parameter.
2226
2227 PRETEND_SIZE is a variable that should be set to the amount of stack
2228 that must be pushed by the prolog to pretend that our caller pushed
2229 it.
2230
2231 Normally, this macro will push all remaining incoming registers on the
2232 stack and set PRETEND_SIZE to the length of the registers pushed. */
2233
2234void
2235setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2236 CUMULATIVE_ARGS *cum;
2237 enum machine_mode mode;
2238 tree type;
2239 int *pretend_size;
2240 int no_rtl;
2241
2242{
4cc833b7
RH
2243 CUMULATIVE_ARGS next_cum;
2244 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 2245 rtx save_area = NULL_RTX, mem;
dfafc897 2246 int first_reg_offset, set;
4697a36c 2247
60e2d0ca 2248 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c 2249 {
4cc833b7
RH
2250 tree fntype;
2251 int stdarg_p;
2252
2253 fntype = TREE_TYPE (current_function_decl);
2254 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
2255 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2256 != void_type_node));
2257
2258 /* For varargs, we do not want to skip the dummy va_dcl argument.
2259 For stdargs, we do want to skip the last named argument. */
2260 next_cum = *cum;
2261 if (stdarg_p)
2262 function_arg_advance (&next_cum, mode, type, 1);
2263
2264 /* Indicate to allocate space on the stack for varargs save area. */
2265 /* ??? Does this really have to be located at a magic spot on the
2266 stack, or can we allocate this with assign_stack_local instead. */
00dba523 2267 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 2268 if (! no_rtl)
2c4974b7 2269 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 2270 - RS6000_VARARGS_SIZE);
4cc833b7
RH
2271
2272 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 2273 }
60e2d0ca 2274 else
4697a36c 2275 {
4cc833b7 2276 save_area = virtual_incoming_args_rtx;
00dba523 2277 cfun->machine->sysv_varargs_p = 0;
4697a36c 2278
4cc833b7 2279 first_reg_offset = cum->words;
4697a36c
MM
2280 if (MUST_PASS_IN_STACK (mode, type))
2281 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
4cc833b7 2282 }
4697a36c 2283
dfafc897 2284 set = get_varargs_alias_set ();
c81fc13e 2285 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 2286 {
dfafc897
FS
2287 mem = gen_rtx_MEM (BLKmode,
2288 plus_constant (save_area,
2289 first_reg_offset * reg_size)),
2290 MEM_ALIAS_SET (mem) = set;
2291
4cc833b7 2292 move_block_from_reg
dfafc897 2293 (GP_ARG_MIN_REG + first_reg_offset, mem,
4cc833b7
RH
2294 GP_ARG_NUM_REG - first_reg_offset,
2295 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
2296
2297 /* ??? Does ABI_V4 need this at all? */
4697a36c
MM
2298 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
2299 }
2300
4697a36c 2301 /* Save FP registers if needed. */
4cc833b7 2302 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
c81fc13e 2303 && TARGET_HARD_FLOAT && ! no_rtl
4cc833b7 2304 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 2305 {
4cc833b7 2306 int fregno = next_cum.fregno;
9ebbca7d 2307 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
2308 rtx lab = gen_label_rtx ();
2309 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 2310
4cc833b7 2311 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 2312 pc_rtx,
39403d82 2313 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
2314 gen_rtx_NE (VOIDmode, cr1,
2315 const0_rtx),
39403d82 2316 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
2317 pc_rtx)));
2318
4cc833b7
RH
2319 while (fregno <= FP_ARG_V4_MAX_REG)
2320 {
dfafc897
FS
2321 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
2322 MEM_ALIAS_SET (mem) = set;
2323 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
2324 fregno++;
2325 off += 8;
4697a36c 2326 }
4cc833b7
RH
2327
2328 emit_label (lab);
4697a36c 2329 }
4697a36c 2330}
4697a36c 2331
dfafc897 2332/* Create the va_list data type. */
2c4974b7 2333
dfafc897
FS
2334tree
2335rs6000_build_va_list ()
2336{
bab45a51 2337 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4697a36c 2338
9ebbca7d
GK
2339 /* For AIX, prefer 'char *' because that's what the system
2340 header files like. */
dfafc897 2341 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
9ebbca7d 2342 return build_pointer_type (char_type_node);
dfafc897 2343
0f4fd75d 2344 record = make_lang_type (RECORD_TYPE);
bab45a51 2345 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 2346
9ebbca7d
GK
2347 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
2348 unsigned_char_type_node);
2349 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
2350 unsigned_char_type_node);
dfafc897
FS
2351 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
2352 ptr_type_node);
2353 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
2354 ptr_type_node);
2355
2356 DECL_FIELD_CONTEXT (f_gpr) = record;
2357 DECL_FIELD_CONTEXT (f_fpr) = record;
2358 DECL_FIELD_CONTEXT (f_ovf) = record;
2359 DECL_FIELD_CONTEXT (f_sav) = record;
2360
bab45a51
FS
2361 TREE_CHAIN (record) = type_decl;
2362 TYPE_NAME (record) = type_decl;
dfafc897
FS
2363 TYPE_FIELDS (record) = f_gpr;
2364 TREE_CHAIN (f_gpr) = f_fpr;
2365 TREE_CHAIN (f_fpr) = f_ovf;
2366 TREE_CHAIN (f_ovf) = f_sav;
2367
2368 layout_type (record);
2369
2370 /* The correct type is an array type of one element. */
2371 return build_array_type (record, build_index_type (size_zero_node));
2372}
2373
2374/* Implement va_start. */
2375
2376void
2377rs6000_va_start (stdarg_p, valist, nextarg)
2378 int stdarg_p;
2379 tree valist;
2380 rtx nextarg;
4697a36c 2381{
dfafc897
FS
2382 HOST_WIDE_INT words, n_gpr, n_fpr;
2383 tree f_gpr, f_fpr, f_ovf, f_sav;
2384 tree gpr, fpr, ovf, sav, t;
2c4974b7 2385
dfafc897 2386 /* Only SVR4 needs something special. */
2c4974b7 2387 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
dfafc897
FS
2388 {
2389 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2390 return;
2391 }
2392
973a648b 2393 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
2394 f_fpr = TREE_CHAIN (f_gpr);
2395 f_ovf = TREE_CHAIN (f_fpr);
2396 f_sav = TREE_CHAIN (f_ovf);
2397
8ebecc3b 2398 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
2399 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2400 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2401 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2402 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2403
2404 /* Count number of gp and fp argument registers used. */
4cc833b7 2405 words = current_function_args_info.words;
dfafc897
FS
2406 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
2407 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
2408
2409 if (TARGET_DEBUG_ARG)
2410 fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n",
2411 words, n_gpr, n_fpr);
2412
2413 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
2414 TREE_SIDE_EFFECTS (t) = 1;
2415 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2416
2417 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
2418 TREE_SIDE_EFFECTS (t) = 1;
2419 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2420
2421 /* Find the overflow area. */
2422 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
2423 if (words != 0)
2424 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
2425 build_int_2 (words * UNITS_PER_WORD, 0));
2426 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2427 TREE_SIDE_EFFECTS (t) = 1;
2428 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2429
2430 /* Find the register save area. */
2431 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
2432 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
2433 build_int_2 (-RS6000_VARARGS_SIZE, -1));
2434 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
2435 TREE_SIDE_EFFECTS (t) = 1;
2436 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2437}
2438
2439/* Implement va_arg. */
2440
2441rtx
2442rs6000_va_arg (valist, type)
2443 tree valist, type;
2444{
2445 tree f_gpr, f_fpr, f_ovf, f_sav;
2446 tree gpr, fpr, ovf, sav, reg, t, u;
2447 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
2448 rtx lab_false, lab_over, addr_rtx, r;
2449
9ebbca7d
GK
2450 /* For AIX, the rule is that structures are passed left-aligned in
2451 their stack slot. However, GCC does not presently do this:
2452 structures which are the same size as integer types are passed
2453 right-aligned, as if they were in fact integers. This only
2454 matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */
dfafc897 2455 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
9ebbca7d
GK
2456 {
2457 HOST_WIDE_INT align, rounded_size;
2458 enum machine_mode mode;
2459 tree addr_tree;
2460
2461 /* Compute the rounded size of the type. */
2462 align = PARM_BOUNDARY / BITS_PER_UNIT;
2463 rounded_size = (((int_size_in_bytes (type) + align - 1) / align)
2464 * align);
2465
2466 addr_tree = valist;
2467
2468 mode = TYPE_MODE (type);
2469 if (mode != BLKmode)
2470 {
2471 HOST_WIDE_INT adj;
2472 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2473 if (rounded_size > align)
2474 adj = rounded_size;
2475
2476 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2477 build_int_2 (rounded_size - adj, 0));
2478 }
2479
2480 addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2481 addr_rtx = copy_to_reg (addr_rtx);
2482
2483 /* Compute new value for AP. */
2484 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2485 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2486 build_int_2 (rounded_size, 0)));
2487 TREE_SIDE_EFFECTS (t) = 1;
2488 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2489
2490 return addr_rtx;
2491 }
dfafc897 2492
973a648b 2493 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
2494 f_fpr = TREE_CHAIN (f_gpr);
2495 f_ovf = TREE_CHAIN (f_fpr);
2496 f_sav = TREE_CHAIN (f_ovf);
2497
8ebecc3b 2498 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
2499 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2500 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2501 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2502 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2503
2504 size = int_size_in_bytes (type);
2505 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 2506
dfafc897 2507 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 2508 {
dfafc897
FS
2509 /* Aggregates and long doubles are passed by reference. */
2510 indirect_p = 1;
2511 reg = gpr;
2512 n_reg = 1;
2513 sav_ofs = 0;
2514 sav_scale = 4;
2515 size = rsize = UNITS_PER_WORD;
2516 }
2517 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
2518 {
2519 /* FP args go in FP registers, if present. */
2520 indirect_p = 0;
2521 reg = fpr;
2522 n_reg = 1;
2523 sav_ofs = 8*4;
2524 sav_scale = 8;
4cc833b7 2525 }
dfafc897
FS
2526 else
2527 {
2528 /* Otherwise into GP registers. */
2529 indirect_p = 0;
2530 reg = gpr;
2531 n_reg = rsize;
2532 sav_ofs = 0;
2533 sav_scale = 4;
2534 }
2535
2536 /*
2537 * Pull the value out of the saved registers ...
2538 */
2539
2540 lab_false = gen_label_rtx ();
2541 lab_over = gen_label_rtx ();
2542 addr_rtx = gen_reg_rtx (Pmode);
2543
2544 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
2545 GEN_INT (8 - n_reg + 1),
2546 GE, const1_rtx, QImode, 1, 1, lab_false);
2c4974b7 2547
dfafc897
FS
2548 /* Long long is aligned in the registers. */
2549 if (n_reg > 1)
2c4974b7 2550 {
dfafc897
FS
2551 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
2552 build_int_2 (n_reg - 1, 0));
2553 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
2554 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
2555 TREE_SIDE_EFFECTS (u) = 1;
2556 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
2c4974b7 2557 }
dfafc897
FS
2558
2559 if (sav_ofs)
2560 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2c4974b7 2561 else
dfafc897 2562 t = sav;
2c4974b7 2563
dfafc897
FS
2564 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
2565 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 2566
dfafc897
FS
2567 u = build1 (CONVERT_EXPR, integer_type_node, u);
2568 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 2569
dfafc897
FS
2570 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
2571 TREE_SIDE_EFFECTS (u) = 1;
2572
2573 t = build (PLUS_EXPR, ptr_type_node, t, u);
2574 TREE_SIDE_EFFECTS (t) = 1;
2575
2576 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2577 if (r != addr_rtx)
2578 emit_move_insn (addr_rtx, r);
2579
2580 emit_jump_insn (gen_jump (lab_over));
2581 emit_barrier ();
2582 emit_label (lab_false);
2583
2584 /*
2585 * ... otherwise out of the overflow area.
2586 */
2587
2588 /* Make sure we don't find reg 7 for the next int arg. */
2589 if (n_reg > 1)
2590 {
2591 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
2592 TREE_SIDE_EFFECTS (t) = 1;
2593 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2594 }
2595
2596 /* Care for on-stack alignment if needed. */
2597 if (rsize <= 1)
2598 t = ovf;
2599 else
2600 {
2601 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
2602 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
2603 }
2604 t = save_expr (t);
2605
2606 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2607 if (r != addr_rtx)
2608 emit_move_insn (addr_rtx, r);
2609
2610 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
2611 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2612 TREE_SIDE_EFFECTS (t) = 1;
2613 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2614
2615 emit_label (lab_over);
2616
2617 if (indirect_p)
2618 {
2619 r = gen_rtx_MEM (Pmode, addr_rtx);
2620 MEM_ALIAS_SET (r) = get_varargs_alias_set ();
2621 emit_move_insn (addr_rtx, r);
2622 }
2623
2624 return addr_rtx;
4697a36c 2625}
5b5040b9
RK
2626\f
2627/* Generate a memory reference for expand_block_move, copying volatile,
2628 and other bits from an original memory reference. */
2629
2630static rtx
2631expand_block_move_mem (mode, addr, orig_mem)
2632 enum machine_mode mode;
2633 rtx addr;
2634 rtx orig_mem;
2635{
39403d82 2636 rtx mem = gen_rtx_MEM (mode, addr);
b6c9286a 2637
c6df88cb 2638 MEM_COPY_ATTRIBUTES (mem, orig_mem);
b6c9286a
MM
2639#ifdef MEM_UNALIGNED_P
2640 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
2641#endif
5b5040b9
RK
2642 return mem;
2643}
2644
7e69e155
MM
2645/* Expand a block move operation, and return 1 if successful. Return 0
2646 if we should let the compiler generate normal code.
2647
2648 operands[0] is the destination
2649 operands[1] is the source
2650 operands[2] is the length
2651 operands[3] is the alignment */
2652
3933e0e1
MM
2653#define MAX_MOVE_REG 4
2654
7e69e155
MM
2655int
2656expand_block_move (operands)
2657 rtx operands[];
2658{
b6c9286a
MM
2659 rtx orig_dest = operands[0];
2660 rtx orig_src = operands[1];
7e69e155 2661 rtx bytes_rtx = operands[2];
7e69e155 2662 rtx align_rtx = operands[3];
3933e0e1 2663 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 2664 int align;
3933e0e1
MM
2665 int bytes;
2666 int offset;
2667 int num_reg;
2668 int i;
7e69e155
MM
2669 rtx src_reg;
2670 rtx dest_reg;
3933e0e1
MM
2671 rtx src_addr;
2672 rtx dest_addr;
7e69e155 2673 rtx tmp_reg;
3933e0e1 2674 rtx stores[MAX_MOVE_REG];
7e69e155
MM
2675 int move_bytes;
2676
3933e0e1 2677 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 2678 if (! constp)
3933e0e1
MM
2679 return 0;
2680
5ee95df6
FS
2681 /* If this is not a fixed size alignment, abort */
2682 if (GET_CODE (align_rtx) != CONST_INT)
2683 abort ();
2684 align = INTVAL (align_rtx);
2685
7e69e155 2686 /* Anything to move? */
3933e0e1
MM
2687 bytes = INTVAL (bytes_rtx);
2688 if (bytes <= 0)
7e69e155
MM
2689 return 1;
2690
3933e0e1
MM
2691 /* Don't support real large moves. If string instructions are not used,
2692 then don't generate more than 8 loads. */
2693 if (TARGET_STRING)
2694 {
c81fc13e 2695 if (bytes > 8*4)
3933e0e1
MM
2696 return 0;
2697 }
cc0d9ba8 2698 else if (! STRICT_ALIGNMENT)
3933e0e1 2699 {
c81fc13e
DE
2700 if (TARGET_POWERPC64 && align >= 4)
2701 {
2702 if (bytes > 8*8)
2703 return 0;
2704 }
2705 else
2706 if (bytes > 8*4)
2707 return 0;
3933e0e1
MM
2708 }
2709 else if (bytes > 8*align)
7e69e155
MM
2710 return 0;
2711
2712 /* Move the address into scratch registers. */
b6c9286a
MM
2713 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2714 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
7e69e155 2715
3933e0e1 2716 if (TARGET_STRING) /* string instructions are available */
7e69e155 2717 {
3933e0e1 2718 for ( ; bytes > 0; bytes -= move_bytes)
7e69e155 2719 {
3933e0e1 2720 if (bytes > 24 /* move up to 32 bytes at a time */
cc0d9ba8
DE
2721 && ! fixed_regs[5]
2722 && ! fixed_regs[6]
2723 && ! fixed_regs[7]
2724 && ! fixed_regs[8]
2725 && ! fixed_regs[9]
2726 && ! fixed_regs[10]
2727 && ! fixed_regs[11]
2728 && ! fixed_regs[12])
3933e0e1
MM
2729 {
2730 move_bytes = (bytes > 32) ? 32 : bytes;
cc0d9ba8
DE
2731 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
2732 dest_reg,
2733 orig_dest),
2734 expand_block_move_mem (BLKmode,
2735 src_reg,
2736 orig_src),
2737 GEN_INT ((move_bytes == 32)
2738 ? 0 : move_bytes),
4c64a852 2739 align_rtx));
3933e0e1
MM
2740 }
2741 else if (bytes > 16 /* move up to 24 bytes at a time */
f9562f27
DE
2742 && ! fixed_regs[5]
2743 && ! fixed_regs[6]
cc0d9ba8
DE
2744 && ! fixed_regs[7]
2745 && ! fixed_regs[8]
2746 && ! fixed_regs[9]
f9562f27 2747 && ! fixed_regs[10])
3933e0e1
MM
2748 {
2749 move_bytes = (bytes > 24) ? 24 : bytes;
cc0d9ba8
DE
2750 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
2751 dest_reg,
2752 orig_dest),
2753 expand_block_move_mem (BLKmode,
2754 src_reg,
2755 orig_src),
3933e0e1 2756 GEN_INT (move_bytes),
4c64a852 2757 align_rtx));
3933e0e1
MM
2758 }
2759 else if (bytes > 8 /* move up to 16 bytes at a time */
f9562f27
DE
2760 && ! fixed_regs[5]
2761 && ! fixed_regs[6]
2762 && ! fixed_regs[7]
2763 && ! fixed_regs[8])
3933e0e1
MM
2764 {
2765 move_bytes = (bytes > 16) ? 16 : bytes;
cc0d9ba8
DE
2766 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
2767 dest_reg,
2768 orig_dest),
2769 expand_block_move_mem (BLKmode,
2770 src_reg,
2771 orig_src),
3933e0e1 2772 GEN_INT (move_bytes),
4c64a852 2773 align_rtx));
3933e0e1 2774 }
acad7ed3
DE
2775 else if (bytes >= 8 && TARGET_POWERPC64
2776 /* 64-bit loads and stores require word-aligned displacements. */
2777 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2778 {
2779 move_bytes = 8;
2780 tmp_reg = gen_reg_rtx (DImode);
2781 emit_move_insn (tmp_reg,
2782 expand_block_move_mem (DImode,
2eba1afa 2783 src_reg, orig_src));
acad7ed3 2784 emit_move_insn (expand_block_move_mem (DImode,
2eba1afa 2785 dest_reg, orig_dest),
acad7ed3
DE
2786 tmp_reg);
2787 }
2788 else if (bytes > 4)
3933e0e1
MM
2789 { /* move up to 8 bytes at a time */
2790 move_bytes = (bytes > 8) ? 8 : bytes;
cc0d9ba8
DE
2791 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
2792 dest_reg,
2793 orig_dest),
2794 expand_block_move_mem (BLKmode,
2795 src_reg,
2796 orig_src),
3933e0e1 2797 GEN_INT (move_bytes),
4c64a852 2798 align_rtx));
3933e0e1 2799 }
cc0d9ba8 2800 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
2801 { /* move 4 bytes */
2802 move_bytes = 4;
2803 tmp_reg = gen_reg_rtx (SImode);
cc0d9ba8
DE
2804 emit_move_insn (tmp_reg,
2805 expand_block_move_mem (SImode,
2806 src_reg, orig_src));
2807 emit_move_insn (expand_block_move_mem (SImode,
2808 dest_reg, orig_dest),
2809 tmp_reg);
3933e0e1 2810 }
cc0d9ba8 2811 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
2812 { /* move 2 bytes */
2813 move_bytes = 2;
2814 tmp_reg = gen_reg_rtx (HImode);
cc0d9ba8
DE
2815 emit_move_insn (tmp_reg,
2816 expand_block_move_mem (HImode,
2817 src_reg, orig_src));
2818 emit_move_insn (expand_block_move_mem (HImode,
2819 dest_reg, orig_dest),
2820 tmp_reg);
3933e0e1
MM
2821 }
2822 else if (bytes == 1) /* move 1 byte */
2823 {
2824 move_bytes = 1;
2825 tmp_reg = gen_reg_rtx (QImode);
cc0d9ba8
DE
2826 emit_move_insn (tmp_reg,
2827 expand_block_move_mem (QImode,
2828 src_reg, orig_src));
2829 emit_move_insn (expand_block_move_mem (QImode,
2830 dest_reg, orig_dest),
2831 tmp_reg);
3933e0e1
MM
2832 }
2833 else
2834 { /* move up to 4 bytes at a time */
2835 move_bytes = (bytes > 4) ? 4 : bytes;
cc0d9ba8
DE
2836 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
2837 dest_reg,
2838 orig_dest),
2839 expand_block_move_mem (BLKmode,
2840 src_reg,
2841 orig_src),
3933e0e1 2842 GEN_INT (move_bytes),
4c64a852 2843 align_rtx));
3933e0e1 2844 }
4c64a852 2845
015892ee
RK
2846 if (bytes > move_bytes)
2847 {
cc0d9ba8
DE
2848 if (! TARGET_POWERPC64)
2849 {
2850 emit_insn (gen_addsi3 (src_reg, src_reg,
2851 GEN_INT (move_bytes)));
2852 emit_insn (gen_addsi3 (dest_reg, dest_reg,
2853 GEN_INT (move_bytes)));
2854 }
2855 else
2856 {
2857 emit_insn (gen_adddi3 (src_reg, src_reg,
2858 GEN_INT (move_bytes)));
2859 emit_insn (gen_adddi3 (dest_reg, dest_reg,
2860 GEN_INT (move_bytes)));
2861 }
015892ee 2862 }
4c64a852 2863 }
3933e0e1
MM
2864 }
2865
2866 else /* string instructions not available */
2867 {
2868 num_reg = offset = 0;
2869 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
7e69e155 2870 {
3933e0e1
MM
2871 /* Calculate the correct offset for src/dest */
2872 if (offset == 0)
7e69e155 2873 {
3933e0e1
MM
2874 src_addr = src_reg;
2875 dest_addr = dest_reg;
2876 }
2877 else
2878 {
c5c76735
JL
2879 src_addr = plus_constant (src_reg, offset);
2880 dest_addr = plus_constant (dest_reg, offset);
3933e0e1
MM
2881 }
2882
cc0d9ba8
DE
2883 /* Generate the appropriate load and store, saving the stores
2884 for later. */
2885 if (bytes >= 8 && TARGET_POWERPC64
2886 /* 64-bit loads and stores require word-aligned displacements. */
2887 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
b6c9286a
MM
2888 {
2889 move_bytes = 8;
2890 tmp_reg = gen_reg_rtx (DImode);
cc0d9ba8
DE
2891 emit_insn (gen_movdi (tmp_reg,
2892 expand_block_move_mem (DImode,
2893 src_addr,
2894 orig_src)));
2895 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
2896 dest_addr,
2897 orig_dest),
2898 tmp_reg);
b6c9286a 2899 }
cc0d9ba8 2900 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
2901 {
2902 move_bytes = 4;
2903 tmp_reg = gen_reg_rtx (SImode);
cc0d9ba8
DE
2904 emit_insn (gen_movsi (tmp_reg,
2905 expand_block_move_mem (SImode,
2906 src_addr,
2907 orig_src)));
2908 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
2909 dest_addr,
2910 orig_dest),
2911 tmp_reg);
3933e0e1 2912 }
cc0d9ba8 2913 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
2914 {
2915 move_bytes = 2;
2916 tmp_reg = gen_reg_rtx (HImode);
c81fc13e 2917 emit_insn (gen_movhi (tmp_reg,
cc0d9ba8
DE
2918 expand_block_move_mem (HImode,
2919 src_addr,
2920 orig_src)));
2921 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
2922 dest_addr,
2923 orig_dest),
2924 tmp_reg);
3933e0e1
MM
2925 }
2926 else
2927 {
2928 move_bytes = 1;
2929 tmp_reg = gen_reg_rtx (QImode);
c81fc13e 2930 emit_insn (gen_movqi (tmp_reg,
cc0d9ba8
DE
2931 expand_block_move_mem (QImode,
2932 src_addr,
2933 orig_src)));
2934 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
2935 dest_addr,
2936 orig_dest),
2937 tmp_reg);
3933e0e1
MM
2938 }
2939
2940 if (num_reg >= MAX_MOVE_REG)
2941 {
2942 for (i = 0; i < num_reg; i++)
2943 emit_insn (stores[i]);
2944 num_reg = 0;
7e69e155
MM
2945 }
2946 }
3933e0e1 2947
b6c9286a
MM
2948 for (i = 0; i < num_reg; i++)
2949 emit_insn (stores[i]);
7e69e155
MM
2950 }
2951
2952 return 1;
2953}
2954
9878760c
RK
2955\f
2956/* Return 1 if OP is a load multiple operation. It is known to be a
2957 PARALLEL and the first section will be tested. */
2958
2959int
2960load_multiple_operation (op, mode)
2961 rtx op;
296b8152 2962 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
2963{
2964 int count = XVECLEN (op, 0);
e2c953b6 2965 unsigned int dest_regno;
9878760c
RK
2966 rtx src_addr;
2967 int i;
2968
2969 /* Perform a quick check so we don't blow up below. */
2970 if (count <= 1
2971 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2972 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
2973 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
2974 return 0;
2975
2976 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
2977 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
2978
2979 for (i = 1; i < count; i++)
2980 {
2981 rtx elt = XVECEXP (op, 0, i);
2982
2983 if (GET_CODE (elt) != SET
2984 || GET_CODE (SET_DEST (elt)) != REG
2985 || GET_MODE (SET_DEST (elt)) != SImode
2986 || REGNO (SET_DEST (elt)) != dest_regno + i
2987 || GET_CODE (SET_SRC (elt)) != MEM
2988 || GET_MODE (SET_SRC (elt)) != SImode
2989 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2990 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2991 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2992 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
2993 return 0;
2994 }
2995
2996 return 1;
2997}
2998
2999/* Similar, but tests for store multiple. Here, the second vector element
3000 is a CLOBBER. It will be tested later. */
3001
3002int
3003store_multiple_operation (op, mode)
3004 rtx op;
296b8152 3005 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
3006{
3007 int count = XVECLEN (op, 0) - 1;
e2c953b6 3008 unsigned int src_regno;
9878760c
RK
3009 rtx dest_addr;
3010 int i;
3011
3012 /* Perform a quick check so we don't blow up below. */
3013 if (count <= 1
3014 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3015 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3016 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3017 return 0;
3018
3019 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3020 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3021
3022 for (i = 1; i < count; i++)
3023 {
3024 rtx elt = XVECEXP (op, 0, i + 1);
3025
3026 if (GET_CODE (elt) != SET
3027 || GET_CODE (SET_SRC (elt)) != REG
3028 || GET_MODE (SET_SRC (elt)) != SImode
3029 || REGNO (SET_SRC (elt)) != src_regno + i
3030 || GET_CODE (SET_DEST (elt)) != MEM
3031 || GET_MODE (SET_DEST (elt)) != SImode
3032 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
3033 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
3034 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
3035 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
3036 return 0;
3037 }
3038
3039 return 1;
3040}
9ebbca7d
GK
3041
3042/* Return 1 for an PARALLEL suitable for mtcrf. */
3043
3044int
3045mtcrf_operation (op, mode)
3046 rtx op;
3047 enum machine_mode mode ATTRIBUTE_UNUSED;
3048{
3049 int count = XVECLEN (op, 0);
3050 int i;
9ebbca7d
GK
3051 rtx src_reg;
3052
3053 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
3054 if (count < 1
3055 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3056 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
3057 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 3058 return 0;
e35b9579 3059 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
3060
3061 if (GET_CODE (src_reg) != REG
3062 || GET_MODE (src_reg) != SImode
3063 || ! INT_REGNO_P (REGNO (src_reg)))
3064 return 0;
3065
e35b9579 3066 for (i = 0; i < count; i++)
9ebbca7d
GK
3067 {
3068 rtx exp = XVECEXP (op, 0, i);
3069 rtx unspec;
3070 int maskval;
3071
3072 if (GET_CODE (exp) != SET
3073 || GET_CODE (SET_DEST (exp)) != REG
3074 || GET_MODE (SET_DEST (exp)) != CCmode
3075 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
3076 return 0;
3077 unspec = SET_SRC (exp);
3078 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
3079
3080 if (GET_CODE (unspec) != UNSPEC
3081 || XINT (unspec, 1) != 20
3082 || XVECLEN (unspec, 0) != 2
3083 || XVECEXP (unspec, 0, 0) != src_reg
3084 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
3085 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
3086 return 0;
3087 }
e35b9579 3088 return 1;
9ebbca7d
GK
3089}
3090
3091/* Return 1 for an PARALLEL suitable for lmw. */
3092
3093int
3094lmw_operation (op, mode)
3095 rtx op;
3096 enum machine_mode mode ATTRIBUTE_UNUSED;
3097{
3098 int count = XVECLEN (op, 0);
e2c953b6 3099 unsigned int dest_regno;
9ebbca7d 3100 rtx src_addr;
e2c953b6 3101 unsigned int base_regno;
9ebbca7d
GK
3102 HOST_WIDE_INT offset;
3103 int i;
3104
3105 /* Perform a quick check so we don't blow up below. */
3106 if (count <= 1
3107 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3108 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
3109 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
3110 return 0;
3111
3112 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
3113 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
3114
3115 if (dest_regno > 31
e2c953b6 3116 || count != 32 - (int) dest_regno)
9ebbca7d
GK
3117 return 0;
3118
3119 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr))
3120 {
3121 offset = 0;
3122 base_regno = REGNO (src_addr);
3123 if (base_regno == 0)
3124 return 0;
3125 }
3126 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr))
3127 {
3128 offset = INTVAL (XEXP (src_addr, 1));
3129 base_regno = REGNO (XEXP (src_addr, 0));
3130 }
3131 else
3132 return 0;
3133
3134 for (i = 0; i < count; i++)
3135 {
3136 rtx elt = XVECEXP (op, 0, i);
3137 rtx newaddr;
3138 rtx addr_reg;
3139 HOST_WIDE_INT newoffset;
3140
3141 if (GET_CODE (elt) != SET
3142 || GET_CODE (SET_DEST (elt)) != REG
3143 || GET_MODE (SET_DEST (elt)) != SImode
3144 || REGNO (SET_DEST (elt)) != dest_regno + i
3145 || GET_CODE (SET_SRC (elt)) != MEM
3146 || GET_MODE (SET_SRC (elt)) != SImode)
3147 return 0;
3148 newaddr = XEXP (SET_SRC (elt), 0);
3149 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3150 {
3151 newoffset = 0;
3152 addr_reg = newaddr;
3153 }
3154 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3155 {
3156 addr_reg = XEXP (newaddr, 0);
3157 newoffset = INTVAL (XEXP (newaddr, 1));
3158 }
3159 else
3160 return 0;
3161 if (REGNO (addr_reg) != base_regno
3162 || newoffset != offset + 4 * i)
3163 return 0;
3164 }
3165
3166 return 1;
3167}
3168
3169/* Return 1 for an PARALLEL suitable for stmw. */
3170
3171int
3172stmw_operation (op, mode)
3173 rtx op;
3174 enum machine_mode mode ATTRIBUTE_UNUSED;
3175{
3176 int count = XVECLEN (op, 0);
e2c953b6 3177 unsigned int src_regno;
9ebbca7d 3178 rtx dest_addr;
e2c953b6 3179 unsigned int base_regno;
9ebbca7d
GK
3180 HOST_WIDE_INT offset;
3181 int i;
3182
3183 /* Perform a quick check so we don't blow up below. */
3184 if (count <= 1
3185 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3186 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3187 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3188 return 0;
3189
3190 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3191 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3192
3193 if (src_regno > 31
e2c953b6 3194 || count != 32 - (int) src_regno)
9ebbca7d
GK
3195 return 0;
3196
3197 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr))
3198 {
3199 offset = 0;
3200 base_regno = REGNO (dest_addr);
3201 if (base_regno == 0)
3202 return 0;
3203 }
3204 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr))
3205 {
3206 offset = INTVAL (XEXP (dest_addr, 1));
3207 base_regno = REGNO (XEXP (dest_addr, 0));
3208 }
3209 else
3210 return 0;
3211
3212 for (i = 0; i < count; i++)
3213 {
3214 rtx elt = XVECEXP (op, 0, i);
3215 rtx newaddr;
3216 rtx addr_reg;
3217 HOST_WIDE_INT newoffset;
3218
3219 if (GET_CODE (elt) != SET
3220 || GET_CODE (SET_SRC (elt)) != REG
3221 || GET_MODE (SET_SRC (elt)) != SImode
3222 || REGNO (SET_SRC (elt)) != src_regno + i
3223 || GET_CODE (SET_DEST (elt)) != MEM
3224 || GET_MODE (SET_DEST (elt)) != SImode)
3225 return 0;
3226 newaddr = XEXP (SET_DEST (elt), 0);
3227 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3228 {
3229 newoffset = 0;
3230 addr_reg = newaddr;
3231 }
3232 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3233 {
3234 addr_reg = XEXP (newaddr, 0);
3235 newoffset = INTVAL (XEXP (newaddr, 1));
3236 }
3237 else
3238 return 0;
3239 if (REGNO (addr_reg) != base_regno
3240 || newoffset != offset + 4 * i)
3241 return 0;
3242 }
3243
3244 return 1;
3245}
9878760c 3246\f
39a10a29
GK
3247
3248/* A validation routine: say whether CODE, a condition code,
3249 and MODE match. The other alternatives either don't make
3250 sense or should never be generated. */
3251static void
3252validate_condition_mode (code, mode)
3253 enum rtx_code code;
3254 enum machine_mode mode;
3255{
3256 if (GET_RTX_CLASS (code) != '<'
3257 || GET_MODE_CLASS (mode) != MODE_CC)
3258 abort ();
3259
3260 /* These don't make sense. */
3261 if ((code == GT || code == LT || code == GE || code == LE)
3262 && mode == CCUNSmode)
3263 abort ();
3264
3265 if ((code == GTU || code == LTU || code == GEU || code == LEU)
3266 && mode != CCUNSmode)
3267 abort ();
3268
3269 if (mode != CCFPmode
3270 && (code == ORDERED || code == UNORDERED
3271 || code == UNEQ || code == LTGT
3272 || code == UNGT || code == UNLT
3273 || code == UNGE || code == UNLE))
3274 abort();
3275
de6c5979
BL
3276 /* These should never be generated except for
3277 flag_unsafe_math_optimizations. */
39a10a29 3278 if (mode == CCFPmode
de6c5979 3279 && ! flag_unsafe_math_optimizations
39a10a29
GK
3280 && (code == LE || code == GE
3281 || code == UNEQ || code == LTGT
3282 || code == UNGT || code == UNLT))
3283 abort ();
3284
3285 /* These are invalid; the information is not there. */
3286 if (mode == CCEQmode
3287 && code != EQ && code != NE)
3288 abort ();
3289}
3290
9878760c
RK
3291/* Return 1 if OP is a comparison operation that is valid for a branch insn.
3292 We only check the opcode against the mode of the CC value here. */
3293
3294int
3295branch_comparison_operator (op, mode)
3296 register rtx op;
296b8152 3297 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
3298{
3299 enum rtx_code code = GET_CODE (op);
3300 enum machine_mode cc_mode;
3301
3302 if (GET_RTX_CLASS (code) != '<')
3303 return 0;
3304
3305 cc_mode = GET_MODE (XEXP (op, 0));
3306 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3307 return 0;
3308
39a10a29 3309 validate_condition_mode (code, cc_mode);
9878760c 3310
39a10a29
GK
3311 return 1;
3312}
3313
3314/* Return 1 if OP is a comparison operation that is valid for a branch
3315 insn and which is true if the corresponding bit in the CC register
3316 is set. */
3317
3318int
3319branch_positive_comparison_operator (op, mode)
3320 register rtx op;
3321 enum machine_mode mode;
3322{
3323 enum rtx_code code;
3324
3325 if (! branch_comparison_operator (op, mode))
9878760c
RK
3326 return 0;
3327
39a10a29
GK
3328 code = GET_CODE (op);
3329 return (code == EQ || code == LT || code == GT
3330 || code == LTU || code == GTU
3331 || code == UNORDERED);
9878760c
RK
3332}
3333
39a10a29 3334
9878760c
RK
3335/* Return 1 if OP is a comparison operation that is valid for an scc insn.
3336 We check the opcode against the mode of the CC value and disallow EQ or
3337 NE comparisons for integers. */
3338
3339int
3340scc_comparison_operator (op, mode)
3341 register rtx op;
3342 enum machine_mode mode;
3343{
3344 enum rtx_code code = GET_CODE (op);
3345 enum machine_mode cc_mode;
3346
3347 if (GET_MODE (op) != mode && mode != VOIDmode)
3348 return 0;
3349
3350 if (GET_RTX_CLASS (code) != '<')
3351 return 0;
3352
3353 cc_mode = GET_MODE (XEXP (op, 0));
3354 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3355 return 0;
3356
39a10a29 3357 validate_condition_mode (code, cc_mode);
9878760c 3358
39a10a29 3359 if (code == NE && cc_mode != CCFPmode)
c5defebb
RK
3360 return 0;
3361
9878760c
RK
3362 return 1;
3363}
e0cd0770
JC
3364
3365int
3366trap_comparison_operator (op, mode)
3367 rtx op;
3368 enum machine_mode mode;
3369{
3370 if (mode != VOIDmode && mode != GET_MODE (op))
3371 return 0;
39a10a29 3372 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 3373}
dfbdccdb
GK
3374
3375int
3376boolean_operator (op, mode)
3377 rtx op;
3378 enum machine_mode mode ATTRIBUTE_UNUSED;
3379{
3380 enum rtx_code code = GET_CODE (op);
3381 return (code == AND || code == IOR || code == XOR);
3382}
1d328b19
GK
3383
3384int
3385boolean_or_operator (op, mode)
3386 rtx op;
3387 enum machine_mode mode ATTRIBUTE_UNUSED;
3388{
3389 enum rtx_code code = GET_CODE (op);
3390 return (code == IOR || code == XOR);
3391}
9878760c
RK
3392\f
3393/* Return 1 if ANDOP is a mask that has no bits on that are not in the
3394 mask required to convert the result of a rotate insn into a shift
3395 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
3396
3397int
3398includes_lshift_p (shiftop, andop)
3399 register rtx shiftop;
3400 register rtx andop;
3401{
e2c953b6
DE
3402 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3403
3404 shift_mask <<= INTVAL (shiftop);
9878760c
RK
3405
3406 return (INTVAL (andop) & ~shift_mask) == 0;
3407}
3408
3409/* Similar, but for right shift. */
3410
3411int
3412includes_rshift_p (shiftop, andop)
3413 register rtx shiftop;
3414 register rtx andop;
3415{
a7653a2c 3416 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
3417
3418 shift_mask >>= INTVAL (shiftop);
3419
e2c953b6
DE
3420 return (INTVAL (andop) & ~shift_mask) == 0;
3421}
3422
3423/* Return 1 if ANDOP is a mask that has no bits on that are not in the
3424 mask required to convert the result of a rotate insn into a shift
3425 left insn of SHIFTOP bits. */
3426
3427int
3428includes_lshift64_p (shiftop, andop)
3429 register rtx shiftop;
3430 register rtx andop;
3431{
3432#if HOST_BITS_PER_WIDE_INT == 64
3433 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3434
3435 shift_mask <<= INTVAL (shiftop);
3436
3437 return (INTVAL (andop) & ~shift_mask) == 0;
3438#else
3439 unsigned HOST_WIDE_INT shift_mask_low = ~(unsigned HOST_WIDE_INT) 0;
3440 unsigned HOST_WIDE_INT shift_mask_high = ~(unsigned HOST_WIDE_INT) 0;
3441
3442 shift_mask_low <<= INTVAL (shiftop);
3443
3444 if (INTVAL (shiftop) > 32)
3445 shift_mask_high <<= (INTVAL (shiftop) - 32);
3446
3447 if (GET_CODE (andop) == CONST_INT)
3448 return (INTVAL (andop) & ~shift_mask_low) == 0;
3449 else
3450 return ((CONST_DOUBLE_HIGH (andop) & ~shift_mask_high) == 0
3451 && (CONST_DOUBLE_LOW (andop) & ~shift_mask_low) == 0);
3452#endif
9878760c 3453}
35068b43
RK
3454
3455/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
3456 for lfq and stfq insns.
3457
3458 Note reg1 and reg2 *must* be hard registers. To be sure we will
3459 abort if we are passed pseudo registers. */
3460
3461int
3462registers_ok_for_quad_peep (reg1, reg2)
3463 rtx reg1, reg2;
3464{
3465 /* We might have been passed a SUBREG. */
3466 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
3467 return 0;
3468
3469 return (REGNO (reg1) == REGNO (reg2) - 1);
3470}
3471
3472/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
3473 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
3474
3475int
3476addrs_ok_for_quad_peep (addr1, addr2)
3477 register rtx addr1;
3478 register rtx addr2;
3479{
e2c953b6 3480 unsigned int reg1;
35068b43
RK
3481 int offset1;
3482
3483 /* Extract an offset (if used) from the first addr. */
3484 if (GET_CODE (addr1) == PLUS)
3485 {
3486 /* If not a REG, return zero. */
3487 if (GET_CODE (XEXP (addr1, 0)) != REG)
3488 return 0;
3489 else
3490 {
3491 reg1 = REGNO (XEXP (addr1, 0));
3492 /* The offset must be constant! */
3493 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
3494 return 0;
3495 offset1 = INTVAL (XEXP (addr1, 1));
3496 }
3497 }
3498 else if (GET_CODE (addr1) != REG)
3499 return 0;
3500 else
3501 {
3502 reg1 = REGNO (addr1);
3503 /* This was a simple (mem (reg)) expression. Offset is 0. */
3504 offset1 = 0;
3505 }
3506
acad7ed3 3507 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
35068b43
RK
3508 if (GET_CODE (addr2) != PLUS)
3509 return 0;
3510
3511 if (GET_CODE (XEXP (addr2, 0)) != REG
3512 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
3513 return 0;
3514
3515 if (reg1 != REGNO (XEXP (addr2, 0)))
3516 return 0;
3517
3518 /* The offset for the second addr must be 8 more than the first addr. */
3519 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
3520 return 0;
3521
3522 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
3523 instructions. */
3524 return 1;
3525}
9878760c
RK
3526\f
3527/* Return the register class of a scratch register needed to copy IN into
3528 or out of a register in CLASS in MODE. If it can be done directly,
3529 NO_REGS is returned. */
3530
3531enum reg_class
3532secondary_reload_class (class, mode, in)
3533 enum reg_class class;
296b8152 3534 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
3535 rtx in;
3536{
5accd822 3537 int regno;
9878760c 3538
3cb999d8 3539#if TARGET_ELF
1427100a 3540 /* We can not copy a symbolic operand directly into anything other than
e7b7998a
JL
3541 BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS
3542 is needed as an intermediate register. */
3cb999d8 3543 if (class != BASE_REGS
e7b7998a 3544 && (GET_CODE (in) == SYMBOL_REF
201b6183 3545 || GET_CODE (in) == HIGH
e7b7998a
JL
3546 || GET_CODE (in) == LABEL_REF
3547 || GET_CODE (in) == CONST))
3548 return BASE_REGS;
3cb999d8 3549#endif
e7b7998a 3550
5accd822
DE
3551 if (GET_CODE (in) == REG)
3552 {
3553 regno = REGNO (in);
3554 if (regno >= FIRST_PSEUDO_REGISTER)
3555 {
3556 regno = true_regnum (in);
3557 if (regno >= FIRST_PSEUDO_REGISTER)
3558 regno = -1;
3559 }
3560 }
3561 else if (GET_CODE (in) == SUBREG)
3562 {
3563 regno = true_regnum (in);
3564 if (regno >= FIRST_PSEUDO_REGISTER)
3565 regno = -1;
3566 }
3567 else
3568 regno = -1;
3569
9878760c
RK
3570 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
3571 into anything. */
3572 if (class == GENERAL_REGS || class == BASE_REGS
3573 || (regno >= 0 && INT_REGNO_P (regno)))
3574 return NO_REGS;
3575
3576 /* Constants, memory, and FP registers can go into FP registers. */
3577 if ((regno == -1 || FP_REGNO_P (regno))
3578 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
3579 return NO_REGS;
3580
3581 /* We can copy among the CR registers. */
3582 if ((class == CR_REGS || class == CR0_REGS)
3583 && regno >= 0 && CR_REGNO_P (regno))
3584 return NO_REGS;
3585
3586 /* Otherwise, we need GENERAL_REGS. */
3587 return GENERAL_REGS;
3588}
3589\f
3590/* Given a comparison operation, return the bit number in CCR to test. We
3591 know this is a valid comparison.
3592
3593 SCC_P is 1 if this is for an scc. That means that %D will have been
3594 used instead of %C, so the bits will be in different places.
3595
b4ac57ab 3596 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
3597
3598int
3599ccr_bit (op, scc_p)
3600 register rtx op;
3601 int scc_p;
3602{
3603 enum rtx_code code = GET_CODE (op);
3604 enum machine_mode cc_mode;
3605 int cc_regnum;
3606 int base_bit;
9ebbca7d 3607 rtx reg;
9878760c
RK
3608
3609 if (GET_RTX_CLASS (code) != '<')
3610 return -1;
3611
9ebbca7d
GK
3612 reg = XEXP (op, 0);
3613
3614 if (GET_CODE (reg) != REG
3615 || ! CR_REGNO_P (REGNO (reg)))
3616 abort ();
3617
3618 cc_mode = GET_MODE (reg);
3619 cc_regnum = REGNO (reg);
3620 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 3621
39a10a29 3622 validate_condition_mode (code, cc_mode);
c5defebb 3623
9878760c
RK
3624 switch (code)
3625 {
3626 case NE:
3627 return scc_p ? base_bit + 3 : base_bit + 2;
3628 case EQ:
3629 return base_bit + 2;
1c882ea4 3630 case GT: case GTU: case UNLE:
9878760c 3631 return base_bit + 1;
1c882ea4 3632 case LT: case LTU: case UNGE:
9878760c 3633 return base_bit;
1c882ea4
GK
3634 case ORDERED: case UNORDERED:
3635 return base_bit + 3;
9878760c
RK
3636
3637 case GE: case GEU:
39a10a29 3638 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
3639 unordered position. So test that bit. For integer, this is ! LT
3640 unless this is an scc insn. */
39a10a29 3641 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
3642
3643 case LE: case LEU:
39a10a29 3644 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 3645
9878760c
RK
3646 default:
3647 abort ();
3648 }
3649}
1ff7789b 3650\f
8d30c4ee 3651/* Return the GOT register. */
1ff7789b
MM
3652
3653struct rtx_def *
3654rs6000_got_register (value)
5f59ecb7 3655 rtx value ATTRIBUTE_UNUSED;
1ff7789b 3656{
8d30c4ee
FS
3657 /* The second flow pass currently (June 1999) can't update regs_ever_live
3658 without disturbing other parts of the compiler, so update it here to
3659 make the prolog/epilogue code happy. */
3cb999d8 3660 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
8d30c4ee 3661 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 3662
8d30c4ee 3663 current_function_uses_pic_offset_table = 1;
3cb999d8 3664
1ff7789b
MM
3665 return pic_offset_table_rtx;
3666}
a7df97e6 3667\f
71f123ca 3668/* Functions to init, mark and free struct machine_function.
a7df97e6
MM
3669 These will be called, via pointer variables,
3670 from push_function_context and pop_function_context. */
3671
00dba523
NC
3672static void
3673rs6000_init_machine_status (p)
a7df97e6
MM
3674 struct function *p;
3675{
71f123ca
FS
3676 p->machine = (machine_function *) xcalloc (1, sizeof (machine_function));
3677}
a7df97e6 3678
71f123ca
FS
3679static void
3680rs6000_mark_machine_status (p)
3681 struct function *p;
3682{
3683 if (p->machine)
3684 ggc_mark_rtx (p->machine->ra_rtx);
a7df97e6
MM
3685}
3686
00dba523
NC
3687static void
3688rs6000_free_machine_status (p)
a7df97e6
MM
3689 struct function *p;
3690{
00dba523
NC
3691 if (p->machine == NULL)
3692 return;
a7df97e6 3693
00dba523
NC
3694 free (p->machine);
3695 p->machine = NULL;
a7df97e6
MM
3696}
3697
9878760c
RK
3698\f
3699/* Print an operand. Recognize special options, documented below. */
3700
38c1f2d7 3701#if TARGET_ELF
d9407988 3702#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 3703#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
3704#else
3705#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 3706#define SMALL_DATA_REG 0
ba5e43aa
MM
3707#endif
3708
9878760c
RK
3709void
3710print_operand (file, x, code)
3711 FILE *file;
3712 rtx x;
9ebbca7d 3713 int code;
9878760c
RK
3714{
3715 int i;
a260abc9 3716 HOST_WIDE_INT val;
9878760c
RK
3717
3718 /* These macros test for integers and extract the low-order bits. */
3719#define INT_P(X) \
3720((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
3721 && GET_MODE (X) == VOIDmode)
3722
3723#define INT_LOWPART(X) \
3724 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
3725
3726 switch (code)
3727 {
a8b3aeda 3728 case '.':
a85d226b
RK
3729 /* Write out an instruction after the call which may be replaced
3730 with glue code by the loader. This depends on the AIX version. */
3731 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
3732 return;
3733
c81bebd7
MM
3734 case '$':
3735 /* Write out either a '.' or '$' for the current location, depending
3736 on whether this is Solaris or not. */
3737 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
3738 return;
3739
81eace42
GK
3740 /* %a is output_address. */
3741
9854d9ed
RK
3742 case 'A':
3743 /* If X is a constant integer whose low-order 5 bits are zero,
3744 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 3745 in the AIX assembler where "sri" with a zero shift count
9854d9ed
RK
3746 write a trash instruction. */
3747 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 3748 putc ('l', file);
9854d9ed 3749 else
76229ac8 3750 putc ('r', file);
9854d9ed
RK
3751 return;
3752
3753 case 'b':
e2c953b6
DE
3754 /* If constant, low-order 16 bits of constant, unsigned.
3755 Otherwise, write normally. */
3756 if (INT_P (x))
3757 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
3758 else
3759 print_operand (file, x, 0);
cad12a8d
RK
3760 return;
3761
a260abc9
DE
3762 case 'B':
3763 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
3764 for 64-bit mask direction. */
296b8152 3765 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 3766 return;
a260abc9 3767
81eace42
GK
3768 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
3769 output_operand. */
3770
9854d9ed 3771 case 'D':
39a10a29
GK
3772 /* There used to be a comment for 'C' reading "This is an
3773 optional cror needed for certain floating-point
3774 comparisons. Otherwise write nothing." */
3775
9854d9ed
RK
3776 /* Similar, except that this is for an scc, so we must be able to
3777 encode the test in a single bit that is one. We do the above
3778 for any LE, GE, GEU, or LEU and invert the bit for NE. */
3779 if (GET_CODE (x) == LE || GET_CODE (x) == GE
3780 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
3781 {
9ebbca7d 3782 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
3783
3784 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
3785 base_bit + 2,
3786 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
3787 }
3788
3789 else if (GET_CODE (x) == NE)
3790 {
9ebbca7d 3791 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
3792
3793 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
3794 base_bit + 2, base_bit + 2);
3795 }
3796 return;
3797
3798 case 'E':
39a10a29 3799 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
3800 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3801 output_operand_lossage ("invalid %%E value");
78fbdbf7 3802 else
39a10a29 3803 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 3804 return;
9854d9ed
RK
3805
3806 case 'f':
3807 /* X is a CR register. Print the shift count needed to move it
3808 to the high-order four bits. */
3809 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3810 output_operand_lossage ("invalid %%f value");
3811 else
9ebbca7d 3812 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
3813 return;
3814
3815 case 'F':
3816 /* Similar, but print the count for the rotate in the opposite
3817 direction. */
3818 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3819 output_operand_lossage ("invalid %%F value");
3820 else
9ebbca7d 3821 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
3822 return;
3823
3824 case 'G':
3825 /* X is a constant integer. If it is negative, print "m",
3826 otherwise print "z". This is to make a aze or ame insn. */
3827 if (GET_CODE (x) != CONST_INT)
3828 output_operand_lossage ("invalid %%G value");
3829 else if (INTVAL (x) >= 0)
76229ac8 3830 putc ('z', file);
9854d9ed 3831 else
76229ac8 3832 putc ('m', file);
9854d9ed 3833 return;
e2c953b6 3834
9878760c 3835 case 'h':
df3d94ed
RK
3836 /* If constant, output low-order five bits. Otherwise,
3837 write normally. */
9878760c 3838 if (INT_P (x))
5f59ecb7 3839 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
3840 else
3841 print_operand (file, x, 0);
3842 return;
3843
64305719
DE
3844 case 'H':
3845 /* If constant, output low-order six bits. Otherwise,
3846 write normally. */
3847 if (INT_P (x))
5f59ecb7 3848 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
3849 else
3850 print_operand (file, x, 0);
3851 return;
3852
9854d9ed
RK
3853 case 'I':
3854 /* Print `i' if this is a constant, else nothing. */
9878760c 3855 if (INT_P (x))
76229ac8 3856 putc ('i', file);
9878760c
RK
3857 return;
3858
9854d9ed
RK
3859 case 'j':
3860 /* Write the bit number in CCR for jump. */
3861 i = ccr_bit (x, 0);
3862 if (i == -1)
3863 output_operand_lossage ("invalid %%j code");
9878760c 3864 else
9854d9ed 3865 fprintf (file, "%d", i);
9878760c
RK
3866 return;
3867
9854d9ed
RK
3868 case 'J':
3869 /* Similar, but add one for shift count in rlinm for scc and pass
3870 scc flag to `ccr_bit'. */
3871 i = ccr_bit (x, 1);
3872 if (i == -1)
3873 output_operand_lossage ("invalid %%J code");
3874 else
a0466a68
RK
3875 /* If we want bit 31, write a shift count of zero, not 32. */
3876 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
3877 return;
3878
9854d9ed
RK
3879 case 'k':
3880 /* X must be a constant. Write the 1's complement of the
3881 constant. */
9878760c 3882 if (! INT_P (x))
9854d9ed 3883 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
3884 else
3885 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
3886 return;
3887
81eace42 3888 case 'K':
9ebbca7d
GK
3889 /* X must be a symbolic constant on ELF. Write an
3890 expression suitable for an 'addi' that adds in the low 16
3891 bits of the MEM. */
3892 if (GET_CODE (x) != CONST)
3893 {
3894 print_operand_address (file, x);
3895 fputs ("@l", file);
3896 }
3897 else
3898 {
3899 if (GET_CODE (XEXP (x, 0)) != PLUS
3900 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
3901 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3902 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 3903 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
3904 print_operand_address (file, XEXP (XEXP (x, 0), 0));
3905 fputs ("@l", file);
3906 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
3907 }
81eace42
GK
3908 return;
3909
3910 /* %l is output_asm_label. */
9ebbca7d 3911
9854d9ed
RK
3912 case 'L':
3913 /* Write second word of DImode or DFmode reference. Works on register
3914 or non-indexed memory only. */
3915 if (GET_CODE (x) == REG)
5ebfb2ba 3916 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
3917 else if (GET_CODE (x) == MEM)
3918 {
3919 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 3920 we have already done it, we can just use an offset of word. */
9854d9ed
RK
3921 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3922 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
19087b1c
DE
3923 output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0),
3924 UNITS_PER_WORD));
9854d9ed 3925 else
19087b1c
DE
3926 output_address (plus_constant_for_output (XEXP (x, 0),
3927 UNITS_PER_WORD));
ba5e43aa 3928 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
3929 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3930 reg_names[SMALL_DATA_REG]);
9854d9ed 3931 }
9878760c 3932 return;
9854d9ed 3933
9878760c
RK
3934 case 'm':
3935 /* MB value for a mask operand. */
3936 if (! mask_operand (x, VOIDmode))
3937 output_operand_lossage ("invalid %%m value");
3938
3939 val = INT_LOWPART (x);
3940
3941 /* If the high bit is set and the low bit is not, the value is zero.
3942 If the high bit is zero, the value is the first 1 bit we find from
3943 the left. */
0858c623 3944 if ((val & 0x80000000) && ((val & 1) == 0))
9878760c 3945 {
19d2d16f 3946 putc ('0', file);
9878760c
RK
3947 return;
3948 }
0858c623 3949 else if ((val & 0x80000000) == 0)
9878760c
RK
3950 {
3951 for (i = 1; i < 32; i++)
0858c623 3952 if ((val <<= 1) & 0x80000000)
9878760c
RK
3953 break;
3954 fprintf (file, "%d", i);
3955 return;
3956 }
3957
3958 /* Otherwise, look for the first 0 bit from the right. The result is its
3959 number plus 1. We know the low-order bit is one. */
3960 for (i = 0; i < 32; i++)
3961 if (((val >>= 1) & 1) == 0)
3962 break;
3963
a260abc9 3964 /* If we ended in ...01, i would be 0. The correct value is 31, so
9878760c
RK
3965 we want 31 - i. */
3966 fprintf (file, "%d", 31 - i);
3967 return;
3968
3969 case 'M':
3970 /* ME value for a mask operand. */
3971 if (! mask_operand (x, VOIDmode))
a260abc9 3972 output_operand_lossage ("invalid %%M value");
9878760c
RK
3973
3974 val = INT_LOWPART (x);
3975
3976 /* If the low bit is set and the high bit is not, the value is 31.
3977 If the low bit is zero, the value is the first 1 bit we find from
3978 the right. */
0858c623 3979 if ((val & 1) && ((val & 0x80000000) == 0))
9878760c 3980 {
76229ac8 3981 fputs ("31", file);
9878760c
RK
3982 return;
3983 }
3984 else if ((val & 1) == 0)
3985 {
3986 for (i = 0; i < 32; i++)
3987 if ((val >>= 1) & 1)
3988 break;
3989
a260abc9 3990 /* If we had ....10, i would be 0. The result should be
9878760c
RK
3991 30, so we need 30 - i. */
3992 fprintf (file, "%d", 30 - i);
3993 return;
3994 }
3995
3996 /* Otherwise, look for the first 0 bit from the left. The result is its
3997 number minus 1. We know the high-order bit is one. */
3998 for (i = 0; i < 32; i++)
0858c623 3999 if (((val <<= 1) & 0x80000000) == 0)
9878760c
RK
4000 break;
4001
4002 fprintf (file, "%d", i);
4003 return;
4004
81eace42
GK
4005 /* %n outputs the negative of its operand. */
4006
9878760c
RK
4007 case 'N':
4008 /* Write the number of elements in the vector times 4. */
4009 if (GET_CODE (x) != PARALLEL)
4010 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
4011 else
4012 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
4013 return;
4014
4015 case 'O':
4016 /* Similar, but subtract 1 first. */
4017 if (GET_CODE (x) != PARALLEL)
1427100a 4018 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
4019 else
4020 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
4021 return;
4022
9854d9ed
RK
4023 case 'p':
4024 /* X is a CONST_INT that is a power of two. Output the logarithm. */
4025 if (! INT_P (x)
4026 || (i = exact_log2 (INT_LOWPART (x))) < 0)
4027 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
4028 else
4029 fprintf (file, "%d", i);
9854d9ed
RK
4030 return;
4031
9878760c
RK
4032 case 'P':
4033 /* The operand must be an indirect memory reference. The result
4034 is the register number. */
4035 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
4036 || REGNO (XEXP (x, 0)) >= 32)
4037 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
4038 else
4039 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
4040 return;
4041
dfbdccdb
GK
4042 case 'q':
4043 /* This outputs the logical code corresponding to a boolean
4044 expression. The expression may have one or both operands
39a10a29
GK
4045 negated (if one, only the first one). For condition register
4046 logical operations, it will also treat the negated
4047 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 4048 {
63bc1d05 4049 const char *const *t = 0;
dfbdccdb
GK
4050 const char *s;
4051 enum rtx_code code = GET_CODE (x);
4052 static const char * const tbl[3][3] = {
4053 { "and", "andc", "nor" },
4054 { "or", "orc", "nand" },
4055 { "xor", "eqv", "xor" } };
4056
4057 if (code == AND)
4058 t = tbl[0];
4059 else if (code == IOR)
4060 t = tbl[1];
4061 else if (code == XOR)
4062 t = tbl[2];
4063 else
4064 output_operand_lossage ("invalid %%q value");
4065
4066 if (GET_CODE (XEXP (x, 0)) != NOT)
4067 s = t[0];
4068 else
4069 {
4070 if (GET_CODE (XEXP (x, 1)) == NOT)
4071 s = t[2];
4072 else
4073 s = t[1];
4074 }
4075
4076 fputs (s, file);
4077 }
4078 return;
4079
9854d9ed
RK
4080 case 'R':
4081 /* X is a CR register. Print the mask for `mtcrf'. */
4082 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
4083 output_operand_lossage ("invalid %%R value");
4084 else
9ebbca7d 4085 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 4086 return;
9854d9ed
RK
4087
4088 case 's':
4089 /* Low 5 bits of 32 - value */
4090 if (! INT_P (x))
4091 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
4092 else
4093 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 4094 return;
9854d9ed 4095
a260abc9
DE
4096 case 'S':
4097 /* PowerPC64 mask position. All 0's and all 1's are excluded.
4098 CONST_INT 32-bit mask is considered sign-extended so any
4099 transition must occur within the CONST_INT, not on the boundary. */
4100 if (! mask64_operand (x, VOIDmode))
4101 output_operand_lossage ("invalid %%S value");
4102
4103 val = INT_LOWPART (x);
4104
4105 if (val & 1) /* Clear Left */
4106 {
a238cd8b
DE
4107 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4108 if (!((val >>= 1) & 1))
4109 break;
a260abc9 4110
a238cd8b
DE
4111#if HOST_BITS_PER_WIDE_INT == 32
4112 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4113 {
4114 val = CONST_DOUBLE_HIGH (x);
4115
4116 if (val == 0)
4117 --i;
4118 else
4119 for (i = 32; i < 64; i++)
4120 if (!((val >>= 1) & 1))
4121 break;
4122 }
a260abc9 4123#endif
a238cd8b
DE
4124 /* i = index of last set bit from right
4125 mask begins at 63 - i from left */
4126 if (i > 63)
4127 output_operand_lossage ("%%S computed all 1's mask");
cccf3bdc 4128
a260abc9
DE
4129 fprintf (file, "%d", 63 - i);
4130 return;
4131 }
4132 else /* Clear Right */
4133 {
a238cd8b
DE
4134 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4135 if ((val >>= 1) & 1)
4136 break;
a260abc9 4137
a238cd8b 4138#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
4139 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4140 {
a238cd8b 4141 val = CONST_DOUBLE_HIGH (x);
a260abc9 4142
a238cd8b 4143 if (val == (HOST_WIDE_INT) -1)
a260abc9 4144 --i;
a260abc9 4145 else
a238cd8b
DE
4146 for (i = 32; i < 64; i++)
4147 if ((val >>= 1) & 1)
a260abc9
DE
4148 break;
4149 }
4150#endif
a238cd8b
DE
4151 /* i = index of last clear bit from right
4152 mask ends at 62 - i from left */
4153 if (i > 62)
4154 output_operand_lossage ("%%S computed all 0's mask");
cccf3bdc 4155
a238cd8b 4156 fprintf (file, "%d", 62 - i);
a260abc9
DE
4157 return;
4158 }
4159
cccf3bdc
DE
4160 case 'T':
4161 /* Print the symbolic name of a branch target register. */
4162 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
4163 && REGNO (x) != COUNT_REGISTER_REGNUM))
4164 output_operand_lossage ("invalid %%T value");
e2c953b6 4165 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
4166 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
4167 else
4168 fputs ("ctr", file);
4169 return;
4170
9854d9ed 4171 case 'u':
802a0058 4172 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
4173 if (! INT_P (x))
4174 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
4175 else
4176 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
4177 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
4178 return;
4179
802a0058
MM
4180 case 'v':
4181 /* High-order 16 bits of constant for use in signed operand. */
4182 if (! INT_P (x))
4183 output_operand_lossage ("invalid %%v value");
e2c953b6
DE
4184 else
4185 {
4186 int value = (INT_LOWPART (x) >> 16) & 0xffff;
802a0058 4187
e2c953b6
DE
4188 /* Solaris assembler doesn't like lis 0,0x8000 */
4189 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
4190 fprintf (file, "%d", value | (~0 << 16));
4191 else
4192 fprintf (file, "0x%x", value);
4193 return;
4194 }
802a0058 4195
9854d9ed
RK
4196 case 'U':
4197 /* Print `u' if this has an auto-increment or auto-decrement. */
4198 if (GET_CODE (x) == MEM
4199 && (GET_CODE (XEXP (x, 0)) == PRE_INC
4200 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 4201 putc ('u', file);
9854d9ed 4202 return;
9878760c 4203
e0cd0770
JC
4204 case 'V':
4205 /* Print the trap code for this operand. */
4206 switch (GET_CODE (x))
4207 {
4208 case EQ:
4209 fputs ("eq", file); /* 4 */
4210 break;
4211 case NE:
4212 fputs ("ne", file); /* 24 */
4213 break;
4214 case LT:
4215 fputs ("lt", file); /* 16 */
4216 break;
4217 case LE:
4218 fputs ("le", file); /* 20 */
4219 break;
4220 case GT:
4221 fputs ("gt", file); /* 8 */
4222 break;
4223 case GE:
4224 fputs ("ge", file); /* 12 */
4225 break;
4226 case LTU:
4227 fputs ("llt", file); /* 2 */
4228 break;
4229 case LEU:
4230 fputs ("lle", file); /* 6 */
4231 break;
4232 case GTU:
4233 fputs ("lgt", file); /* 1 */
4234 break;
4235 case GEU:
4236 fputs ("lge", file); /* 5 */
4237 break;
4238 default:
4239 abort ();
4240 }
4241 break;
4242
9854d9ed
RK
4243 case 'w':
4244 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
4245 normally. */
4246 if (INT_P (x))
5f59ecb7
DE
4247 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
4248 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
4249 else
4250 print_operand (file, x, 0);
9878760c
RK
4251 return;
4252
9854d9ed 4253 case 'W':
e2c953b6
DE
4254 /* MB value for a PowerPC64 rldic operand. */
4255 if (! rldic_operand (x, VOIDmode))
4256 output_operand_lossage ("invalid %%W value");
4257
4258 val = (GET_CODE (x) == CONST_INT
4259 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
4260
4261 if (val < 0)
4262 i = -1;
9854d9ed 4263 else
e2c953b6
DE
4264 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4265 if ((val <<= 1) < 0)
4266 break;
4267
4268#if HOST_BITS_PER_WIDE_INT == 32
4269 if (GET_CODE (x) == CONST_INT && i >= 0)
4270 i += 32; /* zero-extend high-part was all 0's */
4271 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4272 {
4273 val = CONST_DOUBLE_LOW (x);
4274
4275 if (val == 0)
4276 abort();
4277 else if (val < 0)
4278 --i;
4279 else
4280 for ( ; i < 64; i++)
4281 if ((val <<= 1) < 0)
4282 break;
4283 }
4284#endif
4285
4286 fprintf (file, "%d", i + 1);
9854d9ed 4287 return;
9878760c 4288
9854d9ed
RK
4289 case 'X':
4290 if (GET_CODE (x) == MEM
4291 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
76229ac8 4292 putc ('x', file);
9854d9ed 4293 return;
9878760c 4294
9854d9ed
RK
4295 case 'Y':
4296 /* Like 'L', for third word of TImode */
4297 if (GET_CODE (x) == REG)
5ebfb2ba 4298 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 4299 else if (GET_CODE (x) == MEM)
9878760c 4300 {
9854d9ed
RK
4301 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4302 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 4303 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 4304 else
a54d04b7 4305 output_address (plus_constant (XEXP (x, 0), 8));
ba5e43aa 4306 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
4307 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4308 reg_names[SMALL_DATA_REG]);
9878760c
RK
4309 }
4310 return;
9854d9ed 4311
9878760c 4312 case 'z':
b4ac57ab
RS
4313 /* X is a SYMBOL_REF. Write out the name preceded by a
4314 period and without any trailing data in brackets. Used for function
4d30c363
MM
4315 names. If we are configured for System V (or the embedded ABI) on
4316 the PowerPC, do not emit the period, since those systems do not use
4317 TOCs and the like. */
9878760c
RK
4318 if (GET_CODE (x) != SYMBOL_REF)
4319 abort ();
4320
b6c9286a
MM
4321 if (XSTR (x, 0)[0] != '.')
4322 {
4323 switch (DEFAULT_ABI)
4324 {
4325 default:
4326 abort ();
4327
4328 case ABI_AIX:
4329 putc ('.', file);
4330 break;
4331
4332 case ABI_V4:
4333 case ABI_AIX_NODESC:
c81bebd7 4334 case ABI_SOLARIS:
ee890fe2 4335 case ABI_DARWIN:
b6c9286a 4336 break;
b6c9286a
MM
4337 }
4338 }
9ebbca7d 4339#if TARGET_AIX
9878760c 4340 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9ebbca7d
GK
4341#else
4342 assemble_name (file, XSTR (x, 0));
4343#endif
9878760c
RK
4344 return;
4345
9854d9ed
RK
4346 case 'Z':
4347 /* Like 'L', for last word of TImode. */
4348 if (GET_CODE (x) == REG)
5ebfb2ba 4349 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
4350 else if (GET_CODE (x) == MEM)
4351 {
4352 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4353 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 4354 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 4355 else
a54d04b7 4356 output_address (plus_constant (XEXP (x, 0), 12));
ba5e43aa 4357 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
4358 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4359 reg_names[SMALL_DATA_REG]);
9854d9ed 4360 }
5c23c401 4361 return;
9854d9ed 4362
9878760c
RK
4363 case 0:
4364 if (GET_CODE (x) == REG)
4365 fprintf (file, "%s", reg_names[REGNO (x)]);
4366 else if (GET_CODE (x) == MEM)
4367 {
4368 /* We need to handle PRE_INC and PRE_DEC here, since we need to
4369 know the width from the mode. */
4370 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
4371 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
4372 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 4373 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
4374 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
4375 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 4376 else
a54d04b7 4377 output_address (XEXP (x, 0));
9878760c
RK
4378 }
4379 else
a54d04b7 4380 output_addr_const (file, x);
a85d226b 4381 return;
9878760c
RK
4382
4383 default:
4384 output_operand_lossage ("invalid %%xn code");
4385 }
4386}
4387\f
4388/* Print the address of an operand. */
4389
4390void
4391print_operand_address (file, x)
4392 FILE *file;
4393 register rtx x;
4394{
4395 if (GET_CODE (x) == REG)
4697a36c 4396 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
4397 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
4398 || GET_CODE (x) == LABEL_REF)
9878760c
RK
4399 {
4400 output_addr_const (file, x);
ba5e43aa 4401 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
4402 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4403 reg_names[SMALL_DATA_REG]);
9ebbca7d
GK
4404 else if (TARGET_TOC)
4405 abort();
9878760c
RK
4406 }
4407 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
4408 {
4409 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
4410 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
4411 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 4412 else
4697a36c
MM
4413 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
4414 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
4415 }
4416 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
5f59ecb7
DE
4417 {
4418 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
4419 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4420 }
3cb999d8
DE
4421#if TARGET_ELF
4422 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
4423 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
4424 {
4425 output_addr_const (file, XEXP (x, 1));
4426 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4427 }
3cb999d8 4428#endif
9ebbca7d
GK
4429 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
4430 {
4431 if (TARGET_AIX)
4432 {
4433 rtx contains_minus = XEXP (x, 1);
4434 rtx minus;
4435
4436 /* Find the (minus (sym) (toc)) buried in X, and temporarily
4437 turn it into (sym) for output_addr_const. */
4438 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
4439 contains_minus = XEXP (contains_minus, 0);
4440
4441 minus = XEXP (contains_minus, 0);
4442 XEXP (contains_minus, 0) = XEXP (minus, 0);
4443 output_addr_const (file, XEXP (x, 1));
4444 XEXP (contains_minus, 0) = minus;
4445 }
4446 else
4447 output_addr_const (file, XEXP (x, 1));
4448
4449 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
4450 }
9878760c
RK
4451 else
4452 abort ();
4453}
4454\f
39a10a29
GK
4455enum rtx_code
4456rs6000_reverse_condition (mode, code)
4457 enum machine_mode mode;
4458 enum rtx_code code;
4459{
4460 /* Reversal of FP compares takes care -- an ordered compare
4461 becomes an unordered compare and vice versa. */
4462 if (mode == CCFPmode)
bab6226b 4463 return reverse_condition_maybe_unordered (code);
39a10a29 4464 else
bab6226b 4465 return reverse_condition (code);
39a10a29
GK
4466}
4467
4468
4469/* Generate a compare for CODE. Return a brand-new rtx that
4470 represents the result of the compare. */
4471static rtx
4472rs6000_generate_compare (code)
4473 enum rtx_code code;
4474{
4475 enum machine_mode comp_mode;
4476 rtx compare_result;
4477
4478 if (rs6000_compare_fp_p)
4479 comp_mode = CCFPmode;
4480 else if (code == GTU || code == LTU
4481 || code == GEU || code == LEU)
4482 comp_mode = CCUNSmode;
4483 else
4484 comp_mode = CCmode;
4485
4486 /* First, the compare. */
4487 compare_result = gen_reg_rtx (comp_mode);
4488 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
4489 gen_rtx_COMPARE (comp_mode,
4490 rs6000_compare_op0,
4491 rs6000_compare_op1)));
4492
ca5adc63 4493 /* Some kinds of FP comparisons need an OR operation;
de6c5979 4494 except for flag_unsafe_math_optimizations we don't bother. */
39a10a29 4495 if (rs6000_compare_fp_p
de6c5979 4496 && ! flag_unsafe_math_optimizations
39a10a29
GK
4497 && (code == LE || code == GE
4498 || code == UNEQ || code == LTGT
4499 || code == UNGT || code == UNLT))
4500 {
4501 enum rtx_code or1, or2;
4502 rtx or1_rtx, or2_rtx, compare2_rtx;
4503 rtx or_result = gen_reg_rtx (CCEQmode);
4504
4505 switch (code)
4506 {
4507 case LE: or1 = LT; or2 = EQ; break;
4508 case GE: or1 = GT; or2 = EQ; break;
4509 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
4510 case LTGT: or1 = LT; or2 = GT; break;
4511 case UNGT: or1 = UNORDERED; or2 = GT; break;
4512 case UNLT: or1 = UNORDERED; or2 = LT; break;
4513 default: abort ();
4514 }
4515 validate_condition_mode (or1, comp_mode);
4516 validate_condition_mode (or2, comp_mode);
4517 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
4518 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
4519 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
4520 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
4521 const_true_rtx);
4522 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
4523
4524 compare_result = or_result;
4525 code = EQ;
4526 }
4527
4528 validate_condition_mode (code, GET_MODE (compare_result));
4529
4530 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
4531}
4532
4533
4534/* Emit the RTL for an sCOND pattern. */
4535
4536void
4537rs6000_emit_sCOND (code, result)
4538 enum rtx_code code;
4539 rtx result;
4540{
4541 rtx condition_rtx;
4542 enum machine_mode op_mode;
4543
4544 condition_rtx = rs6000_generate_compare (code);
4545
4546 op_mode = GET_MODE (rs6000_compare_op0);
4547 if (op_mode == VOIDmode)
4548 op_mode = GET_MODE (rs6000_compare_op1);
4549
4550 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
4551 {
4552 PUT_MODE (condition_rtx, DImode);
4553 convert_move (result, condition_rtx, 0);
4554 }
4555 else
4556 {
4557 PUT_MODE (condition_rtx, SImode);
4558 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
4559 }
4560}
4561
4562
4563/* Emit a branch of kind CODE to location LOC. */
4564
4565void
4566rs6000_emit_cbranch (code, loc)
4567 enum rtx_code code;
4568 rtx loc;
4569{
4570 rtx condition_rtx, loc_ref;
4571
4572 condition_rtx = rs6000_generate_compare (code);
4573 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
4574 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4575 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
4576 loc_ref, pc_rtx)));
4577}
4578
4579
12a4e8c5
GK
4580/* Return the string to output a conditional branch to LABEL, which is
4581 the operand number of the label, or -1 if the branch is really a
4582 conditional return.
4583
4584 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
4585 condition code register and its mode specifies what kind of
4586 comparison we made.
4587
4588 REVERSED is non-zero if we should reverse the sense of the comparison.
4589
4590 INSN is the insn. */
4591
4592char *
4593output_cbranch (op, label, reversed, insn)
4594 rtx op;
4595 const char * label;
4596 int reversed;
4597 rtx insn;
4598{
4599 static char string[64];
4600 enum rtx_code code = GET_CODE (op);
4601 rtx cc_reg = XEXP (op, 0);
4602 enum machine_mode mode = GET_MODE (cc_reg);
4603 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 4604 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
4605 int really_reversed = reversed ^ need_longbranch;
4606 char *s = string;
4607 const char *ccode;
4608 const char *pred;
4609 rtx note;
4610
39a10a29
GK
4611 validate_condition_mode (code, mode);
4612
4613 /* Work out which way this really branches. We could use
4614 reverse_condition_maybe_unordered here always but this
4615 makes the resulting assembler clearer. */
12a4e8c5 4616 if (really_reversed)
39a10a29 4617 code = rs6000_reverse_condition (mode, code);
12a4e8c5 4618
39a10a29 4619 switch (code)
12a4e8c5
GK
4620 {
4621 /* Not all of these are actually distinct opcodes, but
4622 we distinguish them for clarity of the resulting assembler. */
4623 case NE: ccode = "ne"; break;
4624 case EQ: ccode = "eq"; break;
4625 case GE: case GEU: ccode = "ge"; break;
4626 case GT: case GTU: ccode = "gt"; break;
4627 case LE: case LEU: ccode = "le"; break;
4628 case LT: case LTU: ccode = "lt"; break;
4629 case UNORDERED: ccode = "un"; break;
4630 case ORDERED: ccode = "nu"; break;
4631 case UNGE: ccode = "nl"; break;
4632 case UNLE: ccode = "ng"; break;
4633 default:
4634 abort();
4635 }
4636
94a54f47
GK
4637 /* Maybe we have a guess as to how likely the branch is.
4638 The old mnemonics don't have a way to specify this information. */
12a4e8c5
GK
4639 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
4640 if (note != NULL_RTX)
4641 {
4642 /* PROB is the difference from 50%. */
4643 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
4644
4645 /* For branches that are very close to 50%, assume not-taken. */
4646 if (abs (prob) > REG_BR_PROB_BASE / 20
4647 && ((prob > 0) ^ need_longbranch))
4648 pred = "+";
4649 else
4650 pred = "-";
4651 }
4652 else
4653 pred = "";
4654
4655 if (label == NULL)
94a54f47 4656 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 4657 else
94a54f47 4658 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 4659
37c67319
GK
4660 /* We need to escape any '%' characters in the reg_names string.
4661 Assume they'd only be the first character... */
4662 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
4663 *s++ = '%';
94a54f47 4664 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
4665
4666 if (label != NULL)
4667 {
4668 /* If the branch distance was too far, we may have to use an
4669 unconditional branch to go the distance. */
4670 if (need_longbranch)
33011c35 4671 s += sprintf (s, ",%c$+8\n\tb %s", '%', label);
12a4e8c5
GK
4672 else
4673 s += sprintf (s, ",%s", label);
4674 }
4675
4676 return string;
4677}
4678\f
9878760c
RK
4679/* This page contains routines that are used to determine what the function
4680 prologue and epilogue code will do and write them out. */
4681
4682/* Return the first fixed-point register that is required to be saved. 32 if
4683 none. */
4684
4685int
4686first_reg_to_save ()
4687{
4688 int first_reg;
4689
4690 /* Find lowest numbered live register. */
4691 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
4692 if (regs_ever_live[first_reg]
4693 && (! call_used_regs[first_reg]
4694 || (first_reg == PIC_OFFSET_TABLE_REGNUM
ee890fe2
SS
4695 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4696 && flag_pic == 1)
4697 || (DEFAULT_ABI == ABI_DARWIN
4698 && flag_pic)))))
9878760c
RK
4699 break;
4700
b5253831
DE
4701 if (profile_flag)
4702 {
4703 /* AIX must save/restore every register that contains a parameter
4704 before/after the .__mcount call plus an additional register
4705 for the static chain, if needed; use registers from 30 down to 22
4706 to do this. */
ee890fe2 4707 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
b5253831
DE
4708 {
4709 int last_parm_reg, profile_first_reg;
4710
4711 /* Figure out last used parameter register. The proper thing
4712 to do is to walk incoming args of the function. A function
4713 might have live parameter registers even if it has no
4714 incoming args. */
4715 for (last_parm_reg = 10;
4716 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4717 last_parm_reg--)
4718 ;
4719
4720 /* Calculate first reg for saving parameter registers
4721 and static chain.
4722 Skip reg 31 which may contain the frame pointer. */
4723 profile_first_reg = (33 - last_parm_reg
4724 - (current_function_needs_context ? 1 : 0));
ee890fe2
SS
4725#if TARGET_MACHO
4726 /* Need to skip another reg to account for R31 being PICBASE
4727 (when flag_pic is set) or R30 being used as the frame
4728 pointer (when flag_pic is not set). */
4729 --profile_first_reg;
4730#endif
b5253831
DE
4731 /* Do not save frame pointer if no parameters needs to be saved. */
4732 if (profile_first_reg == 31)
4733 profile_first_reg = 32;
4734
4735 if (first_reg > profile_first_reg)
4736 first_reg = profile_first_reg;
4737 }
e165f3f0 4738
b5253831
DE
4739 /* SVR4 may need one register to preserve the static chain. */
4740 else if (current_function_needs_context)
4741 {
4742 /* Skip reg 31 which may contain the frame pointer. */
4743 if (first_reg > 30)
4744 first_reg = 30;
4745 }
4746 }
e165f3f0 4747
ee890fe2
SS
4748#if TARGET_MACHO
4749 if (flag_pic && current_function_uses_pic_offset_table &&
4750 (first_reg > PIC_OFFSET_TABLE_REGNUM))
4751 return PIC_OFFSET_TABLE_REGNUM;
4752#endif
4753
9878760c
RK
4754 return first_reg;
4755}
4756
4757/* Similar, for FP regs. */
4758
4759int
4760first_fp_reg_to_save ()
4761{
4762 int first_reg;
4763
4764 /* Find lowest numbered live register. */
4765 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
4766 if (regs_ever_live[first_reg])
4767 break;
4768
4769 return first_reg;
4770}
4697a36c
MM
4771\f
4772/* Calculate the stack information for the current function. This is
4773 complicated by having two separate calling sequences, the AIX calling
4774 sequence and the V.4 calling sequence.
4775
ee890fe2 4776 AIX (and Darwin/Mac OS) stack frames look like:
a260abc9 4777 32-bit 64-bit
4697a36c 4778 SP----> +---------------------------------------+
a260abc9 4779 | back chain to caller | 0 0
4697a36c 4780 +---------------------------------------+
a260abc9 4781 | saved CR | 4 8 (8-11)
4697a36c 4782 +---------------------------------------+
a260abc9 4783 | saved LR | 8 16
4697a36c 4784 +---------------------------------------+
a260abc9 4785 | reserved for compilers | 12 24
4697a36c 4786 +---------------------------------------+
a260abc9 4787 | reserved for binders | 16 32
4697a36c 4788 +---------------------------------------+
a260abc9 4789 | saved TOC pointer | 20 40
4697a36c 4790 +---------------------------------------+
a260abc9 4791 | Parameter save area (P) | 24 48
4697a36c 4792 +---------------------------------------+
a260abc9 4793 | Alloca space (A) | 24+P etc.
802a0058 4794 +---------------------------------------+
a7df97e6 4795 | Local variable space (L) | 24+P+A
4697a36c 4796 +---------------------------------------+
a7df97e6 4797 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 4798 +---------------------------------------+
a7df97e6 4799 | Save area for GP registers (G) | 24+P+A+X+L
4697a36c 4800 +---------------------------------------+
a7df97e6 4801 | Save area for FP registers (F) | 24+P+A+X+L+G
4697a36c
MM
4802 +---------------------------------------+
4803 old SP->| back chain to caller's caller |
4804 +---------------------------------------+
4805
5376a30c
KR
4806 The required alignment for AIX configurations is two words (i.e., 8
4807 or 16 bytes).
4808
4809
4697a36c
MM
4810 V.4 stack frames look like:
4811
4812 SP----> +---------------------------------------+
4813 | back chain to caller | 0
4814 +---------------------------------------+
5eb387b8 4815 | caller's saved LR | 4
4697a36c
MM
4816 +---------------------------------------+
4817 | Parameter save area (P) | 8
4818 +---------------------------------------+
a7df97e6
MM
4819 | Alloca space (A) | 8+P
4820 +---------------------------------------+
4821 | Varargs save area (V) | 8+P+A
4822 +---------------------------------------+
4823 | Local variable space (L) | 8+P+A+V
4824 +---------------------------------------+
4825 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 4826 +---------------------------------------+
a7df97e6
MM
4827 | saved CR (C) | 8+P+A+V+L+X
4828 +---------------------------------------+
4829 | Save area for GP registers (G) | 8+P+A+V+L+X+C
4830 +---------------------------------------+
4831 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
4697a36c
MM
4832 +---------------------------------------+
4833 old SP->| back chain to caller's caller |
4834 +---------------------------------------+
b6c9286a 4835
5376a30c
KR
4836 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
4837 given. (But note below and in sysv4.h that we require only 8 and
4838 may round up the size of our stack frame anyways. The historical
4839 reason is early versions of powerpc-linux which didn't properly
4840 align the stack at program startup. A happy side-effect is that
4841 -mno-eabi libraries can be used with -meabi programs.)
4842
b6c9286a 4843
5376a30c
KR
4844 The EABI configuration defaults to the V.4 layout, unless
4845 -mcall-aix is used, in which case the AIX layout is used. However,
4846 the stack alignment requirements may differ. If -mno-eabi is not
4847 given, the required stack alignment is 8 bytes; if -mno-eabi is
4848 given, the required alignment is 16 bytes. (But see V.4 comment
4849 above.) */
4697a36c 4850
61b2fbe7
MM
4851#ifndef ABI_STACK_BOUNDARY
4852#define ABI_STACK_BOUNDARY STACK_BOUNDARY
4853#endif
4854
4697a36c
MM
4855rs6000_stack_t *
4856rs6000_stack_info ()
4857{
4858 static rs6000_stack_t info, zero_info;
4859 rs6000_stack_t *info_ptr = &info;
9ebbca7d 4860 int reg_size = TARGET_POWERPC64 ? 8 : 4;
24d304eb 4861 enum rs6000_abi abi;
83720594 4862 int ehrd_size;
b6c9286a 4863 int total_raw_size;
4697a36c
MM
4864
4865 /* Zero all fields portably */
4866 info = zero_info;
4867
4868 /* Select which calling sequence */
b6c9286a 4869 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 4870
4697a36c
MM
4871 /* Calculate which registers need to be saved & save area size */
4872 info_ptr->first_gp_reg_save = first_reg_to_save ();
906fb125
GK
4873 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
4874 even if it currently looks like we won't. */
ee890fe2
SS
4875 if (((flag_pic == 1
4876 && (abi == ABI_V4 || abi == ABI_SOLARIS))
4877 || (flag_pic &&
4878 abi == ABI_DARWIN))
906fb125
GK
4879 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
4880 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
4881 else
4882 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c
MM
4883
4884 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
4885 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
4886
4887 /* Does this function call anything? */
71f123ca
FS
4888 info_ptr->calls_p = (! current_function_is_leaf
4889 || cfun->machine->ra_needs_full_frame);
b6c9286a 4890
4697a36c 4891 /* Determine if we need to save the link register */
71f123ca 4892 if (rs6000_ra_ever_killed ()
38c1f2d7 4893 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4697a36c
MM
4894#ifdef TARGET_RELOCATABLE
4895 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
4896#endif
4897 || (info_ptr->first_fp_reg_save != 64
4898 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
24d304eb 4899 || (abi == ABI_V4 && current_function_calls_alloca)
c81bebd7 4900 || (abi == ABI_SOLARIS && current_function_calls_alloca)
ee890fe2 4901 || (DEFAULT_ABI == ABI_DARWIN && flag_pic && current_function_uses_pic_offset_table)
4697a36c
MM
4902 || info_ptr->calls_p)
4903 {
4904 info_ptr->lr_save_p = 1;
9ebbca7d 4905 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
4906 }
4907
9ebbca7d
GK
4908 /* Determine if we need to save the condition code registers. */
4909 if (regs_ever_live[CR2_REGNO]
4910 || regs_ever_live[CR3_REGNO]
4911 || regs_ever_live[CR4_REGNO])
4697a36c
MM
4912 {
4913 info_ptr->cr_save_p = 1;
9ebbca7d 4914 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4697a36c
MM
4915 info_ptr->cr_size = reg_size;
4916 }
4917
83720594
RH
4918 /* If the current function calls __builtin_eh_return, then we need
4919 to allocate stack space for registers that will hold data for
4920 the exception handler. */
4921 if (current_function_calls_eh_return)
4922 {
4923 unsigned int i;
4924 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
4925 continue;
4926 ehrd_size = i * UNITS_PER_WORD;
4927 }
4928 else
4929 ehrd_size = 0;
4930
4697a36c
MM
4931 /* Determine various sizes */
4932 info_ptr->reg_size = reg_size;
4933 info_ptr->fixed_size = RS6000_SAVE_AREA;
4934 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3
DE
4935 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
4936 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
189e03e3 4937 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
b6c9286a 4938 + info_ptr->gp_size
83720594 4939 + ehrd_size
b6c9286a
MM
4940 + info_ptr->cr_size
4941 + info_ptr->lr_size
9ebbca7d 4942 + info_ptr->toc_size, 8);
ee890fe2
SS
4943 if (DEFAULT_ABI == ABI_DARWIN)
4944 info_ptr->save_size = RS6000_ALIGN (info_ptr->save_size, 16);
b6c9286a 4945
4697a36c 4946 /* Calculate the offsets */
24d304eb 4947 switch (abi)
4697a36c 4948 {
b6c9286a 4949 case ABI_NONE:
24d304eb 4950 default:
b6c9286a
MM
4951 abort ();
4952
4953 case ABI_AIX:
4954 case ABI_AIX_NODESC:
ee890fe2 4955 case ABI_DARWIN:
b6c9286a
MM
4956 info_ptr->fp_save_offset = - info_ptr->fp_size;
4957 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
83720594 4958 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
4959 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
4960 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
4961 break;
4962
4963 case ABI_V4:
c81bebd7 4964 case ABI_SOLARIS:
b6c9286a
MM
4965 info_ptr->fp_save_offset = - info_ptr->fp_size;
4966 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6
MM
4967 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
4968 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 4969 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
4970 info_ptr->lr_save_offset = reg_size;
4971 break;
4697a36c
MM
4972 }
4973
ff381587
MM
4974 total_raw_size = (info_ptr->vars_size
4975 + info_ptr->parm_size
ff381587
MM
4976 + info_ptr->save_size
4977 + info_ptr->varargs_size
4978 + info_ptr->fixed_size);
4979
4980 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
4981
4982 /* Determine if we need to allocate any stack frame:
4983
4984 For AIX we need to push the stack if a frame pointer is needed (because
4985 the stack might be dynamically adjusted), if we are debugging, if we
9ebbca7d 4986 make calls, or if the sum of fp_save, gp_save, and local variables
ff381587 4987 are more than the space needed to save all non-volatile registers:
bfc79d3b 4988 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved).
ff381587
MM
4989
4990 For V.4 we don't have the stack cushion that AIX uses, but assume that
4991 the debugger can handle stackless frames. */
4992
4993 if (info_ptr->calls_p)
4994 info_ptr->push_p = 1;
4995
9ebbca7d 4996 else if (abi == ABI_V4 || abi == ABI_SOLARIS)
ff381587 4997 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
9ebbca7d 4998 || info_ptr->calls_p);
ff381587
MM
4999
5000 else
5001 info_ptr->push_p = (frame_pointer_needed
ee890fe2 5002 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
ff381587 5003 || ((total_raw_size - info_ptr->fixed_size)
bfc79d3b 5004 > (TARGET_32BIT ? 220 : 288)));
ff381587 5005
4697a36c 5006 /* Zero offsets if we're not saving those registers */
8dda1a21 5007 if (info_ptr->fp_size == 0)
4697a36c
MM
5008 info_ptr->fp_save_offset = 0;
5009
8dda1a21 5010 if (info_ptr->gp_size == 0)
4697a36c
MM
5011 info_ptr->gp_save_offset = 0;
5012
c81fc13e 5013 if (! info_ptr->lr_save_p)
4697a36c
MM
5014 info_ptr->lr_save_offset = 0;
5015
c81fc13e 5016 if (! info_ptr->cr_save_p)
4697a36c
MM
5017 info_ptr->cr_save_offset = 0;
5018
c81fc13e 5019 if (! info_ptr->toc_save_p)
b6c9286a
MM
5020 info_ptr->toc_save_offset = 0;
5021
4697a36c
MM
5022 return info_ptr;
5023}
5024
5025void
5026debug_stack_info (info)
5027 rs6000_stack_t *info;
9878760c 5028{
d330fd93 5029 const char *abi_string;
24d304eb 5030
c81fc13e 5031 if (! info)
4697a36c
MM
5032 info = rs6000_stack_info ();
5033
5034 fprintf (stderr, "\nStack information for function %s:\n",
5035 ((current_function_decl && DECL_NAME (current_function_decl))
5036 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
5037 : "<unknown>"));
5038
24d304eb
RK
5039 switch (info->abi)
5040 {
b6c9286a
MM
5041 default: abi_string = "Unknown"; break;
5042 case ABI_NONE: abi_string = "NONE"; break;
5043 case ABI_AIX: abi_string = "AIX"; break;
5044 case ABI_AIX_NODESC: abi_string = "AIX"; break;
ee890fe2 5045 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 5046 case ABI_V4: abi_string = "V.4"; break;
c81bebd7 5047 case ABI_SOLARIS: abi_string = "Solaris"; break;
24d304eb
RK
5048 }
5049
5050 fprintf (stderr, "\tABI = %5s\n", abi_string);
5051
4697a36c
MM
5052 if (info->first_gp_reg_save != 32)
5053 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
5054
5055 if (info->first_fp_reg_save != 64)
5056 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 5057
4697a36c
MM
5058 if (info->lr_save_p)
5059 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 5060
4697a36c
MM
5061 if (info->cr_save_p)
5062 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
5063
b6c9286a
MM
5064 if (info->toc_save_p)
5065 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
5066
4697a36c
MM
5067 if (info->push_p)
5068 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
5069
5070 if (info->calls_p)
5071 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
5072
4697a36c
MM
5073 if (info->gp_save_offset)
5074 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
5075
5076 if (info->fp_save_offset)
5077 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
5078
5079 if (info->lr_save_offset)
5080 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
5081
5082 if (info->cr_save_offset)
5083 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
5084
b6c9286a
MM
5085 if (info->toc_save_offset)
5086 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
5087
4697a36c
MM
5088 if (info->varargs_save_offset)
5089 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
5090
5091 if (info->total_size)
5092 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
5093
5094 if (info->varargs_size)
5095 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
5096
5097 if (info->vars_size)
5098 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
5099
5100 if (info->parm_size)
5101 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
5102
5103 if (info->fixed_size)
5104 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
5105
5106 if (info->gp_size)
5107 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
5108
5109 if (info->fp_size)
5110 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
5111
b6c9286a
MM
5112 if (info->lr_size)
5113 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
5114
4697a36c
MM
5115 if (info->cr_size)
5116 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
5117
b6c9286a
MM
5118 if (info->toc_size)
5119 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
5120
4697a36c
MM
5121 if (info->save_size)
5122 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
5123
5124 if (info->reg_size != 4)
5125 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
5126
5127 fprintf (stderr, "\n");
9878760c 5128}
71f123ca
FS
5129
5130rtx
5131rs6000_return_addr (count, frame)
5132 int count;
5133 rtx frame;
5134{
5135 rtx init, reg;
5136
5137 /* Currently we don't optimize very well between prolog and body code and
5138 for PIC code the code can be actually quite bad, so don't try to be
5139 too clever here. */
3418dd3a
FS
5140 if (count != 0
5141 || flag_pic != 0
5142 || DEFAULT_ABI == ABI_AIX
5143 || DEFAULT_ABI == ABI_AIX_NODESC)
71f123ca
FS
5144 {
5145 cfun->machine->ra_needs_full_frame = 1;
5146 return
5147 gen_rtx_MEM (Pmode,
3418dd3a 5148 memory_address (Pmode,
71f123ca
FS
5149 plus_constant (copy_to_reg (gen_rtx_MEM (Pmode,
5150 memory_address (Pmode, frame))),
5151 RETURN_ADDRESS_OFFSET)));
5152 }
5153
5154 reg = cfun->machine->ra_rtx;
5155 if (reg == NULL)
5156 {
5157 /* No rtx yet. Invent one, and initialize it from LR in
5158 the prologue. */
5159 reg = gen_reg_rtx (Pmode);
5160 cfun->machine->ra_rtx = reg;
5161 init = gen_rtx_SET (VOIDmode, reg,
5162 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5163
5164 /* Emit the insn to the prologue with the other argument copies. */
5165 push_topmost_sequence ();
5166 emit_insn_after (init, get_insns ());
5167 pop_topmost_sequence ();
5168 }
5169
5170 return reg;
5171}
5172
5173static int
5174rs6000_ra_ever_killed ()
5175{
5176 rtx top;
5177
5178#ifdef ASM_OUTPUT_MI_THUNK
5179 if (current_function_is_thunk)
5180 return 0;
5181#endif
5182 if (!cfun->machine->ra_rtx || cfun->machine->ra_needs_full_frame)
5183 return regs_ever_live[LINK_REGISTER_REGNUM];
5184
5185 push_topmost_sequence ();
5186 top = get_insns ();
5187 pop_topmost_sequence ();
5188
5189 return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5190 top, NULL_RTX);
5191}
4697a36c 5192\f
8cd8f856
GK
5193/* Add a REG_MAYBE_DEAD note to the insn. */
5194static void
5195rs6000_maybe_dead (insn)
5196 rtx insn;
5197{
5198 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
5199 const0_rtx,
5200 REG_NOTES (insn));
5201}
5202
9ebbca7d 5203/* Emit instructions needed to load the TOC register.
c7ca610e 5204 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 5205 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
5206
5207void
9ebbca7d
GK
5208rs6000_emit_load_toc_table (fromprolog)
5209 int fromprolog;
c7ca610e 5210{
9ebbca7d
GK
5211 rtx dest;
5212 dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
c7ca610e 5213
9ebbca7d 5214 if (TARGET_ELF)
c7ca610e 5215 {
9ebbca7d
GK
5216 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5217 && flag_pic == 1)
38c1f2d7 5218 {
9ebbca7d
GK
5219 rtx temp = (fromprolog
5220 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5221 : gen_reg_rtx (Pmode));
5222 if (TARGET_32BIT)
8cd8f856 5223 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
9ebbca7d 5224 else
8cd8f856
GK
5225 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_di (temp)));
5226 rs6000_maybe_dead (emit_move_insn (dest, temp));
38c1f2d7 5227 }
9ebbca7d
GK
5228 else if (flag_pic == 2)
5229 {
5230 char buf[30];
5231 rtx tempLR = (fromprolog
5232 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5233 : gen_reg_rtx (Pmode));
5234 rtx temp0 = (fromprolog
5235 ? gen_rtx_REG (Pmode, 0)
5236 : gen_reg_rtx (Pmode));
5237 rtx symF;
5238
5239 /* possibly create the toc section */
5240 if (! toc_initialized)
5241 {
5242 toc_section ();
5243 function_section (current_function_decl);
5244 }
5245
5246 if (fromprolog)
5247 {
5248 rtx symL;
5249
5250 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
a8a05998 5251 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
38c1f2d7 5252
9ebbca7d 5253 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
a8a05998 5254 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
38c1f2d7 5255
8cd8f856
GK
5256 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
5257 symF)));
5258 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5259 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
5260 symL,
5261 symF)));
9ebbca7d
GK
5262 }
5263 else
5264 {
5265 rtx tocsym;
5266 static int reload_toc_labelno = 0;
5267
a8a05998 5268 tocsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name));
38c1f2d7 5269
9ebbca7d 5270 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
a8a05998 5271 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 5272
8cd8f856
GK
5273 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
5274 symF,
5275 tocsym)));
5276 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5277 rs6000_maybe_dead (emit_move_insn (temp0,
5278 gen_rtx_MEM (Pmode, dest)));
9ebbca7d 5279 }
8cd8f856 5280 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
9ebbca7d
GK
5281 }
5282 else if (flag_pic == 0 && TARGET_MINIMAL_TOC)
5283 {
5284 /* This is for AIX code running in non-PIC ELF. */
5285 char buf[30];
5286 rtx realsym;
38c1f2d7 5287 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
a8a05998 5288 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 5289
8cd8f856
GK
5290 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
5291 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
9ebbca7d
GK
5292 }
5293 else
5294 abort();
5295 }
5296 else
5297 {
5298 if (TARGET_32BIT)
8cd8f856 5299 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
9ebbca7d 5300 else
8cd8f856 5301 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
9ebbca7d
GK
5302 }
5303}
5304
5305int
5306get_TOC_alias_set ()
5307{
5308 static int set = -1;
5309 if (set == -1)
5310 set = new_alias_set ();
5311 return set;
5312}
5313
5314/* This retuns nonzero if the current function uses the TOC. This is
5315 determined by the presence of (unspec ... 7), which is generated by
5316 the various load_toc_* patterns. */
5317int
5318uses_TOC ()
5319{
5320 rtx insn;
38c1f2d7 5321
9ebbca7d 5322 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2c3c49de 5323 if (INSN_P (insn))
9ebbca7d
GK
5324 {
5325 rtx pat = PATTERN (insn);
5326 int i;
5327
8cd8f856 5328 if (GET_CODE (pat) == PARALLEL)
9ebbca7d
GK
5329 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
5330 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
5331 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
5332 return 1;
38c1f2d7 5333 }
9ebbca7d
GK
5334 return 0;
5335}
38c1f2d7 5336
9ebbca7d
GK
5337rtx
5338create_TOC_reference(symbol)
5339 rtx symbol;
5340{
a8a05998
ZW
5341 return gen_rtx_PLUS (Pmode,
5342 gen_rtx_REG (Pmode, TOC_REGISTER),
5343 gen_rtx_CONST (Pmode,
5344 gen_rtx_MINUS (Pmode, symbol,
5345 gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name)))));
9ebbca7d 5346}
38c1f2d7 5347
9ebbca7d
GK
5348#if TARGET_AIX
5349/* __throw will restore its own return address to be the same as the
5350 return address of the function that the throw is being made to.
5351 This is unfortunate, because we want to check the original
5352 return address to see if we need to restore the TOC.
5353 So we have to squirrel it away here.
5354 This is used only in compiling __throw and __rethrow.
c7ca610e 5355
9ebbca7d
GK
5356 Most of this code should be removed by CSE. */
5357static rtx insn_after_throw;
c7ca610e 5358
9ebbca7d
GK
5359/* This does the saving... */
5360void
5361rs6000_aix_emit_builtin_unwind_init ()
5362{
5363 rtx mem;
5364 rtx stack_top = gen_reg_rtx (Pmode);
5365 rtx opcode_addr = gen_reg_rtx (Pmode);
5366
5367 insn_after_throw = gen_reg_rtx (SImode);
5368
5369 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5370 emit_move_insn (stack_top, mem);
5371
5372 mem = gen_rtx_MEM (Pmode,
5373 gen_rtx_PLUS (Pmode, stack_top,
5374 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5375 emit_move_insn (opcode_addr, mem);
5376 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
c7ca610e
RK
5377}
5378
9ebbca7d
GK
5379/* Emit insns to _restore_ the TOC register, at runtime (specifically in _eh.o).
5380 Only used on AIX.
5381
5382 The idea is that on AIX, function calls look like this:
5383 bl somefunction-trampoline
5384 lwz r2,20(sp)
5385
5386 and later,
5387 somefunction-trampoline:
5388 stw r2,20(sp)
5389 ... load function address in the count register ...
5390 bctr
5391 or like this, if the linker determines that this is not a cross-module call
5392 and so the TOC need not be restored:
5393 bl somefunction
5394 nop
5395 or like this, if the compiler could determine that this is not a
5396 cross-module call:
5397 bl somefunction
5398 now, the tricky bit here is that register 2 is saved and restored
5399 by the _linker_, so we can't readily generate debugging information
5400 for it. So we need to go back up the call chain looking at the
5401 insns at return addresses to see which calls saved the TOC register
5402 and so see where it gets restored from.
5403
5404 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
5405 just before the actual epilogue.
5406
5407 On the bright side, this incurs no space or time overhead unless an
5408 exception is thrown, except for the extra code in libgcc.a.
5409
5410 The parameter STACKSIZE is a register containing (at runtime)
5411 the amount to be popped off the stack in addition to the stack frame
5412 of this routine (which will be __throw or __rethrow, and so is
5413 guaranteed to have a stack frame). */
5414void
5415rs6000_emit_eh_toc_restore (stacksize)
5416 rtx stacksize;
5417{
5418 rtx top_of_stack;
5419 rtx bottom_of_stack = gen_reg_rtx (Pmode);
5420 rtx tocompare = gen_reg_rtx (SImode);
5421 rtx opcode = gen_reg_rtx (SImode);
5422 rtx opcode_addr = gen_reg_rtx (Pmode);
5423 rtx mem;
5424 rtx loop_start = gen_label_rtx ();
5425 rtx no_toc_restore_needed = gen_label_rtx ();
5426 rtx loop_exit = gen_label_rtx ();
5427
5428 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5429 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5430 emit_move_insn (bottom_of_stack, mem);
5431
5432 top_of_stack = expand_binop (Pmode, add_optab,
5433 bottom_of_stack, stacksize,
5434 NULL_RTX, 1, OPTAB_WIDEN);
5435
5436 emit_move_insn (tocompare,
5437 GEN_INT (trunc_int_for_mode (TARGET_32BIT
5438 ? 0x80410014
5439 : 0xE8410028, SImode)));
5440
5441 if (insn_after_throw == NULL_RTX)
5442 abort();
5443 emit_move_insn (opcode, insn_after_throw);
5444
5445 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
5446 emit_label (loop_start);
5447
5448 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
5449 SImode, NULL_RTX, 0, NULL_RTX,
5450 no_toc_restore_needed);
5451
5452 mem = gen_rtx_MEM (Pmode,
5453 gen_rtx_PLUS (Pmode, bottom_of_stack,
5454 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
5455 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
5456
5457 emit_label (no_toc_restore_needed);
5458 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
5459 Pmode, NULL_RTX, 0, NULL_RTX,
5460 loop_exit);
5461
5462 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
5463 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5464 emit_move_insn (bottom_of_stack, mem);
5465
5466 mem = gen_rtx_MEM (Pmode,
5467 gen_rtx_PLUS (Pmode, bottom_of_stack,
5468 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5469 emit_move_insn (opcode_addr, mem);
5470 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
5471
5472 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
5473 emit_jump (loop_start);
5474 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
5475 emit_label (loop_exit);
5476}
5477#endif /* TARGET_AIX */
38c1f2d7 5478\f
9ebbca7d
GK
5479/* This ties together stack memory
5480 (MEM with an alias set of rs6000_sr_alias_set)
5481 and the change to the stack pointer. */
5482static void
5483rs6000_emit_stack_tie ()
5484{
5485 rtx mem;
5486 mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
5487 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5488 emit_insn (gen_stack_tie (mem));
5489}
38c1f2d7 5490
9ebbca7d
GK
5491/* Emit the correct code for allocating stack space, as insns.
5492 If COPY_R12, make sure a copy of the old frame is left in r12.
5493 The generated code may use hard register 0 as a temporary. */
5494
5495static void
5496rs6000_emit_allocate_stack (size, copy_r12)
5497 HOST_WIDE_INT size;
38c1f2d7
MM
5498 int copy_r12;
5499{
9ebbca7d
GK
5500 rtx insn;
5501 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5502 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
5503 rtx todec = GEN_INT (-size);
a157febd
GK
5504
5505 if (current_function_limit_stack)
5506 {
5507 if (REG_P (stack_limit_rtx)
5508 && REGNO (stack_limit_rtx) > 1
5509 && REGNO (stack_limit_rtx) <= 31)
5510 {
9ebbca7d
GK
5511 emit_insn (Pmode == SImode
5512 ? gen_addsi3 (tmp_reg,
5513 stack_limit_rtx,
5514 GEN_INT (size))
5515 : gen_adddi3 (tmp_reg,
5516 stack_limit_rtx,
5517 GEN_INT (size)));
5518
5519 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5520 const0_rtx));
a157febd
GK
5521 }
5522 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 5523 && TARGET_32BIT
a157febd
GK
5524 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5525 {
9ebbca7d
GK
5526 rtx toload = gen_rtx_CONST (VOIDmode,
5527 gen_rtx_PLUS (Pmode,
5528 stack_limit_rtx,
5529 GEN_INT (size)));
5530
5531 emit_insn (gen_elf_high (tmp_reg, toload));
5532 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
5533 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5534 const0_rtx));
a157febd
GK
5535 }
5536 else
5537 warning ("stack limit expression is not supported");
5538 }
5539
9ebbca7d
GK
5540 if (copy_r12 || ! TARGET_UPDATE)
5541 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
5542
38c1f2d7
MM
5543 if (TARGET_UPDATE)
5544 {
9ebbca7d 5545 if (size > 32767)
38c1f2d7 5546 {
9ebbca7d
GK
5547 /* Need a note here so that try_split doesn't get confused. */
5548 if (get_last_insn() == NULL_RTX)
5549 emit_note (0, NOTE_INSN_DELETED);
5550 insn = emit_move_insn (tmp_reg, todec);
5551 try_split (PATTERN (insn), insn, 0);
5552 todec = tmp_reg;
38c1f2d7 5553 }
9ebbca7d
GK
5554
5555 if (Pmode == SImode)
5556 insn = emit_insn (gen_movsi_update (stack_reg, stack_reg,
5557 todec, stack_reg));
5558 else
5559 insn = emit_insn (gen_movdi_update (stack_reg, stack_reg,
5560 todec, stack_reg));
38c1f2d7
MM
5561 }
5562 else
5563 {
9ebbca7d
GK
5564 if (Pmode == SImode)
5565 insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec));
38c1f2d7 5566 else
9ebbca7d
GK
5567 insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec));
5568 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
5569 gen_rtx_REG (Pmode, 12));
5570 }
5571
5572 RTX_FRAME_RELATED_P (insn) = 1;
5573 REG_NOTES (insn) =
5574 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5575 gen_rtx_SET (VOIDmode, stack_reg,
5576 gen_rtx_PLUS (Pmode, stack_reg,
5577 GEN_INT (-size))),
5578 REG_NOTES (insn));
5579}
5580
5581/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced with
5582 (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 is not
5583 NULL.
5584 It would be nice if dwarf2out_frame_debug_expr could deduce these
5585 equivalences by itself so it wasn't necessary to hold its hand so much. */
5586
5587static void
5588rs6000_frame_related (insn, reg, val, reg2, rreg)
5589 rtx insn;
5590 rtx reg;
5591 HOST_WIDE_INT val;
5592 rtx reg2;
5593 rtx rreg;
5594{
5595 rtx real, temp;
5596
5597 real = copy_rtx (PATTERN (insn));
5598
5599 real = replace_rtx (real, reg,
5600 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
5601 STACK_POINTER_REGNUM),
5602 GEN_INT (val)));
5603
5604 /* We expect that 'real' is either a SET or a PARALLEL containing
5605 SETs (and possibly other stuff). In a PARALLEL, all the SETs
5606 are important so they all have to be marked RTX_FRAME_RELATED_P. */
5607
5608 if (GET_CODE (real) == SET)
5609 {
5610 rtx set = real;
5611
5612 temp = simplify_rtx (SET_SRC (set));
5613 if (temp)
5614 SET_SRC (set) = temp;
5615 temp = simplify_rtx (SET_DEST (set));
5616 if (temp)
5617 SET_DEST (set) = temp;
5618 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 5619 {
9ebbca7d
GK
5620 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5621 if (temp)
5622 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 5623 }
38c1f2d7 5624 }
9ebbca7d
GK
5625 else if (GET_CODE (real) == PARALLEL)
5626 {
5627 int i;
5628 for (i = 0; i < XVECLEN (real, 0); i++)
5629 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
5630 {
5631 rtx set = XVECEXP (real, 0, i);
5632
5633 temp = simplify_rtx (SET_SRC (set));
5634 if (temp)
5635 SET_SRC (set) = temp;
5636 temp = simplify_rtx (SET_DEST (set));
5637 if (temp)
5638 SET_DEST (set) = temp;
5639 if (GET_CODE (SET_DEST (set)) == MEM)
5640 {
5641 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5642 if (temp)
5643 XEXP (SET_DEST (set), 0) = temp;
5644 }
5645 RTX_FRAME_RELATED_P (set) = 1;
5646 }
5647 }
5648 else
5649 abort();
5650
5651 if (reg2 != NULL_RTX)
5652 real = replace_rtx (real, reg2, rreg);
5653
5654 RTX_FRAME_RELATED_P (insn) = 1;
5655 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5656 real,
5657 REG_NOTES (insn));
38c1f2d7
MM
5658}
5659
9ebbca7d
GK
5660/* Emit function prologue as insns. */
5661
9878760c 5662void
83720594 5663rs6000_emit_prologue ()
9878760c 5664{
4697a36c 5665 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
5666 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5667 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5668 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5669 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
5670 rtx frame_reg_rtx = sp_reg_rtx;
5671 rtx cr_save_rtx = NULL;
5672 rtx insn;
5673 int saving_FPRs_inline;
5674 int using_store_multiple;
5675 HOST_WIDE_INT sp_offset = 0;
5676
5677 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5678 && info->first_gp_reg_save < 31);
5679 saving_FPRs_inline = (info->first_fp_reg_save == 64
5680 || FP_SAVE_INLINE (info->first_fp_reg_save));
5681
5682 /* For V.4, update stack before we do any saving and set back pointer. */
5683 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5684 {
5685 if (info->total_size < 32767)
5686 sp_offset = info->total_size;
5687 else
5688 frame_reg_rtx = frame_ptr_rtx;
5689 rs6000_emit_allocate_stack (info->total_size,
5690 (frame_reg_rtx != sp_reg_rtx
5691 && (info->cr_save_p
5692 || info->lr_save_p
5693 || info->first_fp_reg_save < 64
5694 || info->first_gp_reg_save < 32
5695 )));
5696 if (frame_reg_rtx != sp_reg_rtx)
5697 rs6000_emit_stack_tie ();
5698 }
5699
5700 /* If we use the link register, get it into r0. */
5701 if (info->lr_save_p)
71f123ca 5702 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
5703 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5704
5705 /* If we need to save CR, put it into r12. */
5706 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
5707 {
5708 cr_save_rtx = gen_rtx_REG (SImode, 12);
5709 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5710 }
5711
5712 /* Do any required saving of fpr's. If only one or two to save, do it
5713 ourself. Otherwise, call function. */
5714 if (saving_FPRs_inline)
5715 {
5716 int i;
5717 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5718 if ((regs_ever_live[info->first_fp_reg_save+i]
5719 && ! call_used_regs[info->first_fp_reg_save+i]))
5720 {
5721 rtx addr, reg, mem;
5722 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5723 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5724 GEN_INT (info->fp_save_offset
5725 + sp_offset
5726 + 8*i));
5727 mem = gen_rtx_MEM (DFmode, addr);
5728 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5729
5730 insn = emit_move_insn (mem, reg);
5731 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5732 NULL_RTX, NULL_RTX);
5733 }
5734 }
5735 else if (info->first_fp_reg_save != 64)
5736 {
5737 int i;
5738 char rname[30];
520a57c8 5739 const char *alloc_rname;
9ebbca7d
GK
5740 rtvec p;
5741 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
5742
5743 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
5744 gen_rtx_REG (Pmode,
5745 LINK_REGISTER_REGNUM));
5746 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
5747 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 5748 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
5749 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
5750 gen_rtx_SYMBOL_REF (Pmode,
5751 alloc_rname));
5752 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5753 {
5754 rtx addr, reg, mem;
5755 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5756 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5757 GEN_INT (info->fp_save_offset
5758 + sp_offset + 8*i));
5759 mem = gen_rtx_MEM (DFmode, addr);
5760 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5761
5762 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
5763 }
5764 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5765 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5766 NULL_RTX, NULL_RTX);
5767 }
b6c9286a 5768
9ebbca7d
GK
5769 /* Save GPRs. This is done as a PARALLEL if we are using
5770 the store-multiple instructions. */
5771 if (using_store_multiple)
b6c9286a 5772 {
9ebbca7d
GK
5773 rtvec p, dwarfp;
5774 int i;
5775 p = rtvec_alloc (32 - info->first_gp_reg_save);
5776 dwarfp = rtvec_alloc (32 - info->first_gp_reg_save);
5777 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5778 {
5779 rtx addr, reg, mem;
5780 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5781 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5782 GEN_INT (info->gp_save_offset
5783 + sp_offset
5784 + reg_size * i));
5785 mem = gen_rtx_MEM (reg_mode, addr);
5786 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5787
5788 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
5789 }
5790 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5791 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5792 NULL_RTX, NULL_RTX);
b6c9286a
MM
5793 }
5794 else
5795 {
9ebbca7d
GK
5796 int i;
5797 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5798 if ((regs_ever_live[info->first_gp_reg_save+i]
5799 && ! call_used_regs[info->first_gp_reg_save+i])
5800 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
ee890fe2
SS
5801 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5802 && flag_pic == 1)
5803 || (DEFAULT_ABI == ABI_DARWIN
5804 && flag_pic))))
9ebbca7d
GK
5805 {
5806 rtx addr, reg, mem;
5807 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5808 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5809 GEN_INT (info->gp_save_offset
5810 + sp_offset
5811 + reg_size * i));
5812 mem = gen_rtx_MEM (reg_mode, addr);
5813 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5814
5815 insn = emit_move_insn (mem, reg);
5816 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5817 NULL_RTX, NULL_RTX);
5818 }
5819 }
5820
83720594
RH
5821 /* ??? There's no need to emit actual instructions here, but it's the
5822 easiest way to get the frame unwind information emitted. */
5823 if (current_function_calls_eh_return)
5824 {
5825 unsigned int i, regno;
5826 for (i = 0; ; ++i)
5827 {
5828 rtx addr, reg, mem;
5829
5830 regno = EH_RETURN_DATA_REGNO (i);
5831 if (regno == INVALID_REGNUM)
5832 break;
5833
5834 reg = gen_rtx_REG (reg_mode, regno);
5835 addr = plus_constant (frame_reg_rtx,
5836 info->ehrd_offset + sp_offset + reg_size * i);
5837 mem = gen_rtx_MEM (reg_mode, addr);
5838 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5839
5840 insn = emit_move_insn (mem, reg);
5841 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5842 NULL_RTX, NULL_RTX);
5843 }
5844 }
5845
9ebbca7d
GK
5846 /* Save lr if we used it. */
5847 if (info->lr_save_p)
5848 {
5849 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5850 GEN_INT (info->lr_save_offset + sp_offset));
5851 rtx reg = gen_rtx_REG (Pmode, 0);
5852 rtx mem = gen_rtx_MEM (Pmode, addr);
5853 /* This should not be of rs6000_sr_alias_set, because of
5854 __builtin_return_address. */
5855
5856 insn = emit_move_insn (mem, reg);
5857 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5858 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5859 }
5860
5861 /* Save CR if we use any that must be preserved. */
5862 if (info->cr_save_p)
5863 {
5864 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5865 GEN_INT (info->cr_save_offset + sp_offset));
5866 rtx mem = gen_rtx_MEM (SImode, addr);
5867 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5868
5869 /* If r12 was used to hold the original sp, copy cr into r0 now
5870 that it's free. */
5871 if (REGNO (frame_reg_rtx) == 12)
5872 {
5873 cr_save_rtx = gen_rtx_REG (SImode, 0);
5874 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5875 }
5876 insn = emit_move_insn (mem, cr_save_rtx);
5877
5878 /* Now, there's no way that dwarf2out_frame_debug_expr is going
5879 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
5880 OK. All we have to do is specify that _one_ condition code
5881 register is saved in this stack slot. The thrower's epilogue
5882 will then restore all the call-saved registers. */
5883 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5884 cr_save_rtx, gen_rtx_REG (SImode, CR0_REGNO));
5885 }
5886
5887 /* Update stack and set back pointer unless this is V.4,
5888 for which it was done previously. */
5889 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
5890 rs6000_emit_allocate_stack (info->total_size, FALSE);
5891
5892 /* Set frame pointer, if needed. */
5893 if (frame_pointer_needed)
5894 {
5895 insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM),
5896 sp_reg_rtx);
5897 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 5898 }
9878760c 5899
9ebbca7d
GK
5900 /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
5901 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
5902 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5903 && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
5904 {
5905 /* If emit_load_toc_table will use the link register, we need to save
5906 it. We use R11 for this purpose because emit_load_toc_table
5907 can use register 0. This allows us to use a plain 'blr' to return
5908 from the procedure more often. */
5909 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 &&
5910 ! info->lr_save_p);
5911 if (save_LR_around_toc_setup)
5912 emit_move_insn (gen_rtx_REG (Pmode, 11),
5913 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5914
5915 rs6000_emit_load_toc_table (TRUE);
5916
5917 if (save_LR_around_toc_setup)
5918 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5919 gen_rtx_REG (Pmode, 11));
5920 }
ee890fe2
SS
5921
5922 if (DEFAULT_ABI == ABI_DARWIN
5923 && flag_pic && current_function_uses_pic_offset_table)
5924 {
5925 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
5926
5927 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest)));
5928
5929 rs6000_maybe_dead (
5930 emit_move_insn (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM),
5931 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
5932 }
9ebbca7d
GK
5933}
5934
5935
5936/* Write function prologue. */
5937void
5938output_prolog (file, size)
5939 FILE *file;
5940 int size ATTRIBUTE_UNUSED;
5941{
5942 rs6000_stack_t *info = rs6000_stack_info ();
5943
4697a36c
MM
5944 if (TARGET_DEBUG_STACK)
5945 debug_stack_info (info);
9878760c
RK
5946
5947 /* Write .extern for any function we will call to save and restore fp
5948 values. */
b6c9286a 5949 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 5950 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c
MM
5951 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
5952 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
9878760c 5953
c764f757
RK
5954 /* Write .extern for AIX common mode routines, if needed. */
5955 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
5956 {
f6709c70
JW
5957 fputs ("\t.extern __mulh\n", file);
5958 fputs ("\t.extern __mull\n", file);
5959 fputs ("\t.extern __divss\n", file);
5960 fputs ("\t.extern __divus\n", file);
5961 fputs ("\t.extern __quoss\n", file);
5962 fputs ("\t.extern __quous\n", file);
c764f757
RK
5963 common_mode_defined = 1;
5964 }
9878760c 5965
9ebbca7d 5966 if (! HAVE_prologue)
979721f8 5967 {
9ebbca7d
GK
5968 start_sequence ();
5969
5970 /* A NOTE_INSN_DELETED is supposed to be at the start
5971 and end of the "toplevel" insn chain. */
5972 emit_note (0, NOTE_INSN_DELETED);
5973 rs6000_emit_prologue ();
5974 emit_note (0, NOTE_INSN_DELETED);
5975
5976 if (TARGET_DEBUG_STACK)
5977 debug_rtx_list (get_insns(), 100);
5978 final (get_insns(), file, FALSE, FALSE);
5979 end_sequence ();
979721f8
MM
5980 }
5981
9ebbca7d
GK
5982 rs6000_pic_labelno++;
5983}
5984
5985/* Emit function epilogue as insns.
9878760c 5986
9ebbca7d
GK
5987 At present, dwarf2out_frame_debug_expr doesn't understand
5988 register restores, so we don't bother setting RTX_FRAME_RELATED_P
5989 anywhere in the epilogue. Most of the insns below would in any case
5990 need special notes to explain where r11 is in relation to the stack. */
9878760c 5991
9ebbca7d 5992void
83720594 5993rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
5994 int sibcall;
5995{
5996 rs6000_stack_t *info;
5997 int restoring_FPRs_inline;
5998 int using_load_multiple;
5999 int using_mfcr_multiple;
6000 int use_backchain_to_restore_sp;
6001 int sp_offset = 0;
6002 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
6003 rtx frame_reg_rtx = sp_reg_rtx;
6004 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
6005 int reg_size = TARGET_POWERPC64 ? 8 : 4;
6006 int i;
6007
6008 info = rs6000_stack_info ();
6009 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
6010 && info->first_gp_reg_save < 31);
6011 restoring_FPRs_inline = (sibcall
83720594 6012 || current_function_calls_eh_return
9ebbca7d
GK
6013 || info->first_fp_reg_save == 64
6014 || FP_SAVE_INLINE (info->first_fp_reg_save));
6015 use_backchain_to_restore_sp = (frame_pointer_needed
6016 || current_function_calls_alloca
6017 || info->total_size > 32767);
6018 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
6019 || rs6000_cpu == PROCESSOR_PPC603
6020 || rs6000_cpu == PROCESSOR_PPC750
6021 || optimize_size);
6022
6023 /* If we have a frame pointer, a call to alloca, or a large stack
6024 frame, restore the old stack pointer using the backchain. Otherwise,
6025 we know what size to update it with. */
6026 if (use_backchain_to_restore_sp)
bacbde18 6027 {
9ebbca7d
GK
6028 /* Under V.4, don't reset the stack pointer until after we're done
6029 loading the saved registers. */
6030 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6031 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 6032
9ebbca7d
GK
6033 emit_move_insn (frame_reg_rtx,
6034 gen_rtx_MEM (Pmode, sp_reg_rtx));
6035
bacbde18 6036 }
9ebbca7d 6037 else if (info->push_p)
85638c0d 6038 {
9ebbca7d
GK
6039 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6040 sp_offset = info->total_size;
6041 else
6042 {
6043 emit_insn (TARGET_32BIT
6044 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
6045 GEN_INT (info->total_size))
6046 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
6047 GEN_INT (info->total_size)));
6048 }
85638c0d 6049 }
9ebbca7d
GK
6050
6051 /* Get the old lr if we saved it. */
6052 if (info->lr_save_p)
b6c9286a 6053 {
9ebbca7d
GK
6054 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6055 GEN_INT (info->lr_save_offset + sp_offset));
6056 rtx mem = gen_rtx_MEM (Pmode, addr);
6057 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
b6c9286a 6058
9ebbca7d 6059 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 6060 }
9ebbca7d
GK
6061
6062 /* Get the old cr if we saved it. */
6063 if (info->cr_save_p)
6064 {
6065 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6066 GEN_INT (info->cr_save_offset + sp_offset));
6067 rtx mem = gen_rtx_MEM (SImode, addr);
6068 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
b6c9286a 6069
9ebbca7d
GK
6070 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
6071 }
6072
6073 /* Set LR here to try to overlap restores below. */
4697a36c 6074 if (info->lr_save_p)
9ebbca7d
GK
6075 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
6076 gen_rtx_REG (Pmode, 0));
6077
83720594
RH
6078 /* Load exception handler data registers, if needed. */
6079 if (current_function_calls_eh_return)
6080 {
6081 unsigned int i, regno;
6082 for (i = 0; ; ++i)
6083 {
6084 rtx addr, mem;
6085
6086 regno = EH_RETURN_DATA_REGNO (i);
6087 if (regno == INVALID_REGNUM)
6088 break;
6089
6090 addr = plus_constant (frame_reg_rtx,
6091 info->ehrd_offset + sp_offset + reg_size * i);
6092 mem = gen_rtx_MEM (reg_mode, addr);
6093 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6094
6095 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
6096 }
6097 }
9ebbca7d
GK
6098
6099 /* Restore GPRs. This is done as a PARALLEL if we are using
6100 the load-multiple instructions. */
6101 if (using_load_multiple)
979721f8 6102 {
9ebbca7d
GK
6103 rtvec p;
6104 p = rtvec_alloc (32 - info->first_gp_reg_save);
6105 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 6106 {
9ebbca7d
GK
6107 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6108 GEN_INT (info->gp_save_offset
6109 + sp_offset
6110 + reg_size * i));
6111 rtx mem = gen_rtx_MEM (reg_mode, addr);
6112 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6113
6114 RTVEC_ELT (p, i) =
6115 gen_rtx_SET (VOIDmode,
6116 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
6117 mem);
979721f8 6118 }
9ebbca7d 6119 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 6120 }
9ebbca7d
GK
6121 else
6122 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
6123 if ((regs_ever_live[info->first_gp_reg_save+i]
6124 && ! call_used_regs[info->first_gp_reg_save+i])
6125 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
ee890fe2
SS
6126 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6127 && flag_pic == 1)
6128 || (DEFAULT_ABI == ABI_DARWIN
6129 && flag_pic))))
9ebbca7d
GK
6130 {
6131 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6132 GEN_INT (info->gp_save_offset
6133 + sp_offset
6134 + reg_size * i));
6135 rtx mem = gen_rtx_MEM (reg_mode, addr);
6136 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6137
6138 emit_move_insn (gen_rtx_REG (reg_mode,
6139 info->first_gp_reg_save + i),
6140 mem);
6141 }
9878760c 6142
9ebbca7d
GK
6143 /* Restore fpr's if we need to do it without calling a function. */
6144 if (restoring_FPRs_inline)
6145 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
6146 if ((regs_ever_live[info->first_fp_reg_save+i]
6147 && ! call_used_regs[info->first_fp_reg_save+i]))
6148 {
6149 rtx addr, mem;
6150 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6151 GEN_INT (info->fp_save_offset
6152 + sp_offset
6153 + 8*i));
6154 mem = gen_rtx_MEM (DFmode, addr);
6155 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6156
6157 emit_move_insn (gen_rtx_REG (DFmode,
6158 info->first_fp_reg_save + i),
6159 mem);
6160 }
8d30c4ee 6161
9ebbca7d
GK
6162 /* If we saved cr, restore it here. Just those that were used. */
6163 if (info->cr_save_p)
979721f8 6164 {
9ebbca7d 6165 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 6166 int count = 0;
9ebbca7d
GK
6167
6168 if (using_mfcr_multiple)
979721f8 6169 {
9ebbca7d
GK
6170 for (i = 0; i < 8; i++)
6171 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 6172 count++;
9ebbca7d 6173 if (count == 0)
e35b9579
GK
6174 abort ();
6175 }
6176
6177 if (using_mfcr_multiple && count > 1)
6178 {
6179 rtvec p;
6180 int ndx;
9ebbca7d 6181
e35b9579 6182 p = rtvec_alloc (count);
9ebbca7d 6183
e35b9579 6184 ndx = 0;
9ebbca7d
GK
6185 for (i = 0; i < 8; i++)
6186 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6187 {
6188 rtvec r = rtvec_alloc (2);
6189 RTVEC_ELT (r, 0) = r12_rtx;
6190 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 6191 RTVEC_ELT (p, ndx) =
9ebbca7d
GK
6192 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
6193 gen_rtx_UNSPEC (CCmode, r, 20));
e35b9579 6194 ndx++;
9ebbca7d
GK
6195 }
6196 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
6197 if (ndx != count)
6198 abort ();
979721f8
MM
6199 }
6200 else
9ebbca7d
GK
6201 for (i = 0; i < 8; i++)
6202 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 6203 {
9ebbca7d
GK
6204 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
6205 CR0_REGNO+i),
6206 r12_rtx));
979721f8 6207 }
979721f8
MM
6208 }
6209
9ebbca7d
GK
6210 /* If this is V.4, unwind the stack pointer after all of the loads
6211 have been done. We need to emit a block here so that sched
6212 doesn't decide to move the sp change before the register restores
6213 (which may not have any obvious dependency on the stack). This
6214 doesn't hurt performance, because there is no scheduling that can
6215 be done after this point. */
6216 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
b6c9286a 6217 {
9ebbca7d
GK
6218 if (frame_reg_rtx != sp_reg_rtx)
6219 rs6000_emit_stack_tie ();
b6c9286a 6220
9ebbca7d 6221 if (use_backchain_to_restore_sp)
b6c9286a 6222 {
9ebbca7d 6223 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 6224 }
9ebbca7d 6225 else if (sp_offset != 0)
13f1623b 6226 {
9ebbca7d
GK
6227 emit_insn (Pmode == SImode
6228 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
6229 GEN_INT (sp_offset))
6230 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
6231 GEN_INT (sp_offset)));
13f1623b 6232 }
9ebbca7d 6233 }
b6c9286a 6234
83720594
RH
6235 if (current_function_calls_eh_return)
6236 {
6237 rtx sa = EH_RETURN_STACKADJ_RTX;
6238 emit_insn (Pmode == SImode
6239 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
6240 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
6241 }
6242
9ebbca7d
GK
6243 if (!sibcall)
6244 {
6245 rtvec p;
6246 if (! restoring_FPRs_inline)
6247 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
6248 else
6249 p = rtvec_alloc (2);
b6c9286a 6250
e35b9579
GK
6251 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
6252 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
6253 gen_rtx_REG (Pmode,
6254 LINK_REGISTER_REGNUM));
9ebbca7d
GK
6255
6256 /* If we have to restore more than two FP registers, branch to the
6257 restore function. It will return to our caller. */
6258 if (! restoring_FPRs_inline)
6259 {
6260 int i;
6261 char rname[30];
520a57c8 6262 const char *alloc_rname;
979721f8 6263
9ebbca7d
GK
6264 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
6265 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 6266 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
6267 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
6268 gen_rtx_SYMBOL_REF (Pmode,
6269 alloc_rname));
b6c9286a 6270
9ebbca7d
GK
6271 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
6272 {
6273 rtx addr, mem;
6274 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
6275 GEN_INT (info->fp_save_offset + 8*i));
6276 mem = gen_rtx_MEM (DFmode, addr);
6277 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6278
6279 RTVEC_ELT (p, i+3) =
6280 gen_rtx_SET (VOIDmode,
6281 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
6282 mem);
b6c9286a
MM
6283 }
6284 }
9ebbca7d
GK
6285
6286 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 6287 }
9878760c
RK
6288}
6289
6290/* Write function epilogue. */
6291
6292void
6293output_epilog (file, size)
6294 FILE *file;
296b8152 6295 int size ATTRIBUTE_UNUSED;
9878760c 6296{
4697a36c 6297 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 6298
9ebbca7d 6299 if (! HAVE_epilogue)
9878760c 6300 {
9ebbca7d
GK
6301 rtx insn = get_last_insn ();
6302 /* If the last insn was a BARRIER, we don't have to write anything except
6303 the trace table. */
6304 if (GET_CODE (insn) == NOTE)
6305 insn = prev_nonnote_insn (insn);
6306 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 6307 {
9ebbca7d
GK
6308 /* This is slightly ugly, but at least we don't have two
6309 copies of the epilogue-emitting code. */
6310 start_sequence ();
6311
6312 /* A NOTE_INSN_DELETED is supposed to be at the start
6313 and end of the "toplevel" insn chain. */
6314 emit_note (0, NOTE_INSN_DELETED);
6315 rs6000_emit_epilogue (FALSE);
6316 emit_note (0, NOTE_INSN_DELETED);
6317
6318 if (TARGET_DEBUG_STACK)
6319 debug_rtx_list (get_insns(), 100);
6320 final (get_insns(), file, FALSE, FALSE);
6321 end_sequence ();
4697a36c 6322 }
9878760c 6323 }
b4ac57ab 6324
9b30bae2 6325 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
6326 on its format.
6327
6328 We don't output a traceback table if -finhibit-size-directive was
6329 used. The documentation for -finhibit-size-directive reads
6330 ``don't output a @code{.size} assembler directive, or anything
6331 else that would cause trouble if the function is split in the
6332 middle, and the two halves are placed at locations far apart in
6333 memory.'' The traceback table has this property, since it
6334 includes the offset from the start of the function to the
4d30c363
MM
6335 traceback table itself.
6336
6337 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a
MM
6338 different traceback table. */
6339 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
9b30bae2 6340 {
3cce094d 6341 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
314fc5a9
ILT
6342 int fixed_parms, float_parms, parm_info;
6343 int i;
6344
b6c9286a
MM
6345 while (*fname == '.') /* V.4 encodes . in the name */
6346 fname++;
6347
314fc5a9
ILT
6348 /* Need label immediately before tbtab, so we can compute its offset
6349 from the function start. */
6350 if (*fname == '*')
6351 ++fname;
6352 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6353 ASM_OUTPUT_LABEL (file, fname);
6354
6355 /* The .tbtab pseudo-op can only be used for the first eight
6356 expressions, since it can't handle the possibly variable
6357 length fields that follow. However, if you omit the optional
6358 fields, the assembler outputs zeros for all optional fields
6359 anyways, giving each variable length field is minimum length
6360 (as defined in sys/debug.h). Thus we can not use the .tbtab
6361 pseudo-op at all. */
6362
6363 /* An all-zero word flags the start of the tbtab, for debuggers
6364 that have to find it by searching forward from the entry
6365 point or from the current pc. */
19d2d16f 6366 fputs ("\t.long 0\n", file);
314fc5a9
ILT
6367
6368 /* Tbtab format type. Use format type 0. */
19d2d16f 6369 fputs ("\t.byte 0,", file);
314fc5a9
ILT
6370
6371 /* Language type. Unfortunately, there doesn't seem to be any
6372 official way to get this info, so we use language_string. C
6373 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 6374 value for C for now. There is no official value for Java,
6f573ff9
JL
6375 although IBM appears to be using 13. There is no official value
6376 for Chill, so we've choosen 44 pseudo-randomly. */
314fc5a9 6377 if (! strcmp (language_string, "GNU C")
e2c953b6 6378 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
6379 i = 0;
6380 else if (! strcmp (language_string, "GNU F77"))
6381 i = 1;
6382 else if (! strcmp (language_string, "GNU Ada"))
6383 i = 3;
8b83775b 6384 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
6385 i = 2;
6386 else if (! strcmp (language_string, "GNU C++"))
6387 i = 9;
9517ead8
AG
6388 else if (! strcmp (language_string, "GNU Java"))
6389 i = 13;
6f573ff9
JL
6390 else if (! strcmp (language_string, "GNU CHILL"))
6391 i = 44;
314fc5a9
ILT
6392 else
6393 abort ();
6394 fprintf (file, "%d,", i);
6395
6396 /* 8 single bit fields: global linkage (not set for C extern linkage,
6397 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
6398 from start of procedure stored in tbtab, internal function, function
6399 has controlled storage, function has no toc, function uses fp,
6400 function logs/aborts fp operations. */
6401 /* Assume that fp operations are used if any fp reg must be saved. */
4697a36c 6402 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
6403
6404 /* 6 bitfields: function is interrupt handler, name present in
6405 proc table, function calls alloca, on condition directives
6406 (controls stack walks, 3 bits), saves condition reg, saves
6407 link reg. */
6408 /* The `function calls alloca' bit seems to be set whenever reg 31 is
6409 set up as a frame pointer, even when there is no alloca call. */
6410 fprintf (file, "%d,",
6411 ((1 << 6) | (frame_pointer_needed << 5)
4697a36c 6412 | (info->cr_save_p << 1) | (info->lr_save_p)));
314fc5a9
ILT
6413
6414 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
6415 (6 bits). */
6416 fprintf (file, "%d,",
4697a36c 6417 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
6418
6419 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
6420 fprintf (file, "%d,", (32 - first_reg_to_save ()));
6421
6422 {
6423 /* Compute the parameter info from the function decl argument
6424 list. */
6425 tree decl;
6426 int next_parm_info_bit;
6427
6428 next_parm_info_bit = 31;
6429 parm_info = 0;
6430 fixed_parms = 0;
6431 float_parms = 0;
6432
6433 for (decl = DECL_ARGUMENTS (current_function_decl);
6434 decl; decl = TREE_CHAIN (decl))
6435 {
6436 rtx parameter = DECL_INCOMING_RTL (decl);
6437 enum machine_mode mode = GET_MODE (parameter);
6438
6439 if (GET_CODE (parameter) == REG)
6440 {
6441 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6442 {
6443 int bits;
6444
6445 float_parms++;
6446
6447 if (mode == SFmode)
6448 bits = 0x2;
6449 else if (mode == DFmode)
6450 bits = 0x3;
6451 else
6452 abort ();
6453
6454 /* If only one bit will fit, don't or in this entry. */
6455 if (next_parm_info_bit > 0)
6456 parm_info |= (bits << (next_parm_info_bit - 1));
6457 next_parm_info_bit -= 2;
6458 }
6459 else
6460 {
6461 fixed_parms += ((GET_MODE_SIZE (mode)
6462 + (UNITS_PER_WORD - 1))
6463 / UNITS_PER_WORD);
6464 next_parm_info_bit -= 1;
6465 }
6466 }
6467 }
6468 }
6469
6470 /* Number of fixed point parameters. */
6471 /* This is actually the number of words of fixed point parameters; thus
6472 an 8 byte struct counts as 2; and thus the maximum value is 8. */
6473 fprintf (file, "%d,", fixed_parms);
6474
6475 /* 2 bitfields: number of floating point parameters (7 bits), parameters
6476 all on stack. */
6477 /* This is actually the number of fp registers that hold parameters;
6478 and thus the maximum value is 13. */
6479 /* Set parameters on stack bit if parameters are not in their original
6480 registers, regardless of whether they are on the stack? Xlc
6481 seems to set the bit when not optimizing. */
6482 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
6483
6484 /* Optional fields follow. Some are variable length. */
6485
6486 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
6487 11 double float. */
6488 /* There is an entry for each parameter in a register, in the order that
6489 they occur in the parameter list. Any intervening arguments on the
6490 stack are ignored. If the list overflows a long (max possible length
6491 34 bits) then completely leave off all elements that don't fit. */
6492 /* Only emit this long if there was at least one parameter. */
6493 if (fixed_parms || float_parms)
6494 fprintf (file, "\t.long %d\n", parm_info);
6495
6496 /* Offset from start of code to tb table. */
19d2d16f 6497 fputs ("\t.long ", file);
314fc5a9 6498 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
9ebbca7d 6499#if TARGET_AIX
314fc5a9 6500 RS6000_OUTPUT_BASENAME (file, fname);
9ebbca7d
GK
6501#else
6502 assemble_name (file, fname);
6503#endif
19d2d16f 6504 fputs ("-.", file);
9ebbca7d 6505#if TARGET_AIX
314fc5a9 6506 RS6000_OUTPUT_BASENAME (file, fname);
9ebbca7d
GK
6507#else
6508 assemble_name (file, fname);
6509#endif
19d2d16f 6510 putc ('\n', file);
314fc5a9
ILT
6511
6512 /* Interrupt handler mask. */
6513 /* Omit this long, since we never set the interrupt handler bit
6514 above. */
6515
6516 /* Number of CTL (controlled storage) anchors. */
6517 /* Omit this long, since the has_ctl bit is never set above. */
6518
6519 /* Displacement into stack of each CTL anchor. */
6520 /* Omit this list of longs, because there are no CTL anchors. */
6521
6522 /* Length of function name. */
296b8152 6523 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
6524
6525 /* Function name. */
6526 assemble_string (fname, strlen (fname));
6527
6528 /* Register for alloca automatic storage; this is always reg 31.
6529 Only emit this if the alloca bit was set above. */
6530 if (frame_pointer_needed)
19d2d16f 6531 fputs ("\t.byte 31\n", file);
9b30bae2 6532 }
9878760c 6533}
17167fd8
MM
6534\f
6535/* A C compound statement that outputs the assembler code for a thunk function,
6536 used to implement C++ virtual function calls with multiple inheritance. The
6537 thunk acts as a wrapper around a virtual function, adjusting the implicit
6538 object parameter before handing control off to the real function.
6539
6540 First, emit code to add the integer DELTA to the location that contains the
6541 incoming first argument. Assume that this argument contains a pointer, and
6542 is the one used to pass the `this' pointer in C++. This is the incoming
6543 argument *before* the function prologue, e.g. `%o0' on a sparc. The
6544 addition must preserve the values of all other incoming arguments.
6545
6546 After the addition, emit code to jump to FUNCTION, which is a
6547 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
6548 the return address. Hence returning from FUNCTION will return to whoever
6549 called the current `thunk'.
6550
6551 The effect must be as if FUNCTION had been called directly with the adjusted
6552 first argument. This macro is responsible for emitting all of the code for
6553 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
6554 invoked.
6555
6556 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
6557 extracted from it.) It might possibly be useful on some targets, but
6558 probably not.
6559
6560 If you do not define this macro, the target-independent code in the C++
6561 frontend will generate a less efficient heavyweight thunk that calls
6562 FUNCTION instead of jumping to it. The generic approach does not support
6563 varargs. */
6564
6565void
6566output_mi_thunk (file, thunk_fndecl, delta, function)
6567 FILE *file;
d330fd93 6568 tree thunk_fndecl ATTRIBUTE_UNUSED;
17167fd8
MM
6569 int delta;
6570 tree function;
6571{
d330fd93
KG
6572 const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
6573 const char *prefix;
3cce094d 6574 const char *fname;
d330fd93 6575 const char *r0 = reg_names[0];
d330fd93
KG
6576 const char *toc = reg_names[2];
6577 const char *schain = reg_names[11];
6578 const char *r12 = reg_names[12];
17167fd8
MM
6579 char buf[512];
6580 static int labelno = 0;
6581
6582 /* Small constants that can be done by one add instruction */
6583 if (delta >= -32768 && delta <= 32767)
6584 {
22b4a3b0 6585 if (! TARGET_NEW_MNEMONICS)
17167fd8
MM
6586 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
6587 else
6588 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
6589 }
6590
6591 /* Large constants that can be done by one addis instruction */
6592 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
6593 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6594 delta >> 16);
6595
6596 /* 32-bit constants that can be done by an add and addis instruction. */
6597 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
6598 {
22b4a3b0 6599 /* Break into two pieces, propagating the sign bit from the low word to
17167fd8
MM
6600 the upper word. */
6601 int delta_high = delta >> 16;
6602 int delta_low = delta & 0xffff;
6603 if ((delta_low & 0x8000) != 0)
6604 {
6605 delta_high++;
6606 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
6607 }
6608
6609 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6610 delta_high);
6611
22b4a3b0 6612 if (! TARGET_NEW_MNEMONICS)
17167fd8
MM
6613 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
6614 else
6615 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
6616 }
6617
6618 /* 64-bit constants, fixme */
6619 else
6620 abort ();
6621
6622 /* Get the prefix in front of the names. */
6623 switch (DEFAULT_ABI)
6624 {
6625 default:
6626 abort ();
6627
6628 case ABI_AIX:
6629 prefix = ".";
6630 break;
6631
6632 case ABI_V4:
6633 case ABI_AIX_NODESC:
6634 case ABI_SOLARIS:
6635 prefix = "";
6636 break;
17167fd8
MM
6637 }
6638
6639 /* If the function is compiled in this module, jump to it directly.
6640 Otherwise, load up its address and jump to it. */
6641
6642 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
42820a49 6643
9ebbca7d 6644 if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode)
22b4a3b0
FS
6645 && ! lookup_attribute ("longcall",
6646 TYPE_ATTRIBUTES (TREE_TYPE (function))))
17167fd8
MM
6647 {
6648 fprintf (file, "\tb %s", prefix);
6649 assemble_name (file, fname);
22b4a3b0 6650 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
949ea356 6651 putc ('\n', file);
17167fd8
MM
6652 }
6653
6654 else
6655 {
6656 switch (DEFAULT_ABI)
6657 {
6658 default:
17167fd8
MM
6659 abort ();
6660
6661 case ABI_AIX:
6662 /* Set up a TOC entry for the function. */
6663 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
6664 toc_section ();
6665 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
6666 labelno++;
6667
6668 /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since
6669 there will be only one TOC entry for this function. */
6670 fputs ("\t.tc\t", file);
6671 assemble_name (file, buf);
6672 fputs ("[TC],", file);
6673 assemble_name (file, buf);
6674 putc ('\n', file);
6675 text_section ();
6676 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12);
6677 assemble_name (file, buf);
6678 asm_fprintf (file, "(%s)\n", reg_names[2]);
6679 asm_fprintf (file,
6680 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
6681 r0, r12);
6682
6683 asm_fprintf (file,
6684 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
6685 toc, r12);
6686
6687 asm_fprintf (file, "\tmtctr %s\n", r0);
6688 asm_fprintf (file,
6689 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
6690 schain, r12);
6691
6692 asm_fprintf (file, "\tbctr\n");
6693 break;
6694
9ebbca7d
GK
6695 case ABI_AIX_NODESC:
6696 case ABI_SOLARIS:
17167fd8 6697 case ABI_V4:
22b4a3b0
FS
6698 fprintf (file, "\tb %s", prefix);
6699 assemble_name (file, fname);
6700 if (flag_pic) fputs ("@plt", file);
949ea356 6701 putc ('\n', file);
22b4a3b0 6702 break;
ee890fe2
SS
6703
6704#if TARGET_MACHO
6705 case ABI_DARWIN:
6706 fprintf (file, "\tb %s", prefix);
6707 if (flag_pic && !machopic_name_defined_p (fname))
6708 assemble_name (file, machopic_stub_name (fname));
6709 else
6710 assemble_name (file, fname);
6711 putc ('\n', file);
6712 break;
6713#endif
9ebbca7d
GK
6714 }
6715 }
6716}
42820a49 6717
9ebbca7d
GK
6718\f
6719/* A quick summary of the various types of 'constant-pool tables'
6720 under PowerPC:
6721
6722 Target Flags Name One table per
6723 AIX (none) AIX TOC object file
6724 AIX -mfull-toc AIX TOC object file
6725 AIX -mminimal-toc AIX minimal TOC translation unit
6726 SVR4/EABI (none) SVR4 SDATA object file
6727 SVR4/EABI -fpic SVR4 pic object file
6728 SVR4/EABI -fPIC SVR4 PIC translation unit
6729 SVR4/EABI -mrelocatable EABI TOC function
6730 SVR4/EABI -maix AIX TOC object file
6731 SVR4/EABI -maix -mminimal-toc
6732 AIX minimal TOC translation unit
6733
6734 Name Reg. Set by entries contains:
6735 made by addrs? fp? sum?
6736
6737 AIX TOC 2 crt0 as Y option option
6738 AIX minimal TOC 30 prolog gcc Y Y option
6739 SVR4 SDATA 13 crt0 gcc N Y N
6740 SVR4 pic 30 prolog ld Y not yet N
6741 SVR4 PIC 30 prolog gcc Y option option
6742 EABI TOC 30 prolog gcc Y option option
6743
6744*/
6745
6746/* Hash table stuff for keeping track of TOC entries. */
6747
6748struct toc_hash_struct
6749{
6750 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
6751 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
6752 rtx key;
a9098fd0 6753 enum machine_mode key_mode;
9ebbca7d
GK
6754 int labelno;
6755};
17167fd8 6756
9ebbca7d
GK
6757static htab_t toc_hash_table;
6758
6759/* Hash functions for the hash table. */
6760
6761static unsigned
6762rs6000_hash_constant (k)
6763 rtx k;
6764{
a9098fd0 6765 unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k);
9ebbca7d
GK
6766 const char *format = GET_RTX_FORMAT (GET_CODE (k));
6767 int flen = strlen (format);
6768 int fidx;
6769
6770 if (GET_CODE (k) == LABEL_REF)
832ea3b3 6771 return result * 1231 + X0INT (XEXP (k, 0), 3);
9ebbca7d
GK
6772
6773 if (GET_CODE (k) == CONST_DOUBLE)
6774 fidx = 2;
6775 else if (GET_CODE (k) == CODE_LABEL)
6776 fidx = 3;
6777 else
6778 fidx = 0;
6779
6780 for (; fidx < flen; fidx++)
6781 switch (format[fidx])
6782 {
6783 case 's':
6784 {
6785 unsigned i, len;
6786 const char *str = XSTR (k, fidx);
6787 len = strlen (str);
6788 result = result * 613 + len;
6789 for (i = 0; i < len; i++)
6790 result = result * 613 + (unsigned) str[i];
17167fd8
MM
6791 break;
6792 }
9ebbca7d
GK
6793 case 'u':
6794 case 'e':
6795 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
6796 break;
6797 case 'i':
6798 case 'n':
6799 result = result * 613 + (unsigned) XINT (k, fidx);
6800 break;
6801 case 'w':
6802 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
6803 result = result * 613 + (unsigned) XWINT (k, fidx);
6804 else
6805 {
6806 size_t i;
6807 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
6808 result = result * 613 + (unsigned) (XWINT (k, fidx)
6809 >> CHAR_BIT * i);
6810 }
6811 break;
6812 default:
6813 abort();
6814 }
6815 return result;
6816}
6817
6818static unsigned
6819toc_hash_function (hash_entry)
6820 const void * hash_entry;
6821{
a9098fd0
GK
6822 const struct toc_hash_struct *thc =
6823 (const struct toc_hash_struct *) hash_entry;
6824 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
6825}
6826
6827/* Compare H1 and H2 for equivalence. */
6828
6829static int
6830toc_hash_eq (h1, h2)
6831 const void * h1;
6832 const void * h2;
6833{
6834 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
6835 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
6836
a9098fd0
GK
6837 if (((const struct toc_hash_struct *) h1)->key_mode
6838 != ((const struct toc_hash_struct *) h2)->key_mode)
6839 return 0;
6840
9ebbca7d
GK
6841 /* Gotcha: One of these const_doubles will be in memory.
6842 The other may be on the constant-pool chain.
6843 So rtx_equal_p will think they are different... */
6844 if (r1 == r2)
6845 return 1;
6846 if (GET_CODE (r1) != GET_CODE (r2)
6847 || GET_MODE (r1) != GET_MODE (r2))
6848 return 0;
6849 if (GET_CODE (r1) == CONST_DOUBLE)
6850 {
6851 int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE));
6852 int i;
6853 for (i = 2; i < format_len; i++)
6854 if (XWINT (r1, i) != XWINT (r2, i))
6855 return 0;
6856
6857 return 1;
17167fd8 6858 }
9ebbca7d 6859 else if (GET_CODE (r1) == LABEL_REF)
e4a0656f
GK
6860 return (CODE_LABEL_NUMBER (XEXP (r1, 0))
6861 == CODE_LABEL_NUMBER (XEXP (r2, 0)));
9ebbca7d
GK
6862 else
6863 return rtx_equal_p (r1, r2);
6864}
6865
6866/* Mark the hash table-entry HASH_ENTRY. */
6867
6868static int
6869toc_hash_mark_entry (hash_slot, unused)
2eba1afa 6870 void ** hash_slot;
9ebbca7d
GK
6871 void * unused ATTRIBUTE_UNUSED;
6872{
6873 const struct toc_hash_struct * hash_entry =
6874 *(const struct toc_hash_struct **) hash_slot;
6875 rtx r = hash_entry->key;
6876 ggc_set_mark (hash_entry);
6877 /* For CODE_LABELS, we don't want to drag in the whole insn chain... */
6878 if (GET_CODE (r) == LABEL_REF)
6879 {
6880 ggc_set_mark (r);
6881 ggc_set_mark (XEXP (r, 0));
6882 }
6883 else
6884 ggc_mark_rtx (r);
6885 return 1;
6886}
6887
6888/* Mark all the elements of the TOC hash-table *HT. */
6889
6890static void
6891toc_hash_mark_table (vht)
6892 void *vht;
6893{
6894 htab_t *ht = vht;
6895
6896 htab_traverse (*ht, toc_hash_mark_entry, (void *)0);
17167fd8
MM
6897}
6898
28e510bd
MM
6899/* These are the names given by the C++ front-end to vtables, and
6900 vtable-like objects. Ideally, this logic should not be here;
6901 instead, there should be some programmatic way of inquiring as
6902 to whether or not an object is a vtable. */
6903
6904#define VTABLE_NAME_P(NAME) \
6905 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
6906 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
6907 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
6908 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
6909
6910void
6911rs6000_output_symbol_ref (file, x)
6912 FILE *file;
6913 rtx x;
6914{
6915 /* Currently C++ toc references to vtables can be emitted before it
6916 is decided whether the vtable is public or private. If this is
6917 the case, then the linker will eventually complain that there is
6918 a reference to an unknown section. Thus, for vtables only,
6919 we emit the TOC reference to reference the symbol and not the
6920 section. */
6921 const char *name = XSTR (x, 0);
6922
6923 if (VTABLE_NAME_P (name))
6924 {
6925 RS6000_OUTPUT_BASENAME (file, name);
6926 }
6927 else
6928 assemble_name (file, name);
6929}
6930
9878760c
RK
6931/* Output a TOC entry. We derive the entry name from what is
6932 being written. */
6933
6934void
a9098fd0 6935output_toc (file, x, labelno, mode)
9878760c
RK
6936 FILE *file;
6937 rtx x;
6938 int labelno;
a9098fd0 6939 enum machine_mode mode;
9878760c
RK
6940{
6941 char buf[256];
3cce094d 6942 const char *name = buf;
ec940faa 6943 const char *real_name;
9878760c
RK
6944 rtx base = x;
6945 int offset = 0;
6946
4697a36c
MM
6947 if (TARGET_NO_TOC)
6948 abort ();
6949
9ebbca7d
GK
6950 /* When the linker won't eliminate them, don't output duplicate
6951 TOC entries (this happens on AIX if there is any kind of TOC,
1f8f4a0b
MM
6952 and on SVR4 under -fPIC or -mrelocatable). */
6953 if (TARGET_TOC)
9ebbca7d
GK
6954 {
6955 struct toc_hash_struct *h;
6956 void * * found;
6957
6958 h = ggc_alloc (sizeof (*h));
6959 h->key = x;
a9098fd0 6960 h->key_mode = mode;
9ebbca7d
GK
6961 h->labelno = labelno;
6962
6963 found = htab_find_slot (toc_hash_table, h, 1);
6964 if (*found == NULL)
6965 *found = h;
6966 else /* This is indeed a duplicate.
6967 Set this label equal to that label. */
6968 {
6969 fputs ("\t.set ", file);
6970 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6971 fprintf (file, "%d,", labelno);
6972 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6973 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
6974 found)->labelno));
6975 return;
6976 }
6977 }
6978
6979 /* If we're going to put a double constant in the TOC, make sure it's
6980 aligned properly when strict alignment is on. */
ff1720ed
RK
6981 if (GET_CODE (x) == CONST_DOUBLE
6982 && STRICT_ALIGNMENT
a9098fd0 6983 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
6984 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
6985 ASM_OUTPUT_ALIGN (file, 3);
6986 }
6987
9ebbca7d 6988 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
9878760c 6989
37c37a57
RK
6990 /* Handle FP constants specially. Note that if we have a minimal
6991 TOC, things we put here aren't actually in the TOC, so we can allow
6992 FP constants. */
a9098fd0 6993 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 6994 {
042259f2
DE
6995 REAL_VALUE_TYPE rv;
6996 long k[2];
0adc764e 6997
042259f2
DE
6998 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
6999 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 7000
13ded975
DE
7001 if (TARGET_64BIT)
7002 {
7003 if (TARGET_MINIMAL_TOC)
7004 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
7005 else
7006 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
0858c623 7007 k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
7008 return;
7009 }
1875cc88 7010 else
13ded975
DE
7011 {
7012 if (TARGET_MINIMAL_TOC)
31bfaa0b 7013 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]);
13ded975 7014 else
31bfaa0b 7015 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n",
13ded975
DE
7016 k[0], k[1], k[0], k[1]);
7017 return;
7018 }
9878760c 7019 }
a9098fd0 7020 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 7021 {
042259f2
DE
7022 REAL_VALUE_TYPE rv;
7023 long l;
9878760c 7024
042259f2
DE
7025 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
7026 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7027
31bfaa0b
DE
7028 if (TARGET_64BIT)
7029 {
7030 if (TARGET_MINIMAL_TOC)
7031 fprintf (file, "\t.llong 0x%lx00000000\n", l);
7032 else
7033 fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l);
7034 return;
7035 }
042259f2 7036 else
31bfaa0b
DE
7037 {
7038 if (TARGET_MINIMAL_TOC)
7039 fprintf (file, "\t.long 0x%lx\n", l);
7040 else
7041 fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l);
7042 return;
7043 }
042259f2 7044 }
f176e826 7045 else if (GET_MODE (x) == VOIDmode
a9098fd0 7046 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 7047 {
e2c953b6 7048 unsigned HOST_WIDE_INT low;
042259f2
DE
7049 HOST_WIDE_INT high;
7050
7051 if (GET_CODE (x) == CONST_DOUBLE)
7052 {
7053 low = CONST_DOUBLE_LOW (x);
7054 high = CONST_DOUBLE_HIGH (x);
7055 }
7056 else
7057#if HOST_BITS_PER_WIDE_INT == 32
7058 {
7059 low = INTVAL (x);
0858c623 7060 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
7061 }
7062#else
7063 {
0858c623 7064 low = INTVAL (x) & 0xffffffff;
042259f2
DE
7065 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
7066 }
7067#endif
9878760c 7068
a9098fd0
GK
7069 /* TOC entries are always Pmode-sized, but since this
7070 is a bigendian machine then if we're putting smaller
7071 integer constants in the TOC we have to pad them.
7072 (This is still a win over putting the constants in
7073 a separate constant pool, because then we'd have
02a4ec28
FS
7074 to have both a TOC entry _and_ the actual constant.)
7075
7076 For a 32-bit target, CONST_INT values are loaded and shifted
7077 entirely within `low' and can be stored in one TOC entry. */
7078
7079 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 7080 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
7081
7082 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
a9098fd0
GK
7083 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
7084 POINTER_SIZE, &low, &high, 0);
7085
13ded975
DE
7086 if (TARGET_64BIT)
7087 {
7088 if (TARGET_MINIMAL_TOC)
7089 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
7090 else
7091 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
7092 (long)high, (long)low, (long)high, (long)low);
7093 return;
7094 }
1875cc88 7095 else
13ded975 7096 {
02a4ec28
FS
7097 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
7098 {
7099 if (TARGET_MINIMAL_TOC)
7100 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n",
7101 (long)high, (long)low);
7102 else
7103 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n",
7104 (long)high, (long)low, (long)high, (long)low);
7105 }
13ded975 7106 else
02a4ec28
FS
7107 {
7108 if (TARGET_MINIMAL_TOC)
7109 fprintf (file, "\t.long 0x%lx\n",
7110 (long)low);
7111 else
7112 fprintf (file, "\t.tc IS_%lx[TC],0x%lx\n",
7113 (long)low, (long)low);
7114 }
13ded975
DE
7115 return;
7116 }
9878760c
RK
7117 }
7118
7119 if (GET_CODE (x) == CONST)
7120 {
7121 base = XEXP (XEXP (x, 0), 0);
7122 offset = INTVAL (XEXP (XEXP (x, 0), 1));
7123 }
7124
7125 if (GET_CODE (base) == SYMBOL_REF)
7126 name = XSTR (base, 0);
7127 else if (GET_CODE (base) == LABEL_REF)
7128 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
7129 else if (GET_CODE (base) == CODE_LABEL)
7130 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
7131 else
7132 abort ();
7133
2e4eb9b0 7134 STRIP_NAME_ENCODING (real_name, name);
1875cc88 7135 if (TARGET_MINIMAL_TOC)
13ded975 7136 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
1875cc88
JW
7137 else
7138 {
b6c9286a 7139 fprintf (file, "\t.tc %s", real_name);
9878760c 7140
1875cc88
JW
7141 if (offset < 0)
7142 fprintf (file, ".N%d", - offset);
7143 else if (offset)
7144 fprintf (file, ".P%d", offset);
9878760c 7145
19d2d16f 7146 fputs ("[TC],", file);
1875cc88 7147 }
581bc4de
MM
7148
7149 /* Currently C++ toc references to vtables can be emitted before it
7150 is decided whether the vtable is public or private. If this is
7151 the case, then the linker will eventually complain that there is
7152 a TOC reference to an unknown section. Thus, for vtables only,
7153 we emit the TOC reference to reference the symbol and not the
7154 section. */
28e510bd 7155 if (VTABLE_NAME_P (name))
581bc4de 7156 {
89c01f0e 7157 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
7158 if (offset < 0)
7159 fprintf (file, "%d", offset);
7160 else if (offset > 0)
7161 fprintf (file, "+%d", offset);
7162 }
7163 else
7164 output_addr_const (file, x);
19d2d16f 7165 putc ('\n', file);
9878760c
RK
7166}
7167\f
7168/* Output an assembler pseudo-op to write an ASCII string of N characters
7169 starting at P to FILE.
7170
7171 On the RS/6000, we have to do this using the .byte operation and
7172 write out special characters outside the quoted string.
7173 Also, the assembler is broken; very long strings are truncated,
7174 so we must artificially break them up early. */
7175
7176void
7177output_ascii (file, p, n)
7178 FILE *file;
d330fd93 7179 const char *p;
9878760c
RK
7180 int n;
7181{
7182 char c;
7183 int i, count_string;
d330fd93
KG
7184 const char *for_string = "\t.byte \"";
7185 const char *for_decimal = "\t.byte ";
7186 const char *to_close = NULL;
9878760c
RK
7187
7188 count_string = 0;
7189 for (i = 0; i < n; i++)
7190 {
7191 c = *p++;
7192 if (c >= ' ' && c < 0177)
7193 {
7194 if (for_string)
7195 fputs (for_string, file);
7196 putc (c, file);
7197
7198 /* Write two quotes to get one. */
7199 if (c == '"')
7200 {
7201 putc (c, file);
7202 ++count_string;
7203 }
7204
7205 for_string = NULL;
7206 for_decimal = "\"\n\t.byte ";
7207 to_close = "\"\n";
7208 ++count_string;
7209
7210 if (count_string >= 512)
7211 {
7212 fputs (to_close, file);
7213
7214 for_string = "\t.byte \"";
7215 for_decimal = "\t.byte ";
7216 to_close = NULL;
7217 count_string = 0;
7218 }
7219 }
7220 else
7221 {
7222 if (for_decimal)
7223 fputs (for_decimal, file);
7224 fprintf (file, "%d", c);
7225
7226 for_string = "\n\t.byte \"";
7227 for_decimal = ", ";
7228 to_close = "\n";
7229 count_string = 0;
7230 }
7231 }
7232
7233 /* Now close the string if we have written one. Then end the line. */
7234 if (to_close)
9ebbca7d 7235 fputs (to_close, file);
9878760c
RK
7236}
7237\f
7238/* Generate a unique section name for FILENAME for a section type
7239 represented by SECTION_DESC. Output goes into BUF.
7240
7241 SECTION_DESC can be any string, as long as it is different for each
7242 possible section type.
7243
7244 We name the section in the same manner as xlc. The name begins with an
7245 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
7246 names) with the last period replaced by the string SECTION_DESC. If
7247 FILENAME does not contain a period, SECTION_DESC is appended to the end of
7248 the name. */
9878760c
RK
7249
7250void
7251rs6000_gen_section_name (buf, filename, section_desc)
7252 char **buf;
9ebbca7d
GK
7253 const char *filename;
7254 const char *section_desc;
9878760c 7255{
9ebbca7d 7256 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
7257 char *p;
7258 int len;
9878760c
RK
7259
7260 after_last_slash = filename;
7261 for (q = filename; *q; q++)
11e5fe42
RK
7262 {
7263 if (*q == '/')
7264 after_last_slash = q + 1;
7265 else if (*q == '.')
7266 last_period = q;
7267 }
9878760c 7268
11e5fe42 7269 len = strlen (after_last_slash) + strlen (section_desc) + 2;
9878760c
RK
7270 *buf = (char *) permalloc (len);
7271
7272 p = *buf;
7273 *p++ = '_';
7274
7275 for (q = after_last_slash; *q; q++)
7276 {
11e5fe42 7277 if (q == last_period)
9878760c
RK
7278 {
7279 strcpy (p, section_desc);
7280 p += strlen (section_desc);
9878760c
RK
7281 }
7282
e9a780ec 7283 else if (ISALNUM (*q))
9878760c
RK
7284 *p++ = *q;
7285 }
7286
11e5fe42 7287 if (last_period == 0)
9878760c
RK
7288 strcpy (p, section_desc);
7289 else
7290 *p = '\0';
7291}
e165f3f0 7292\f
411707f4
CC
7293
7294/* Emit profile function. */
7295void
7296output_profile_hook (labelno)
7297 int labelno;
7298{
8480e480
CC
7299 if (DEFAULT_ABI == ABI_AIX)
7300 {
7301 char buf[30];
7302 char *label_name;
7303 rtx fun;
411707f4 7304
8480e480 7305 labelno += 1;
411707f4 7306
8480e480
CC
7307 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7308 STRIP_NAME_ENCODING (label_name, ggc_strdup (buf));
7309 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 7310
8480e480
CC
7311 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
7312 fun, Pmode);
7313 }
ee890fe2
SS
7314 else if (DEFAULT_ABI == ABI_DARWIN)
7315 {
7316 char *mcount_name = RS6000_MCOUNT;
7317 int caller_addr_regno = LINK_REGISTER_REGNUM;
7318
7319 /* Be conservative and always set this, at least for now. */
7320 current_function_uses_pic_offset_table = 1;
7321
7322#if TARGET_MACHO
7323 /* For PIC code, set up a stub and collect the caller's address
7324 from r0, which is where the prologue puts it. */
7325 if (flag_pic)
7326 {
7327 mcount_name = machopic_stub_name (mcount_name);
7328 if (current_function_uses_pic_offset_table)
7329 caller_addr_regno = 0;
7330 }
7331#endif
7332 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
7333 0, VOIDmode, 1,
7334 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
7335 }
411707f4
CC
7336}
7337
e165f3f0
RK
7338/* Write function profiler code. */
7339
7340void
7341output_function_profiler (file, labelno)
7342 FILE *file;
7343 int labelno;
7344{
7345 /* The last used parameter register. */
7346 int last_parm_reg;
7347 int i, j;
3daf36a4 7348 char buf[100];
e165f3f0 7349
3daf36a4 7350 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 7351 switch (DEFAULT_ABI)
3daf36a4 7352 {
38c1f2d7
MM
7353 default:
7354 abort ();
7355
7356 case ABI_V4:
7357 case ABI_SOLARIS:
7358 case ABI_AIX_NODESC:
7359 fprintf (file, "\tmflr %s\n", reg_names[0]);
7360 if (flag_pic == 1)
7361 {
dfdfa60f
DE
7362 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
7363 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7364 reg_names[0], reg_names[1]);
17167fd8 7365 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 7366 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 7367 assemble_name (file, buf);
17167fd8 7368 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 7369 }
9ebbca7d 7370 else if (flag_pic > 1)
38c1f2d7 7371 {
dfdfa60f
DE
7372 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7373 reg_names[0], reg_names[1]);
9ebbca7d
GK
7374 /* Now, we need to get the address of the label. */
7375 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 7376 assemble_name (file, buf);
9ebbca7d
GK
7377 fputs ("-.\n1:", file);
7378 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
7379 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
7380 reg_names[0], reg_names[11]);
7381 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
7382 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 7383 }
38c1f2d7
MM
7384 else
7385 {
17167fd8 7386 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 7387 assemble_name (file, buf);
dfdfa60f 7388 fputs ("@ha\n", file);
b5253831
DE
7389 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7390 reg_names[0], reg_names[1]);
a260abc9 7391 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 7392 assemble_name (file, buf);
17167fd8 7393 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
7394 }
7395
b5253831
DE
7396 if (current_function_needs_context)
7397 asm_fprintf (file, "\tmr %s,%s\n",
7398 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
38c1f2d7 7399 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
b5253831
DE
7400 if (current_function_needs_context)
7401 asm_fprintf (file, "\tmr %s,%s\n",
7402 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
38c1f2d7
MM
7403 break;
7404
7405 case ABI_AIX:
ee890fe2 7406 case ABI_DARWIN:
411707f4 7407 /* Don't do anything, done in output_profile_hook (). */
38c1f2d7 7408 break;
411707f4 7409
38c1f2d7 7410 }
e165f3f0 7411}
a251ffd0
TG
7412
7413/* Adjust the cost of a scheduling dependency. Return the new cost of
7414 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7415
7416int
a06faf84 7417rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
7418 rtx insn;
7419 rtx link;
296b8152 7420 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
7421 int cost;
7422{
7423 if (! recog_memoized (insn))
7424 return 0;
7425
7426 if (REG_NOTE_KIND (link) != 0)
7427 return 0;
7428
7429 if (REG_NOTE_KIND (link) == 0)
7430 {
7431 /* Data dependency; DEP_INSN writes a register that INSN reads some
7432 cycles later. */
7433
7434 /* Tell the first scheduling pass about the latency between a mtctr
7435 and bctr (and mtlr and br/blr). The first scheduling pass will not
7436 know about this latency since the mtctr instruction, which has the
7437 latency associated to it, will be generated by reload. */
7438 if (get_attr_type (insn) == TYPE_JMPREG)
7439 return TARGET_POWER ? 5 : 4;
7440
7441 /* Fall out to return default cost. */
7442 }
7443
7444 return cost;
7445}
b6c9286a 7446
bef84347
VM
7447/* A C statement (sans semicolon) to update the integer scheduling priority
7448 INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier,
7449 increase the priority to execute INSN later. Do not define this macro if
7450 you do not need to adjust the scheduling priorities of insns. */
7451
7452int
7453rs6000_adjust_priority (insn, priority)
d330fd93 7454 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
7455 int priority;
7456{
7457 /* On machines (like the 750) which have asymetric integer units, where one
7458 integer unit can do multiply and divides and the other can't, reduce the
7459 priority of multiply/divide so it is scheduled before other integer
7460 operationss. */
7461
7462#if 0
2c3c49de 7463 if (! INSN_P (insn))
bef84347
VM
7464 return priority;
7465
7466 if (GET_CODE (PATTERN (insn)) == USE)
7467 return priority;
7468
7469 switch (rs6000_cpu_attr) {
7470 case CPU_PPC750:
7471 switch (get_attr_type (insn))
7472 {
7473 default:
7474 break;
7475
7476 case TYPE_IMUL:
7477 case TYPE_IDIV:
3cb999d8
DE
7478 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
7479 priority, priority);
bef84347
VM
7480 if (priority >= 0 && priority < 0x01000000)
7481 priority >>= 3;
7482 break;
7483 }
7484 }
7485#endif
7486
7487 return priority;
7488}
7489
b6c9286a
MM
7490/* Return how many instructions the machine can issue per cycle */
7491int get_issue_rate()
7492{
7493 switch (rs6000_cpu_attr) {
3cb999d8
DE
7494 case CPU_RIOS1: /* ? */
7495 case CPU_RS64A:
7496 case CPU_PPC601: /* ? */
7497 return 3;
b6c9286a 7498 case CPU_PPC603:
bef84347
VM
7499 case CPU_PPC750:
7500 return 2;
3cb999d8 7501 case CPU_RIOS2:
b6c9286a 7502 case CPU_PPC604:
19684119 7503 case CPU_PPC604E:
b6c9286a 7504 case CPU_PPC620:
3cb999d8 7505 case CPU_PPC630:
b6c9286a
MM
7506 return 4;
7507 default:
7508 return 1;
7509 }
7510}
7511
b6c9286a 7512\f
b6c9286a
MM
7513/* Length in units of the trampoline for entering a nested function. */
7514
7515int
7516rs6000_trampoline_size ()
7517{
7518 int ret = 0;
7519
7520 switch (DEFAULT_ABI)
7521 {
7522 default:
7523 abort ();
7524
7525 case ABI_AIX:
8f802bfb 7526 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
7527 break;
7528
7529 case ABI_V4:
c81bebd7 7530 case ABI_SOLARIS:
b6c9286a 7531 case ABI_AIX_NODESC:
03a7e1a5 7532 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 7533 break;
b6c9286a
MM
7534 }
7535
7536 return ret;
7537}
7538
7539/* Emit RTL insns to initialize the variable parts of a trampoline.
7540 FNADDR is an RTX for the address of the function's pure code.
7541 CXT is an RTX for the static chain value for the function. */
7542
7543void
7544rs6000_initialize_trampoline (addr, fnaddr, cxt)
7545 rtx addr;
7546 rtx fnaddr;
7547 rtx cxt;
7548{
ac2a93a1 7549 enum machine_mode pmode = Pmode;
8bd04c56
MM
7550 int regsize = (TARGET_32BIT) ? 4 : 8;
7551 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
7552
7553 switch (DEFAULT_ABI)
7554 {
7555 default:
7556 abort ();
7557
8bd04c56 7558/* Macros to shorten the code expansions below. */
39403d82 7559#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
7560#define MEM_PLUS(addr,offset) \
7561 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 7562
b6c9286a
MM
7563 /* Under AIX, just build the 3 word function descriptor */
7564 case ABI_AIX:
8bd04c56
MM
7565 {
7566 rtx fn_reg = gen_reg_rtx (pmode);
7567 rtx toc_reg = gen_reg_rtx (pmode);
7568 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
7569 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
7570 emit_move_insn (MEM_DEREF (addr), fn_reg);
7571 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
7572 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
7573 }
b6c9286a
MM
7574 break;
7575
eaf1bcf1 7576 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
b6c9286a 7577 case ABI_V4:
c81bebd7 7578 case ABI_SOLARIS:
b6c9286a 7579 case ABI_AIX_NODESC:
39403d82 7580 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
7581 FALSE, VOIDmode, 4,
7582 addr, pmode,
7583 GEN_INT (rs6000_trampoline_size ()), SImode,
7584 fnaddr, pmode,
7585 ctx_reg, pmode);
b6c9286a 7586 break;
b6c9286a
MM
7587 }
7588
7589 return;
7590}
7509c759
MM
7591
7592\f
7593/* If defined, a C expression whose value is nonzero if IDENTIFIER
7594 with arguments ARGS is a valid machine specific attribute for DECL.
7595 The attributes in ATTRIBUTES have previously been assigned to DECL. */
7596
7597int
7598rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
296b8152
KG
7599 tree decl ATTRIBUTE_UNUSED;
7600 tree attributes ATTRIBUTE_UNUSED;
7601 tree identifier ATTRIBUTE_UNUSED;
7602 tree args ATTRIBUTE_UNUSED;
7509c759
MM
7603{
7604 return 0;
7605}
7606
7607/* If defined, a C expression whose value is nonzero if IDENTIFIER
7608 with arguments ARGS is a valid machine specific attribute for TYPE.
7609 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
7610
7611int
7612rs6000_valid_type_attribute_p (type, attributes, identifier, args)
7613 tree type;
296b8152 7614 tree attributes ATTRIBUTE_UNUSED;
7509c759
MM
7615 tree identifier;
7616 tree args;
7617{
7618 if (TREE_CODE (type) != FUNCTION_TYPE
7619 && TREE_CODE (type) != FIELD_DECL
7620 && TREE_CODE (type) != TYPE_DECL)
7621 return 0;
7622
6a4cee5f
MM
7623 /* Longcall attribute says that the function is not within 2**26 bytes
7624 of the current function, and to do an indirect call. */
7625 if (is_attribute_p ("longcall", identifier))
7626 return (args == NULL_TREE);
7627
7509c759
MM
7628 return 0;
7629}
7630
7631/* If defined, a C expression whose value is zero if the attributes on
7632 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
7633 two if they are nearly compatible (which causes a warning to be
7634 generated). */
7635
7636int
7637rs6000_comp_type_attributes (type1, type2)
296b8152
KG
7638 tree type1 ATTRIBUTE_UNUSED;
7639 tree type2 ATTRIBUTE_UNUSED;
7509c759
MM
7640{
7641 return 1;
7642}
7643
7644/* If defined, a C statement that assigns default attributes to newly
7645 defined TYPE. */
7646
7647void
7648rs6000_set_default_type_attributes (type)
296b8152 7649 tree type ATTRIBUTE_UNUSED;
7509c759 7650{
3cb999d8 7651 return;
7509c759
MM
7652}
7653
3cb999d8
DE
7654/* Return a reference suitable for calling a function with the
7655 longcall attribute. */
6a4cee5f
MM
7656struct rtx_def *
7657rs6000_longcall_ref (call_ref)
7658 rtx call_ref;
7659{
d330fd93 7660 const char *call_name;
6a4cee5f
MM
7661 tree node;
7662
7663 if (GET_CODE (call_ref) != SYMBOL_REF)
7664 return call_ref;
7665
7666 /* System V adds '.' to the internal name, so skip them. */
7667 call_name = XSTR (call_ref, 0);
7668 if (*call_name == '.')
7669 {
7670 while (*call_name == '.')
7671 call_name++;
7672
7673 node = get_identifier (call_name);
39403d82 7674 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
7675 }
7676
7677 return force_reg (Pmode, call_ref);
7678}
7679
7509c759
MM
7680\f
7681/* A C statement or statements to switch to the appropriate section
7682 for output of RTX in mode MODE. You can assume that RTX is some
7683 kind of constant in RTL. The argument MODE is redundant except in
7684 the case of a `const_int' rtx. Select the section by calling
7685 `text_section' or one of the alternatives for other sections.
7686
7687 Do not define this macro if you put all constants in the read-only
7688 data section. */
7689
7690#ifdef USING_SVR4_H
7691
7692void
7693rs6000_select_rtx_section (mode, x)
a9098fd0 7694 enum machine_mode mode;
7509c759
MM
7695 rtx x;
7696{
a9098fd0 7697 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 7698 toc_section ();
7509c759
MM
7699 else
7700 const_section ();
7701}
7702
7703/* A C statement or statements to switch to the appropriate
7704 section for output of DECL. DECL is either a `VAR_DECL' node
7705 or a constant of some sort. RELOC indicates whether forming
7706 the initial value of DECL requires link-time relocations. */
7707
7708void
7709rs6000_select_section (decl, reloc)
7710 tree decl;
7711 int reloc;
7712{
7713 int size = int_size_in_bytes (TREE_TYPE (decl));
63019373
GK
7714 int needs_sdata;
7715 int readonly;
7716 static void (* const sec_funcs[4]) PARAMS ((void)) = {
7717 &const_section,
7718 &sdata2_section,
7719 &data_section,
7720 &sdata_section
7721 };
7722
7723 needs_sdata = (size > 0
7724 && size <= g_switch_value
7725 && rs6000_sdata != SDATA_NONE
7726 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7509c759
MM
7727
7728 if (TREE_CODE (decl) == STRING_CST)
63019373 7729 readonly = ! flag_writable_strings;
a9098fd0 7730 else if (TREE_CODE (decl) == VAR_DECL)
63019373
GK
7731 readonly = (! (flag_pic && reloc)
7732 && TREE_READONLY (decl)
7733 && ! TREE_SIDE_EFFECTS (decl)
7734 && DECL_INITIAL (decl)
7735 && DECL_INITIAL (decl) != error_mark_node
7736 && TREE_CONSTANT (DECL_INITIAL (decl)));
7509c759 7737 else
63019373
GK
7738 readonly = 1;
7739 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7740 readonly = 0;
7741
7742 (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])();
7743}
7744
7745/* A C statement to build up a unique section name, expressed as a
7746 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
7747 RELOC indicates whether the initial value of EXP requires
7748 link-time relocations. If you do not define this macro, GCC will use
7749 the symbol name prefixed by `.' as the section name. Note - this
7750 macro can now be called for unitialised data items as well as
7751 initialised data and functions. */
7752
7753void
7754rs6000_unique_section (decl, reloc)
7755 tree decl;
7756 int reloc;
7757{
7758 int size = int_size_in_bytes (TREE_TYPE (decl));
7759 int needs_sdata;
7760 int readonly;
7761 int len;
7762 int sec;
7763 const char *name;
7764 char *string;
7765 const char *prefix;
7766
7767 static const char *const prefixes[7][2] =
7768 {
7769 { ".text.", ".gnu.linkonce.t." },
7770 { ".rodata.", ".gnu.linkonce.r." },
7771 { ".sdata2.", ".gnu.linkonce.s2." },
7772 { ".data.", ".gnu.linkonce.d." },
7773 { ".sdata.", ".gnu.linkonce.s." },
7774 { ".bss.", ".gnu.linkonce.b." },
7775 { ".sbss.", ".gnu.linkonce.sb." }
7776 };
7777
7778 needs_sdata = (TREE_CODE (decl) != FUNCTION_DECL
7779 && size > 0
7780 && size <= g_switch_value
7781 && rs6000_sdata != SDATA_NONE
7782 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7783
7784 if (TREE_CODE (decl) == STRING_CST)
7785 readonly = ! flag_writable_strings;
7786 else if (TREE_CODE (decl) == VAR_DECL)
7787 readonly = (! (flag_pic && reloc)
7788 && TREE_READONLY (decl)
7789 && ! TREE_SIDE_EFFECTS (decl)
7790 && DECL_INITIAL (decl)
7791 && DECL_INITIAL (decl) != error_mark_node
7792 && TREE_CONSTANT (DECL_INITIAL (decl)));
7793 else
7794 readonly = 1;
7795 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7796 readonly = 0;
7797
7798 sec = ((TREE_CODE (decl) == FUNCTION_DECL ? 0 : 1)
7799 + (readonly ? 0 : 2)
7800 + (needs_sdata ? 1 : 0)
7801 + (DECL_INITIAL (decl) == 0
7802 || DECL_INITIAL (decl) == error_mark_node) ? 4 : 0);
7803
e6978109 7804 STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
63019373
GK
7805 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
7806 len = strlen (name) + strlen (prefix);
7807 string = alloca (len + 1);
7808
7809 sprintf (string, "%s%s", prefix, name);
7810
7811 DECL_SECTION_NAME (decl) = build_string (len, string);
7509c759 7812}
d9407988
MM
7813
7814\f
d9407988
MM
7815/* If we are referencing a function that is static or is known to be
7816 in this file, make the SYMBOL_REF special. We can use this to indicate
7817 that we can branch to this function without emitting a no-op after the
9ebbca7d 7818 call. For real AIX calling sequences, we also replace the
d9407988
MM
7819 function name with the real name (1 or 2 leading .'s), rather than
7820 the function descriptor name. This saves a lot of overriding code
a260abc9 7821 to read the prefixes. */
d9407988
MM
7822
7823void
7824rs6000_encode_section_info (decl)
7825 tree decl;
7826{
7827 if (TREE_CODE (decl) == FUNCTION_DECL)
7828 {
7829 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
8f1b829e 7830 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
c81fc13e 7831 && ! DECL_WEAK (decl))
d9407988
MM
7832 SYMBOL_REF_FLAG (sym_ref) = 1;
7833
9ebbca7d 7834 if (DEFAULT_ABI == ABI_AIX)
d9407988 7835 {
ff669a6c
RH
7836 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
7837 size_t len2 = strlen (XSTR (sym_ref, 0));
520a57c8 7838 char *str = alloca (len1 + len2 + 1);
ff669a6c
RH
7839 str[0] = '.';
7840 str[1] = '.';
7841 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
7842
520a57c8 7843 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
d9407988
MM
7844 }
7845 }
7846 else if (rs6000_sdata != SDATA_NONE
7847 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7848 && TREE_CODE (decl) == VAR_DECL)
7849 {
7850 int size = int_size_in_bytes (TREE_TYPE (decl));
7851 tree section_name = DECL_SECTION_NAME (decl);
d330fd93 7852 const char *name = (char *)0;
d9407988
MM
7853 int len = 0;
7854
7855 if (section_name)
7856 {
7857 if (TREE_CODE (section_name) == STRING_CST)
7858 {
7859 name = TREE_STRING_POINTER (section_name);
7860 len = TREE_STRING_LENGTH (section_name);
7861 }
7862 else
7863 abort ();
7864 }
7865
7866 if ((size > 0 && size <= g_switch_value)
7867 || (name
5f59ecb7 7868 && ((len == sizeof (".sdata") - 1
3cb999d8 7869 && strcmp (name, ".sdata") == 0)
5f59ecb7 7870 || (len == sizeof (".sdata2") - 1
3cb999d8 7871 && strcmp (name, ".sdata2") == 0)
5f59ecb7 7872 || (len == sizeof (".sbss") - 1
3cb999d8 7873 && strcmp (name, ".sbss") == 0)
5f59ecb7 7874 || (len == sizeof (".sbss2") - 1
3cb999d8 7875 && strcmp (name, ".sbss2") == 0)
5f59ecb7 7876 || (len == sizeof (".PPC.EMB.sdata0") - 1
3cb999d8 7877 && strcmp (name, ".PPC.EMB.sdata0") == 0)
5f59ecb7 7878 || (len == sizeof (".PPC.EMB.sbss0") - 1
3cb999d8 7879 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
d9407988
MM
7880 {
7881 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
ff669a6c 7882 size_t len = strlen (XSTR (sym_ref, 0));
88c1e412 7883 char *str = alloca (len + 2);
ff669a6c 7884
ff669a6c
RH
7885 str[0] = '@';
7886 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
88c1e412 7887 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988
MM
7888 }
7889 }
7890}
7891
7509c759 7892#endif /* USING_SVR4_H */
000034eb 7893
a6c2a102 7894\f
000034eb 7895/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
7896 ADDR can be effectively incremented by incrementing REG.
7897
7898 r0 is special and we must not select it as an address
7899 register by this routine since our caller will try to
7900 increment the returned register via an "la" instruction. */
000034eb
DE
7901
7902struct rtx_def *
7903find_addr_reg (addr)
7904 rtx addr;
7905{
7906 while (GET_CODE (addr) == PLUS)
7907 {
02441cd6
JL
7908 if (GET_CODE (XEXP (addr, 0)) == REG
7909 && REGNO (XEXP (addr, 0)) != 0)
000034eb 7910 addr = XEXP (addr, 0);
02441cd6
JL
7911 else if (GET_CODE (XEXP (addr, 1)) == REG
7912 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
7913 addr = XEXP (addr, 1);
7914 else if (CONSTANT_P (XEXP (addr, 0)))
7915 addr = XEXP (addr, 1);
7916 else if (CONSTANT_P (XEXP (addr, 1)))
7917 addr = XEXP (addr, 0);
7918 else
7919 abort ();
7920 }
02441cd6 7921 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
7922 return addr;
7923 abort ();
7924}
7925
a6c2a102
DE
7926void
7927rs6000_fatal_bad_address (op)
7928 rtx op;
7929{
7930 fatal_insn ("bad address", op);
7931}
c8023011
MM
7932
7933/* Called to register all of our global variables with the garbage
7934 collector. */
7935
7936static void
7937rs6000_add_gc_roots ()
7938{
7939 ggc_add_rtx_root (&rs6000_compare_op0, 1);
7940 ggc_add_rtx_root (&rs6000_compare_op1, 1);
9ebbca7d
GK
7941
7942 toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL);
7943 ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table),
7944 toc_hash_mark_table);
ee890fe2
SS
7945
7946#if TARGET_MACHO
7947 machopic_add_gc_roots ();
7948#endif
7949}
7950
7951#if TARGET_MACHO
7952
7953#if 0
7954/* Returns 1 if OP is either a symbol reference or a sum of a symbol
7955 reference and a constant. */
7956
7957int
7958symbolic_operand (op)
7959 register rtx op;
7960{
7961 switch (GET_CODE (op))
7962 {
7963 case SYMBOL_REF:
7964 case LABEL_REF:
7965 return 1;
7966 case CONST:
7967 op = XEXP (op, 0);
7968 return (GET_CODE (op) == SYMBOL_REF ||
7969 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
7970 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
7971 && GET_CODE (XEXP (op, 1)) == CONST_INT);
7972 default:
7973 return 0;
7974 }
c8023011 7975}
ee890fe2
SS
7976#endif
7977
7978#ifdef RS6000_LONG_BRANCH
7979
7980static tree stub_list = 0;
7981
7982/* ADD_COMPILER_STUB adds the compiler generated stub for handling
7983 procedure calls to the linked list. */
7984
7985void
7986add_compiler_stub (label_name, function_name, line_number)
7987 tree label_name;
7988 tree function_name;
7989 int line_number;
7990{
7991 tree stub = build_tree_list (function_name, label_name);
7992 TREE_TYPE (stub) = build_int_2 (line_number, 0);
7993 TREE_CHAIN (stub) = stub_list;
7994 stub_list = stub;
7995}
7996
7997#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
7998#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
7999#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
8000
8001/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for handling
8002 procedure calls from the linked list and initializes the linked list. */
8003
8004void output_compiler_stub ()
8005{
8006 char tmp_buf[256];
8007 char label_buf[256];
8008 char *label;
8009 tree tmp_stub, stub;
8010
8011 if (!flag_pic)
8012 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8013 {
8014 fprintf (asm_out_file,
8015 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
8016
8017#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
8018 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
8019 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
8020#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
8021
8022 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
8023 strcpy (label_buf,
8024 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
8025 else
8026 {
8027 label_buf[0] = '_';
8028 strcpy (label_buf+1,
8029 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
8030 }
8031
8032 strcpy (tmp_buf, "lis r12,hi16(");
8033 strcat (tmp_buf, label_buf);
8034 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
8035 strcat (tmp_buf, label_buf);
8036 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
8037 output_asm_insn (tmp_buf, 0);
8038
8039#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
8040 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
8041 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
8042#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
8043 }
8044
8045 stub_list = 0;
8046}
8047
8048/* NO_PREVIOUS_DEF checks in the link list whether the function name is
8049 already there or not. */
8050
8051int no_previous_def (function_name)
8052 tree function_name;
8053{
8054 tree stub;
8055 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8056 if (function_name == STUB_FUNCTION_NAME (stub))
8057 return 0;
8058 return 1;
8059}
8060
8061/* GET_PREV_LABEL gets the label name from the previous definition of
8062 the function. */
8063
8064tree get_prev_label (function_name)
8065 tree function_name;
8066{
8067 tree stub;
8068 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8069 if (function_name == STUB_FUNCTION_NAME (stub))
8070 return STUB_LABEL_NAME (stub);
8071 return 0;
8072}
8073
8074/* INSN is either a function call or a millicode call. It may have an
8075 unconditional jump in its delay slot.
8076
8077 CALL_DEST is the routine we are calling. */
8078
8079char *
8080output_call (insn, call_dest, operand_number)
8081 rtx insn;
8082 rtx call_dest;
8083 int operand_number;
8084{
8085 static char buf[256];
8086 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
8087 {
8088 tree labelname;
8089 tree funname = get_identifier (XSTR (call_dest, 0));
8090
8091 if (no_previous_def (funname))
8092 {
8093 int line_number;
8094 rtx label_rtx = gen_label_rtx ();
8095 char *label_buf, temp_buf[256];
8096 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
8097 CODE_LABEL_NUMBER (label_rtx));
8098 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
8099 labelname = get_identifier (label_buf);
8100 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
8101 if (insn)
8102 line_number = NOTE_LINE_NUMBER (insn);
8103 add_compiler_stub (labelname, funname, line_number);
8104 }
8105 else
8106 labelname = get_prev_label (funname);
8107
8108 sprintf (buf, "jbsr %%z%d,%.246s",
8109 operand_number, IDENTIFIER_POINTER (labelname));
8110 return buf;
8111 }
8112 else
8113 {
8114 sprintf (buf, "bl %%z%d", operand_number);
8115 return buf;
8116 }
8117}
8118
8119#endif /* RS6000_LONG_BRANCH */
8120
8121#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
8122 do { \
8123 const char *symbol_ = (SYMBOL); \
8124 char *buffer_ = (BUF); \
8125 if (symbol_[0] == '"') \
8126 { \
8127 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
8128 } \
8129 else if (name_needs_quotes(symbol_)) \
8130 { \
8131 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
8132 } \
8133 else \
8134 { \
8135 sprintf(buffer_, "L%d$%s", (N), symbol_); \
8136 } \
8137 } while (0)
8138
8139
8140/* Generate PIC and indirect symbol stubs. */
8141
8142void
8143machopic_output_stub (file, symb, stub)
8144 FILE *file;
8145 const char *symb, *stub;
8146{
8147 unsigned int length;
8148 char *binder_name, *symbol_name, *lazy_ptr_name;
8149 char *local_label_0, *local_label_1, *local_label_2;
8150 static int label = 0;
8151
8152 label += 1;
8153
8154 length = strlen (stub);
8155 binder_name = alloca (length + 32);
8156 GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
8157
8158 length = strlen (symb);
8159 symbol_name = alloca (length + 32);
8160 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
8161
8162 lazy_ptr_name = alloca (length + 32);
8163 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
8164
8165 local_label_0 = alloca (length + 32);
8166 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
8167
8168 local_label_1 = alloca (length + 32);
8169 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_1, symb, length, 1);
8170
8171 local_label_2 = alloca (length + 32);
8172 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_2, symb, length, 2);
8173
8174 if (flag_pic == 2)
8175 machopic_picsymbol_stub_section ();
8176 else
8177 machopic_symbol_stub_section ();
8178
8179 fprintf (file, "%s:\n", stub);
8180 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
8181
8182 if (flag_pic == 2)
8183 {
8184 fprintf (file, "\tmflr r0\n");
8185 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
8186 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
8187 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
8188 lazy_ptr_name, local_label_0);
8189 fprintf (file, "\tmtlr r0\n");
8190 fprintf (file, "\tlwz r12,lo16(%s-%s)(r11)\n",
8191 lazy_ptr_name, local_label_0);
8192 fprintf (file, "\tmtctr r12\n");
8193 fprintf (file, "\taddi r11,r11,lo16(%s-%s)\n",
8194 lazy_ptr_name, local_label_0);
8195 fprintf (file, "\tbctr\n");
8196 }
8197 else
8198 fprintf (file, "non-pure not supported\n");
8199
8200 machopic_lazy_symbol_ptr_section ();
8201 fprintf (file, "%s:\n", lazy_ptr_name);
8202 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
8203 fprintf (file, "\t.long dyld_stub_binding_helper\n");
8204}
8205
8206/* Legitimize PIC addresses. If the address is already
8207 position-independent, we return ORIG. Newly generated
8208 position-independent addresses go into a reg. This is REG if non
8209 zero, otherwise we allocate register(s) as necessary. */
8210
8211#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x4000) < 0x8000)
8212
8213rtx
8214rs6000_machopic_legitimize_pic_address (orig, mode, reg)
8215 rtx orig;
8216 enum machine_mode mode;
8217 rtx reg;
8218{
8219 rtx base, offset;
8220
8221 if (reg == NULL && ! reload_in_progress && ! reload_completed)
8222 reg = gen_reg_rtx (Pmode);
8223
8224 if (GET_CODE (orig) == CONST)
8225 {
8226 if (GET_CODE (XEXP (orig, 0)) == PLUS
8227 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
8228 return orig;
8229
8230 if (GET_CODE (XEXP (orig, 0)) == PLUS)
8231 {
8232 base = rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
8233 Pmode, reg);
8234 offset = rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
8235 Pmode, reg);
8236 }
8237 else
8238 abort ();
8239
8240 if (GET_CODE (offset) == CONST_INT)
8241 {
8242 if (SMALL_INT (offset))
8243 return plus_constant_for_output (base, INTVAL (offset));
8244 else if (! reload_in_progress && ! reload_completed)
8245 offset = force_reg (Pmode, offset);
8246 else
8247 abort ();
8248 }
8249 return gen_rtx (PLUS, Pmode, base, offset);
8250 }
8251
8252 /* Fall back on generic machopic code. */
8253 return machopic_legitimize_pic_address (orig, mode, reg);
8254}
8255
8256/* This is just a placeholder to make linking work without having to
8257 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
8258 ever needed for Darwin (not too likely!) this would have to get a
8259 real definition. */
8260
8261void
8262toc_section ()
8263{
8264}
8265
8266#endif /* TARGET_MACHO */