]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* pt.c (process_template_parm): Undo previous change.
[thirdparty/gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
a260abc9 2 Copyright (C) 1991, 93-7, 1998 Free Software Foundation, Inc.
fab3bcc3 3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c
RK
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
c15c9075
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
9878760c 21
956d6950 22#include "config.h"
c4d38ccb 23#include "system.h"
9878760c
RK
24#include "rtl.h"
25#include "regs.h"
26#include "hard-reg-set.h"
27#include "real.h"
28#include "insn-config.h"
29#include "conditions.h"
30#include "insn-flags.h"
9878760c
RK
31#include "insn-attr.h"
32#include "flags.h"
33#include "recog.h"
34#include "expr.h"
35#include "obstack.h"
9b30bae2 36#include "tree.h"
2a430ec1 37#include "except.h"
a7df97e6 38#include "function.h"
296b8152
KG
39#include "output.h"
40#include "toplev.h"
9b30bae2 41
7509c759
MM
42#ifndef TARGET_NO_PROTOTYPE
43#define TARGET_NO_PROTOTYPE 0
44#endif
45
9b30bae2 46extern char *language_string;
5248c961 47extern int profile_block_flag;
9878760c
RK
48
49#define min(A,B) ((A) < (B) ? (A) : (B))
50#define max(A,B) ((A) > (B) ? (A) : (B))
51
5248c961
RK
52/* Target cpu type */
53
54enum processor_type rs6000_cpu;
8e3f41e7
MM
55struct rs6000_cpu_select rs6000_select[3] =
56{
57 /* switch name, tune arch */
5d6426e0 58 { (char *)0, "--with-cpu=", 1, 1 },
8e3f41e7
MM
59 { (char *)0, "-mcpu=", 1, 1 },
60 { (char *)0, "-mtune=", 1, 0 },
61};
5248c961 62
9878760c
RK
63/* Set to non-zero by "fix" operation to indicate that itrunc and
64 uitrunc must be defined. */
65
66int rs6000_trunc_used;
67
68/* Set to non-zero once they have been defined. */
69
70static int trunc_defined;
71
c764f757
RK
72/* Set to non-zero once AIX common-mode calls have been defined. */
73static int common_mode_defined;
c81bebd7 74
9878760c
RK
75/* Save information from a "cmpxx" operation until the branch or scc is
76 emitted. */
9878760c
RK
77rtx rs6000_compare_op0, rs6000_compare_op1;
78int rs6000_compare_fp_p;
874a0744
MM
79
80#ifdef USING_SVR4_H
81/* Label number of label created for -mrelocatable, to call to so we can
82 get the address of the GOT section */
83int rs6000_pic_labelno;
ab9eef41 84int rs6000_pic_func_labelno;
c81bebd7
MM
85
86/* Which abi to adhere to */
87char *rs6000_abi_name = RS6000_ABI_NAME;
d9407988
MM
88
89/* Semantics of the small data area */
90enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
91
92/* Which small data model to use */
93char *rs6000_sdata_name = (char *)0;
874a0744 94#endif
4697a36c
MM
95
96/* Whether a System V.4 varargs area was created. */
97int rs6000_sysv_varargs_p;
8f75773e 98
b6c9286a
MM
99/* ABI enumeration available for subtarget to use. */
100enum rs6000_abi rs6000_current_abi;
101
802a0058
MM
102/* Offset & size for fpmem stack locations used for converting between
103 float and integral types. */
104int rs6000_fpmem_offset;
105int rs6000_fpmem_size;
106
38c1f2d7
MM
107/* Debug flags */
108char *rs6000_debug_name;
109int rs6000_debug_stack; /* debug stack applications */
110int rs6000_debug_arg; /* debug argument handling */
111
112/* Flag to say the TOC is initialized */
113int toc_initialized;
114
c81bebd7
MM
115\f
116/* Default register names. */
117char rs6000_reg_names[][8] =
118{
802a0058
MM
119 "0", "1", "2", "3", "4", "5", "6", "7",
120 "8", "9", "10", "11", "12", "13", "14", "15",
121 "16", "17", "18", "19", "20", "21", "22", "23",
122 "24", "25", "26", "27", "28", "29", "30", "31",
123 "0", "1", "2", "3", "4", "5", "6", "7",
124 "8", "9", "10", "11", "12", "13", "14", "15",
125 "16", "17", "18", "19", "20", "21", "22", "23",
126 "24", "25", "26", "27", "28", "29", "30", "31",
127 "mq", "lr", "ctr","ap",
128 "0", "1", "2", "3", "4", "5", "6", "7",
129 "fpmem"
c81bebd7
MM
130};
131
132#ifdef TARGET_REGNAMES
133static char alt_reg_names[][8] =
134{
802a0058
MM
135 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
136 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
137 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
138 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
139 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
140 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
141 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
142 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
143 "mq", "lr", "ctr", "ap",
144 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
145 "fpmem"
c81bebd7
MM
146};
147#endif
9878760c 148\f
daf11973
MM
149#ifndef MASK_STRICT_ALIGN
150#define MASK_STRICT_ALIGN 0
151#endif
152
5248c961
RK
153/* Override command line options. Mostly we process the processor
154 type and sometimes adjust other TARGET_ options. */
155
156void
8e3f41e7
MM
157rs6000_override_options (default_cpu)
158 char *default_cpu;
5248c961 159{
c4d38ccb 160 size_t i, j;
8e3f41e7 161 struct rs6000_cpu_select *ptr;
5248c961 162
85638c0d
RK
163 /* Simplify the entries below by making a mask for any POWER
164 variant and any PowerPC variant. */
165
938937d8 166#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
167#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
168 | MASK_PPC_GFXOPT | MASK_POWERPC64)
169#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 170
5248c961
RK
171 static struct ptt
172 {
173 char *name; /* Canonical processor name. */
174 enum processor_type processor; /* Processor type enum value. */
175 int target_enable; /* Target flags to enable. */
176 int target_disable; /* Target flags to disable. */
177 } processor_target_table[]
cf27b467
MM
178 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
179 POWER_MASKS | POWERPC_MASKS},
db7f1e43 180 {"power", PROCESSOR_POWER,
938937d8 181 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 182 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
183 {"power2", PROCESSOR_POWER,
184 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
185 POWERPC_MASKS | MASK_NEW_MNEMONICS},
db7f1e43
RK
186 {"powerpc", PROCESSOR_POWERPC,
187 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 188 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
db7f1e43 189 {"rios", PROCESSOR_RIOS1,
938937d8 190 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
191 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
192 {"rios1", PROCESSOR_RIOS1,
938937d8 193 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
194 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
195 {"rsc", PROCESSOR_PPC601,
938937d8 196 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
197 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
198 {"rsc1", PROCESSOR_PPC601,
938937d8 199 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
200 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
201 {"rios2", PROCESSOR_RIOS2,
938937d8 202 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 203 POWERPC_MASKS | MASK_NEW_MNEMONICS},
49a0b204 204 {"403", PROCESSOR_PPC403,
daf11973 205 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 206 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
207 {"505", PROCESSOR_MPCCORE,
208 MASK_POWERPC | MASK_NEW_MNEMONICS,
209 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 210 {"601", PROCESSOR_PPC601,
938937d8 211 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 212 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 213 {"602", PROCESSOR_PPC603,
cf27b467
MM
214 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
215 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 216 {"603", PROCESSOR_PPC603,
68c49ffa
RK
217 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
218 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
219 {"603e", PROCESSOR_PPC603,
220 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
221 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 222 {"604", PROCESSOR_PPC604,
b6c9286a
MM
223 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
224 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
225 {"604e", PROCESSOR_PPC604,
226 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
227 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 228 {"620", PROCESSOR_PPC620,
68c49ffa 229 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a260abc9 230 POWER_MASKS | MASK_PPC_GPOPT},
07e6159a
MM
231 {"801", PROCESSOR_MPCCORE,
232 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
233 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
234 {"821", PROCESSOR_MPCCORE,
235 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
236 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
237 {"823", PROCESSOR_MPCCORE,
238 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
239 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
240 {"860", PROCESSOR_MPCCORE,
241 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
242 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 243
c4d38ccb 244 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
5248c961 245
8a61d227 246 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
938937d8 247 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
8a61d227 248
5248c961
RK
249 profile_block_flag = 0;
250
251 /* Identify the processor type */
8e3f41e7
MM
252 rs6000_select[0].string = default_cpu;
253 rs6000_cpu = PROCESSOR_DEFAULT;
8e3f41e7
MM
254
255 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
5248c961 256 {
8e3f41e7
MM
257 ptr = &rs6000_select[i];
258 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 259 {
8e3f41e7
MM
260 for (j = 0; j < ptt_size; j++)
261 if (! strcmp (ptr->string, processor_target_table[j].name))
262 {
263 if (ptr->set_tune_p)
264 rs6000_cpu = processor_target_table[j].processor;
265
266 if (ptr->set_arch_p)
267 {
268 target_flags |= processor_target_table[j].target_enable;
269 target_flags &= ~processor_target_table[j].target_disable;
270 }
271 break;
272 }
273
274 if (i == ptt_size)
275 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
276 }
277 }
8a61d227 278
ef792183
MM
279 /* If we are optimizing big endian systems for space, use the
280 store multiple instructions. */
281 if (BYTES_BIG_ENDIAN && optimize_size)
282 target_flags |= MASK_MULTIPLE;
283
8a61d227
MM
284 /* If -mmultiple or -mno-multiple was explicitly used, don't
285 override with the processor default */
286 if (TARGET_MULTIPLE_SET)
287 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 288
938937d8
MM
289 /* If -mstring or -mno-string was explicitly used, don't
290 override with the processor default */
291 if (TARGET_STRING_SET)
1f5515bf 292 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 293
7e69e155
MM
294 /* Don't allow -mmultiple or -mstring on little endian systems, because the
295 hardware doesn't support the instructions used in little endian mode */
296 if (!BYTES_BIG_ENDIAN)
297 {
298 if (TARGET_MULTIPLE)
299 {
300 target_flags &= ~MASK_MULTIPLE;
301 if (TARGET_MULTIPLE_SET)
302 warning ("-mmultiple is not supported on little endian systems");
303 }
304
305 if (TARGET_STRING)
306 {
307 target_flags &= ~MASK_STRING;
938937d8
MM
308 if (TARGET_STRING_SET)
309 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
310 }
311 }
3933e0e1 312
a260abc9
DE
313 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
314 {
315 warning ("-f%s ignored for AIX (all code is position independent)",
316 (flag_pic > 1) ? "PIC" : "pic");
317 flag_pic = 0;
318 }
319
38c1f2d7
MM
320 /* Set debug flags */
321 if (rs6000_debug_name)
322 {
323 if (!strcmp (rs6000_debug_name, "all"))
324 rs6000_debug_stack = rs6000_debug_arg = 1;
325 else if (!strcmp (rs6000_debug_name, "stack"))
326 rs6000_debug_stack = 1;
327 else if (!strcmp (rs6000_debug_name, "arg"))
328 rs6000_debug_arg = 1;
329 else
330 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
331 }
332
c81bebd7
MM
333#ifdef TARGET_REGNAMES
334 /* If the user desires alternate register names, copy in the alternate names
335 now. */
336 if (TARGET_REGNAMES)
337 bcopy ((char *)alt_reg_names, (char *)rs6000_reg_names, sizeof (rs6000_reg_names));
338#endif
339
3933e0e1
MM
340#ifdef SUBTARGET_OVERRIDE_OPTIONS
341 SUBTARGET_OVERRIDE_OPTIONS;
342#endif
5248c961 343}
3cfa4909
MM
344\f
345/* Do anything needed at the start of the asm file. */
346
347void
348rs6000_file_start (file, default_cpu)
349 FILE *file;
350 char *default_cpu;
351{
c4d38ccb 352 size_t i;
3cfa4909
MM
353 char buffer[80];
354 char *start = buffer;
355 struct rs6000_cpu_select *ptr;
356
357 if (flag_verbose_asm)
358 {
359 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
360 rs6000_select[0].string = default_cpu;
361
362 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
363 {
364 ptr = &rs6000_select[i];
365 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
366 {
367 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
368 start = "";
369 }
370 }
371
372#ifdef USING_SVR4_H
373 switch (rs6000_sdata)
374 {
375 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
376 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
377 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
378 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
379 }
380
381 if (rs6000_sdata && g_switch_value)
382 {
383 fprintf (file, "%s -G %d", start, g_switch_value);
384 start = "";
385 }
386#endif
387
388 if (*start == '\0')
389 fputs ("\n", file);
390 }
391}
392
24d304eb
RK
393\f
394/* Create a CONST_DOUBLE from a string. */
395
396struct rtx_def *
397rs6000_float_const (string, mode)
398 char *string;
399 enum machine_mode mode;
400{
401 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
402 return immed_real_const_1 (value, mode);
403}
5248c961 404\f
9878760c
RK
405/* Return non-zero if this function is known to have a null epilogue. */
406
407int
408direct_return ()
409{
4697a36c
MM
410 if (reload_completed)
411 {
412 rs6000_stack_t *info = rs6000_stack_info ();
413
414 if (info->first_gp_reg_save == 32
415 && info->first_fp_reg_save == 64
416 && !info->lr_save_p
1b4a2731 417 && !info->cr_save_p
4697a36c
MM
418 && !info->push_p)
419 return 1;
420 }
421
422 return 0;
9878760c
RK
423}
424
425/* Returns 1 always. */
426
427int
428any_operand (op, mode)
296b8152
KG
429 register rtx op ATTRIBUTE_UNUSED;
430 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
431{
432 return 1;
433}
434
b6c9286a 435/* Returns 1 if op is the count register */
38c1f2d7
MM
436int
437count_register_operand(op, mode)
b6c9286a 438 register rtx op;
296b8152 439 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
440{
441 if (GET_CODE (op) != REG)
442 return 0;
443
444 if (REGNO (op) == COUNT_REGISTER_REGNUM)
445 return 1;
446
447 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
448 return 1;
449
450 return 0;
451}
452
802a0058
MM
453/* Returns 1 if op is memory location for float/int conversions that masquerades
454 as a register. */
38c1f2d7
MM
455int
456fpmem_operand(op, mode)
802a0058 457 register rtx op;
296b8152 458 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
459{
460 if (GET_CODE (op) != REG)
461 return 0;
462
463 if (FPMEM_REGNO_P (REGNO (op)))
464 return 1;
465
466#if 0
467 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
468 return 1;
469#endif
470
471 return 0;
472}
473
9878760c
RK
474/* Return 1 if OP is a constant that can fit in a D field. */
475
476int
477short_cint_operand (op, mode)
478 register rtx op;
296b8152 479 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 480{
e675f625
DE
481 return ((GET_CODE (op) == CONST_INT
482 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000)
483 || GET_CODE (op) == CONSTANT_P_RTX);
9878760c
RK
484}
485
486/* Similar for a unsigned D field. */
487
488int
489u_short_cint_operand (op, mode)
490 register rtx op;
296b8152 491 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 492{
e675f625
DE
493 return ((GET_CODE (op) == CONST_INT
494 && (INTVAL (op) & (~ (HOST_WIDE_INT) 0xffff)) == 0)
495 || GET_CODE (op) == CONSTANT_P_RTX);
9878760c
RK
496}
497
dcfedcd0
RK
498/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
499
500int
501non_short_cint_operand (op, mode)
502 register rtx op;
296b8152 503 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
504{
505 return (GET_CODE (op) == CONST_INT
a7653a2c 506 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
507}
508
9878760c
RK
509/* Returns 1 if OP is a register that is not special (i.e., not MQ,
510 ctr, or lr). */
511
512int
cd2b37d9 513gpc_reg_operand (op, mode)
9878760c
RK
514 register rtx op;
515 enum machine_mode mode;
516{
517 return (register_operand (op, mode)
802a0058
MM
518 && (GET_CODE (op) != REG
519 || (REGNO (op) >= 67 && !FPMEM_REGNO_P (REGNO (op)))
520 || REGNO (op) < 64));
9878760c
RK
521}
522
523/* Returns 1 if OP is either a pseudo-register or a register denoting a
524 CR field. */
525
526int
527cc_reg_operand (op, mode)
528 register rtx op;
529 enum machine_mode mode;
530{
531 return (register_operand (op, mode)
532 && (GET_CODE (op) != REG
533 || REGNO (op) >= FIRST_PSEUDO_REGISTER
534 || CR_REGNO_P (REGNO (op))));
535}
536
537/* Returns 1 if OP is either a constant integer valid for a D-field or a
538 non-special register. If a register, it must be in the proper mode unless
539 MODE is VOIDmode. */
540
541int
542reg_or_short_operand (op, mode)
543 register rtx op;
544 enum machine_mode mode;
545{
f5a28898 546 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
547}
548
549/* Similar, except check if the negation of the constant would be valid for
550 a D-field. */
551
552int
553reg_or_neg_short_operand (op, mode)
554 register rtx op;
555 enum machine_mode mode;
556{
557 if (GET_CODE (op) == CONST_INT)
558 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
559
cd2b37d9 560 return gpc_reg_operand (op, mode);
9878760c
RK
561}
562
563/* Return 1 if the operand is either a register or an integer whose high-order
564 16 bits are zero. */
565
566int
567reg_or_u_short_operand (op, mode)
568 register rtx op;
569 enum machine_mode mode;
570{
e675f625 571 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
572}
573
574/* Return 1 is the operand is either a non-special register or ANY
575 constant integer. */
576
577int
578reg_or_cint_operand (op, mode)
579 register rtx op;
580 enum machine_mode mode;
581{
e675f625
DE
582 return (GET_CODE (op) == CONST_INT
583 || GET_CODE (op) == CONSTANT_P_RTX
584 || gpc_reg_operand (op, mode));
9878760c
RK
585}
586
766a866c
MM
587/* Return 1 if the operand is an operand that can be loaded via the GOT */
588
589int
590got_operand (op, mode)
591 register rtx op;
296b8152 592 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
593{
594 return (GET_CODE (op) == SYMBOL_REF
595 || GET_CODE (op) == CONST
596 || GET_CODE (op) == LABEL_REF);
597}
598
38c1f2d7
MM
599/* Return 1 if the operand is a simple references that can be loaded via
600 the GOT (labels involving addition aren't allowed). */
601
602int
603got_no_const_operand (op, mode)
604 register rtx op;
296b8152 605 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
606{
607 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
608}
609
4e74d8ec
MM
610/* Return the number of instructions it takes to form a constant in an
611 integer register. */
612
613static int
614num_insns_constant_wide (value)
615 HOST_WIDE_INT value;
616{
617 /* signed constant loadable with {cal|addi} */
618 if (((unsigned HOST_WIDE_INT)value + 0x8000) < 0x10000)
619 return 1;
620
621#if HOST_BITS_PER_WIDE_INT == 32
622 /* constant loadable with {cau|addis} */
623 else if ((value & 0xffff) == 0)
624 return 1;
625
626#else
627 /* constant loadable with {cau|addis} */
628 else if ((value & 0xffff) == 0 && (value & ~0xffffffff) == 0)
629 return 1;
630
631 else if (TARGET_64BIT)
632 {
633 HOST_WIDE_INT low = value & 0xffffffff;
634 HOST_WIDE_INT high = value >> 32;
635
636 if (high == 0 && (low & 0x80000000) == 0)
637 return 2;
638
639 else if (high == 0xffffffff && (low & 0x80000000) != 0)
640 return 2;
641
642 else if (!low)
643 return num_insns_constant_wide (high) + 1;
644
645 else
646 return (num_insns_constant_wide (high)
e396202a 647 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
648 }
649#endif
650
651 else
652 return 2;
653}
654
655int
656num_insns_constant (op, mode)
657 rtx op;
658 enum machine_mode mode;
659{
4e74d8ec
MM
660 if (GET_CODE (op) == CONST_INT)
661 return num_insns_constant_wide (INTVAL (op));
662
6fc48950
MM
663 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
664 {
665 long l;
666 REAL_VALUE_TYPE rv;
667
668 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
669 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
670 return num_insns_constant_wide ((HOST_WIDE_INT)l);
671 }
672
47ad8c61 673 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 674 {
47ad8c61
MM
675 HOST_WIDE_INT low;
676 HOST_WIDE_INT high;
677 long l[2];
678 REAL_VALUE_TYPE rv;
679 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 680
47ad8c61
MM
681 if (mode == VOIDmode || mode == DImode)
682 {
683 high = CONST_DOUBLE_HIGH (op);
684 low = CONST_DOUBLE_LOW (op);
685 }
686 else
687 {
688 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
689 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
690 high = l[endian];
691 low = l[1 - endian];
692 }
4e74d8ec 693
47ad8c61
MM
694 if (TARGET_32BIT)
695 return (num_insns_constant_wide (low)
696 + num_insns_constant_wide (high));
4e74d8ec
MM
697
698 else
47ad8c61
MM
699 {
700 if (high == 0 && (low & 0x80000000) == 0)
701 return num_insns_constant_wide (low);
702
703 else if (((high & 0xffffffff) == 0xffffffff)
704 && ((low & 0x80000000) != 0))
705 return num_insns_constant_wide (low);
706
a260abc9
DE
707 else if (mask64_operand (op, mode))
708 return 2;
709
47ad8c61
MM
710 else if (low == 0)
711 return num_insns_constant_wide (high) + 1;
712
713 else
714 return (num_insns_constant_wide (high)
715 + num_insns_constant_wide (low) + 1);
716 }
4e74d8ec
MM
717 }
718
719 else
720 abort ();
721}
722
6f2f8311
RK
723/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
724 with one instruction per word. We only do this if we can safely read
725 CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
726
727int
728easy_fp_constant (op, mode)
729 register rtx op;
730 register enum machine_mode mode;
731{
9878760c
RK
732 if (GET_CODE (op) != CONST_DOUBLE
733 || GET_MODE (op) != mode
4e74d8ec 734 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
735 return 0;
736
b6c9286a 737 /* Consider all constants with -msoft-float to be easy */
4e74d8ec 738 if (TARGET_SOFT_FLOAT && mode != DImode)
b6c9286a
MM
739 return 1;
740
a7273471
MM
741 /* If we are using V.4 style PIC, consider all constants to be hard */
742 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
743 return 0;
744
5ae4759c
MM
745#ifdef TARGET_RELOCATABLE
746 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
747 if (TARGET_RELOCATABLE)
748 return 0;
749#endif
750
042259f2
DE
751 if (mode == DFmode)
752 {
753 long k[2];
754 REAL_VALUE_TYPE rv;
755
756 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
757 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 758
4e74d8ec
MM
759 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
760 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
042259f2 761 }
4e74d8ec
MM
762
763 else if (mode == SFmode)
042259f2
DE
764 {
765 long l;
766 REAL_VALUE_TYPE rv;
767
768 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
769 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 770
4e74d8ec 771 return num_insns_constant_wide (l) == 1;
042259f2 772 }
4e74d8ec 773
a260abc9
DE
774 else if (mode == DImode)
775 return ((TARGET_64BIT
776 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
777 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec
MM
778
779 else
780 abort ();
9878760c 781}
8f75773e 782
b6c9286a
MM
783/* Return 1 if the operand is in volatile memory. Note that during the
784 RTL generation phase, memory_operand does not return TRUE for
785 volatile memory references. So this function allows us to
786 recognize volatile references where its safe. */
787
788int
789volatile_mem_operand (op, mode)
790 register rtx op;
791 enum machine_mode mode;
792{
793 if (GET_CODE (op) != MEM)
794 return 0;
795
796 if (!MEM_VOLATILE_P (op))
797 return 0;
798
799 if (mode != GET_MODE (op))
800 return 0;
801
802 if (reload_completed)
803 return memory_operand (op, mode);
804
805 if (reload_in_progress)
806 return strict_memory_address_p (mode, XEXP (op, 0));
807
808 return memory_address_p (mode, XEXP (op, 0));
809}
810
5b5040b9 811/* Return 1 if the operand is an offsettable memory address. */
914c2e77
RK
812
813int
5b5040b9 814offsettable_addr_operand (op, mode)
914c2e77
RK
815 register rtx op;
816 enum machine_mode mode;
817{
8f75773e 818 return offsettable_address_p (reload_completed | reload_in_progress,
5b5040b9 819 mode, op);
914c2e77
RK
820}
821
9878760c
RK
822/* Return 1 if the operand is either an easy FP constant (see above) or
823 memory. */
824
825int
826mem_or_easy_const_operand (op, mode)
827 register rtx op;
828 enum machine_mode mode;
829{
830 return memory_operand (op, mode) || easy_fp_constant (op, mode);
831}
832
833/* Return 1 if the operand is either a non-special register or an item
834 that can be used as the operand of an SI add insn. */
835
836int
837add_operand (op, mode)
838 register rtx op;
839 enum machine_mode mode;
840{
841 return (reg_or_short_operand (op, mode)
842 || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
843}
844
dcfedcd0
RK
845/* Return 1 if OP is a constant but not a valid add_operand. */
846
847int
848non_add_cint_operand (op, mode)
849 register rtx op;
296b8152 850 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
851{
852 return (GET_CODE (op) == CONST_INT
a7653a2c 853 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
dcfedcd0
RK
854 && (INTVAL (op) & 0xffff) != 0);
855}
856
9878760c
RK
857/* Return 1 if the operand is a non-special register or a constant that
858 can be used as the operand of an OR or XOR insn on the RS/6000. */
859
860int
861logical_operand (op, mode)
862 register rtx op;
863 enum machine_mode mode;
864{
cd2b37d9 865 return (gpc_reg_operand (op, mode)
9878760c 866 || (GET_CODE (op) == CONST_INT
a260abc9 867 && ((INTVAL (op) & (~ (HOST_WIDE_INT) 0xffff)) == 0
e675f625
DE
868 || (INTVAL (op) & 0xffff) == 0))
869 || GET_CODE (op) == CONSTANT_P_RTX);
9878760c
RK
870}
871
dcfedcd0
RK
872/* Return 1 if C is a constant that is not a logical operand (as
873 above). */
874
875int
876non_logical_cint_operand (op, mode)
877 register rtx op;
296b8152 878 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
879{
880 return (GET_CODE (op) == CONST_INT
a260abc9 881 && (INTVAL (op) & (~ (HOST_WIDE_INT) 0xffff)) != 0
dcfedcd0
RK
882 && (INTVAL (op) & 0xffff) != 0);
883}
884
9878760c
RK
885/* Return 1 if C is a constant that can be encoded in a mask on the
886 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
887 Reject all ones and all zeros, since these should have been optimized
888 away and confuse the making of MB and ME. */
889
890int
891mask_constant (c)
a260abc9 892 register HOST_WIDE_INT c;
9878760c
RK
893{
894 int i;
895 int last_bit_value;
896 int transitions = 0;
897
898 if (c == 0 || c == ~0)
899 return 0;
900
901 last_bit_value = c & 1;
902
903 for (i = 1; i < 32; i++)
904 if (((c >>= 1) & 1) != last_bit_value)
905 last_bit_value ^= 1, transitions++;
906
907 return transitions <= 2;
908}
909
910/* Return 1 if the operand is a constant that is a mask on the RS/6000. */
911
912int
913mask_operand (op, mode)
914 register rtx op;
296b8152 915 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
916{
917 return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
918}
919
a260abc9
DE
920/* Return 1 if the operand is a constant that is a PowerPC64 mask.
921 It is if there are no more than one 1->0 or 0->1 transitions.
922 Reject all ones and all zeros, since these should have been optimized
923 away and confuse the making of MB and ME. */
9878760c
RK
924
925int
a260abc9
DE
926mask64_operand (op, mode)
927 register rtx op;
928 enum machine_mode mode;
929{
930 if (GET_CODE (op) == CONST_INT)
931 {
932 HOST_WIDE_INT c = INTVAL (op);
933 int i;
934 int last_bit_value;
935 int transitions = 0;
936
937 if (c == 0 || c == ~0)
938 return 0;
939
940 last_bit_value = c & 1;
941
942 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
943 if (((c >>= 1) & 1) != last_bit_value)
944 last_bit_value ^= 1, transitions++;
945
a238cd8b 946#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
947 /* Consider CONST_INT sign-extended. */
948 transitions += (last_bit_value != 1);
949#endif
950
951 return transitions <= 1;
952 }
953 else if (GET_CODE (op) == CONST_DOUBLE
954 && (mode == VOIDmode || mode == DImode))
955 {
956 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
a238cd8b 957#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
958 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
959#endif
960 int i;
961 int last_bit_value;
962 int transitions = 0;
963
964 if ((low == 0
a238cd8b 965#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
966 && high == 0
967#endif
968 )
969 || (low == ~0
a238cd8b 970#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
971 && high == ~0
972#endif
973 ))
974 return 0;
975
976 last_bit_value = low & 1;
977
978 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
979 if (((low >>= 1) & 1) != last_bit_value)
980 last_bit_value ^= 1, transitions++;
981
a238cd8b 982#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
983 if ((high & 1) != last_bit_value)
984 last_bit_value ^= 1, transitions++;
985
986 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
987 if (((high >>= 1) & 1) != last_bit_value)
988 last_bit_value ^= 1, transitions++;
989#endif
990
991 return transitions <= 1;
992 }
993 else
994 return 0;
995}
996
997/* Return 1 if the operand is either a non-special register or a constant
998 that can be used as the operand of a PowerPC64 logical AND insn. */
999
1000int
1001and64_operand (op, mode)
9878760c
RK
1002 register rtx op;
1003 enum machine_mode mode;
1004{
38c1f2d7 1005 return (logical_operand (op, mode)
a260abc9 1006 || mask64_operand (op, mode));
9878760c
RK
1007}
1008
a260abc9
DE
1009/* Return 1 if the operand is either a non-special register or a
1010 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1011
1012int
a260abc9
DE
1013and_operand (op, mode)
1014 register rtx op;
1015 enum machine_mode mode;
dcfedcd0 1016{
a260abc9
DE
1017 return (logical_operand (op, mode)
1018 || mask_operand (op, mode));
dcfedcd0
RK
1019}
1020
9878760c
RK
1021/* Return 1 if the operand is a general register or memory operand. */
1022
1023int
1024reg_or_mem_operand (op, mode)
1025 register rtx op;
1026 register enum machine_mode mode;
1027{
b6c9286a
MM
1028 return (gpc_reg_operand (op, mode)
1029 || memory_operand (op, mode)
1030 || volatile_mem_operand (op, mode));
9878760c
RK
1031}
1032
a7a813f7
RK
1033/* Return 1 if the operand is a general register or memory operand without
1034 pre-inc or pre_dec which produces invalid form of PowerPC lwa
1035 instruction. */
1036
1037int
1038lwa_operand (op, mode)
1039 register rtx op;
1040 register enum machine_mode mode;
1041{
1042 rtx inner = op;
1043
1044 if (reload_completed && GET_CODE (inner) == SUBREG)
1045 inner = SUBREG_REG (inner);
1046
1047 return gpc_reg_operand (inner, mode)
1048 || (memory_operand (inner, mode)
1049 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1050 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1051}
1052
9878760c
RK
1053/* Return 1 if the operand, used inside a MEM, is a valid first argument
1054 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1055 forced to lr. */
1056
1057int
1058call_operand (op, mode)
1059 register rtx op;
1060 enum machine_mode mode;
1061{
1062 if (mode != VOIDmode && GET_MODE (op) != mode)
1063 return 0;
1064
1065 return (GET_CODE (op) == SYMBOL_REF
1066 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1067}
1068
2af3d377
RK
1069
1070/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
1071 this file. */
1072
1073int
1074current_file_function_operand (op, mode)
1075 register rtx op;
296b8152 1076 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1077{
1078 return (GET_CODE (op) == SYMBOL_REF
1079 && (SYMBOL_REF_FLAG (op)
1080 || op == XEXP (DECL_RTL (current_function_decl), 0)));
1081}
1082
1083
9878760c
RK
1084/* Return 1 if this operand is a valid input for a move insn. */
1085
1086int
1087input_operand (op, mode)
1088 register rtx op;
1089 enum machine_mode mode;
1090{
eb4e8003 1091 /* Memory is always valid. */
9878760c
RK
1092 if (memory_operand (op, mode))
1093 return 1;
1094
eb4e8003
RK
1095 /* For floating-point, easy constants are valid. */
1096 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1097 && CONSTANT_P (op)
1098 && easy_fp_constant (op, mode))
1099 return 1;
1100
4e74d8ec
MM
1101 /* Allow any integer constant. */
1102 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625
DE
1103 && (GET_CODE (op) == CONST_INT
1104 || GET_CODE (op) == CONSTANT_P_RTX
1105 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1106 return 1;
1107
eb4e8003
RK
1108 /* For floating-point or multi-word mode, the only remaining valid type
1109 is a register. */
9878760c
RK
1110 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1111 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1112 return register_operand (op, mode);
9878760c 1113
88fe15a1
RK
1114 /* The only cases left are integral modes one word or smaller (we
1115 do not get called for MODE_CC values). These can be in any
1116 register. */
1117 if (register_operand (op, mode))
a8b3aeda 1118 return 1;
88fe15a1 1119
84cf9dda 1120 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 1121 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
1122 return 1;
1123
b6c9286a
MM
1124 /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC
1125 directly in the instruction stream */
1126 if (DEFAULT_ABI == ABI_NT
1127 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF))
1128 return 1;
1129
88228c4b
MM
1130 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1131 to be valid. */
c81bebd7 1132 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
88228c4b
MM
1133 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1134 && small_data_operand (op, Pmode))
1135 return 1;
1136
042259f2 1137 return 0;
9878760c 1138}
7509c759
MM
1139
1140/* Return 1 for an operand in small memory on V.4/eabi */
1141
1142int
1143small_data_operand (op, mode)
296b8152 1144#if TARGET_ELF
7509c759
MM
1145 rtx op;
1146 enum machine_mode mode;
296b8152
KG
1147#else
1148 rtx op ATTRIBUTE_UNUSED;
1149 enum machine_mode mode ATTRIBUTE_UNUSED;
1150#endif
7509c759 1151{
38c1f2d7 1152#if TARGET_ELF
7509c759
MM
1153 rtx sym_ref, const_part;
1154
d9407988 1155 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 1156 return 0;
a54d04b7 1157
5b9d9a0c 1158 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
7509c759
MM
1159 return 0;
1160
88228c4b
MM
1161 if (GET_CODE (op) == SYMBOL_REF)
1162 sym_ref = op;
1163
1164 else if (GET_CODE (op) != CONST
1165 || GET_CODE (XEXP (op, 0)) != PLUS
1166 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1167 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
1168 return 0;
1169
88228c4b 1170 else
dbf55e53
MM
1171 {
1172 rtx sum = XEXP (op, 0);
1173 HOST_WIDE_INT summand;
1174
1175 /* We have to be careful here, because it is the referenced address
1176 that must be 32k from _SDA_BASE_, not just the symbol. */
1177 summand = INTVAL (XEXP (sum, 1));
1178 if (summand < 0 || summand > g_switch_value)
1179 return 0;
1180
1181 sym_ref = XEXP (sum, 0);
1182 }
88228c4b
MM
1183
1184 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
1185 return 0;
1186
1187 return 1;
d9407988
MM
1188
1189#else
1190 return 0;
1191#endif
7509c759
MM
1192}
1193
4697a36c
MM
1194\f
1195/* Initialize a variable CUM of type CUMULATIVE_ARGS
1196 for a call to a function whose data type is FNTYPE.
1197 For a library call, FNTYPE is 0.
1198
1199 For incoming args we set the number of arguments in the prototype large
1c20ae99 1200 so we never return a PARALLEL. */
4697a36c
MM
1201
1202void
1203init_cumulative_args (cum, fntype, libname, incoming)
1204 CUMULATIVE_ARGS *cum;
1205 tree fntype;
296b8152 1206 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
1207 int incoming;
1208{
1209 static CUMULATIVE_ARGS zero_cumulative;
7509c759 1210 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c
MM
1211
1212 *cum = zero_cumulative;
1213 cum->words = 0;
1214 cum->fregno = FP_ARG_MIN_REG;
1215 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 1216 cum->call_cookie = CALL_NORMAL;
4697a36c
MM
1217
1218 if (incoming)
1219 {
1c20ae99 1220 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
c81bebd7 1221 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4697a36c 1222 cum->varargs_offset = RS6000_VARARGS_OFFSET;
4697a36c
MM
1223 }
1224
1225 else if (cum->prototype)
1226 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1227 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1228 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1229
1230 else
1231 cum->nargs_prototype = 0;
1232
1233 cum->orig_nargs = cum->nargs_prototype;
7509c759
MM
1234
1235 /* Check for DLL import functions */
1236 if (abi == ABI_NT
1237 && fntype
1238 && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype)))
1239 cum->call_cookie = CALL_NT_DLLIMPORT;
1240
6a4cee5f
MM
1241 /* Also check for longcall's */
1242 else if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1243 cum->call_cookie = CALL_LONG;
1244
4697a36c
MM
1245 if (TARGET_DEBUG_ARG)
1246 {
1247 fprintf (stderr, "\ninit_cumulative_args:");
1248 if (fntype)
1249 {
1250 tree ret_type = TREE_TYPE (fntype);
1251 fprintf (stderr, " ret code = %s,",
1252 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1253 }
1254
c81bebd7 1255 if ((abi == ABI_V4 || abi == ABI_SOLARIS) && incoming)
4697a36c 1256 fprintf (stderr, " varargs = %d, ", cum->varargs_offset);
7509c759 1257
6a4cee5f 1258 if (cum->call_cookie & CALL_NT_DLLIMPORT)
7509c759 1259 fprintf (stderr, " dllimport,");
4697a36c 1260
6a4cee5f
MM
1261 if (cum->call_cookie & CALL_LONG)
1262 fprintf (stderr, " longcall,");
1263
4697a36c
MM
1264 fprintf (stderr, " proto = %d, nargs = %d\n",
1265 cum->prototype, cum->nargs_prototype);
1266 }
1267}
1268\f
c229cba9
DE
1269/* If defined, a C expression which determines whether, and in which
1270 direction, to pad out an argument with extra space. The value
1271 should be of type `enum direction': either `upward' to pad above
1272 the argument, `downward' to pad below, or `none' to inhibit
1273 padding.
1274
1275 For the AIX ABI structs are always stored left shifted in their
1276 argument slot. */
1277
c4d38ccb 1278int
c229cba9
DE
1279function_arg_padding (mode, type)
1280 enum machine_mode mode;
1281 tree type;
1282{
c85f7c16 1283 if (type != 0 && AGGREGATE_TYPE_P (type))
c4d38ccb 1284 return (int)upward;
c229cba9
DE
1285
1286 /* This is the default definition. */
1287 return (! BYTES_BIG_ENDIAN
c4d38ccb 1288 ? (int)upward
c229cba9
DE
1289 : ((mode == BLKmode
1290 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1291 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1292 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
c4d38ccb 1293 ? (int)downward : (int)upward));
c229cba9
DE
1294}
1295
b6c9286a
MM
1296/* If defined, a C expression that gives the alignment boundary, in bits,
1297 of an argument with the specified mode and type. If it is not defined,
1298 PARM_BOUNDARY is used for all arguments.
1299
e1f83b4d
MM
1300 Windows NT wants anything >= 8 bytes to be double word aligned.
1301
1302 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
1303
1304int
1305function_arg_boundary (mode, type)
1306 enum machine_mode mode;
1307 tree type;
1308{
c81bebd7 1309 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && mode == DImode)
e1f83b4d
MM
1310 return 64;
1311
b6c9286a
MM
1312 if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
1313 return PARM_BOUNDARY;
1314
1315 if (mode != BLKmode)
1316 return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32;
1317
1318 return (int_size_in_bytes (type) >= 8) ? 64 : 32;
1319}
1320\f
4697a36c
MM
1321/* Update the data in CUM to advance over an argument
1322 of mode MODE and data type TYPE.
1323 (TYPE is null for libcalls where that information may not be available.) */
1324
1325void
1326function_arg_advance (cum, mode, type, named)
1327 CUMULATIVE_ARGS *cum;
1328 enum machine_mode mode;
1329 tree type;
1330 int named;
1331{
a260abc9
DE
1332 int align = (TARGET_32BIT && (cum->words & 1) != 0
1333 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
b6c9286a 1334 cum->words += align;
4697a36c
MM
1335 cum->nargs_prototype--;
1336
c81bebd7 1337 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c
MM
1338 {
1339 /* Long longs must not be split between registers and stack */
1340 if ((GET_MODE_CLASS (mode) != MODE_FLOAT || TARGET_SOFT_FLOAT)
1341 && type && !AGGREGATE_TYPE_P (type)
1342 && cum->words < GP_ARG_NUM_REG
1343 && cum->words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
1344 {
1345 cum->words = GP_ARG_NUM_REG;
1346 }
1347
1348 /* Aggregates get passed as pointers */
1349 if (type && AGGREGATE_TYPE_P (type))
1350 cum->words++;
1351
1352 /* Floats go in registers, & don't occupy space in the GP registers
1353 like they do for AIX unless software floating point. */
1354 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
1355 && TARGET_HARD_FLOAT
1356 && cum->fregno <= FP_ARG_V4_MAX_REG)
1357 cum->fregno++;
1358
1359 else
1360 cum->words += RS6000_ARG_SIZE (mode, type, 1);
1361 }
1362 else
4697a36c
MM
1363 if (named)
1364 {
1365 cum->words += RS6000_ARG_SIZE (mode, type, named);
1366 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
1367 cum->fregno++;
1368 }
1369
1370 if (TARGET_DEBUG_ARG)
1371 fprintf (stderr,
b6c9286a
MM
1372 "function_adv: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
1373 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
4697a36c
MM
1374}
1375\f
1376/* Determine where to put an argument to a function.
1377 Value is zero to push the argument on the stack,
1378 or a hard register in which to store the argument.
1379
1380 MODE is the argument's machine mode.
1381 TYPE is the data type of the argument (as a tree).
1382 This is null for libcalls where that information may
1383 not be available.
1384 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1385 the preceding args and about the function being called.
1386 NAMED is nonzero if this argument is a named parameter
1387 (otherwise it is an extra parameter matching an ellipsis).
1388
1389 On RS/6000 the first eight words of non-FP are normally in registers
1390 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
1391 Under V.4, the first 8 FP args are in registers.
1392
1393 If this is floating-point and no prototype is specified, we use
1394 both an FP and integer register (or possibly FP reg and stack). Library
1395 functions (when TYPE is zero) always have the proper types for args,
1396 so we can pass the FP value just in one register. emit_library_function
1c20ae99 1397 doesn't support PARALLEL anyway. */
4697a36c
MM
1398
1399struct rtx_def *
1400function_arg (cum, mode, type, named)
1401 CUMULATIVE_ARGS *cum;
1402 enum machine_mode mode;
1403 tree type;
1404 int named;
1405{
a260abc9
DE
1406 int align = (TARGET_32BIT && (cum->words & 1) != 0
1407 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
b6c9286a
MM
1408 int align_words = cum->words + align;
1409
4697a36c
MM
1410 if (TARGET_DEBUG_ARG)
1411 fprintf (stderr,
b6c9286a
MM
1412 "function_arg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
1413 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
4697a36c
MM
1414
1415 /* Return a marker to indicate whether CR1 needs to set or clear the bit that V.4
1416 uses to say fp args were passed in registers. Assume that we don't need the
1417 marker for software floating point, or compiler generated library calls. */
1418 if (mode == VOIDmode)
1419 {
7509c759
MM
1420 enum rs6000_abi abi = DEFAULT_ABI;
1421
c81bebd7 1422 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
7509c759
MM
1423 && TARGET_HARD_FLOAT
1424 && cum->nargs_prototype < 0
4697a36c 1425 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 1426 {
6a4cee5f
MM
1427 return GEN_INT (cum->call_cookie
1428 | ((cum->fregno == FP_ARG_MIN_REG)
1429 ? CALL_V4_SET_FP_ARGS
1430 : CALL_V4_CLEAR_FP_ARGS));
7509c759 1431 }
4697a36c 1432
7509c759 1433 return GEN_INT (cum->call_cookie);
4697a36c
MM
1434 }
1435
1436 if (!named)
1437 {
c81bebd7 1438 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
4697a36c
MM
1439 return NULL_RTX;
1440 }
1441
1442 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1443 return NULL_RTX;
1444
1445 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1446 {
5b9d9a0c 1447 if (DEFAULT_ABI == ABI_V4 /* V.4 never passes FP values in GP registers */
c81bebd7 1448 || DEFAULT_ABI == ABI_SOLARIS
5b9d9a0c
MM
1449 || ! type
1450 || ((cum->nargs_prototype > 0)
1451 /* IBM AIX extended its linkage convention definition always to
1452 require FP args after register save area hole on the stack. */
1453 && (DEFAULT_ABI != ABI_AIX
1454 || ! TARGET_XL_CALL
1455 || (align_words < GP_ARG_NUM_REG))))
39403d82 1456 return gen_rtx_REG (mode, cum->fregno);
4697a36c 1457
39403d82 1458 return gen_rtx_PARALLEL (mode,
1c20ae99
JW
1459 gen_rtvec
1460 (2,
39403d82 1461 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
1462 ((align_words >= GP_ARG_NUM_REG)
1463 ? NULL_RTX
1464 : (align_words
1465 + RS6000_ARG_SIZE (mode, type, named)
1466 > GP_ARG_NUM_REG
1467 /* If this is partially on the stack, then
1468 we only include the portion actually
1469 in registers here. */
39403d82 1470 ? gen_rtx_REG (SImode,
1c20ae99 1471 GP_ARG_MIN_REG + align_words)
39403d82 1472 : gen_rtx_REG (mode,
1c20ae99
JW
1473 GP_ARG_MIN_REG + align_words))),
1474 const0_rtx),
39403d82
DE
1475 gen_rtx_EXPR_LIST (VOIDmode,
1476 gen_rtx_REG (mode, cum->fregno),
1c20ae99 1477 const0_rtx)));
4697a36c
MM
1478 }
1479
92dcf4c8
MM
1480 /* Long longs won't be split between register and stack;
1481 FP arguments get passed on the stack if they didn't get a register. */
c81bebd7 1482 else if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) &&
92dcf4c8
MM
1483 (align_words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG
1484 || (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)))
4697a36c
MM
1485 {
1486 return NULL_RTX;
1487 }
4697a36c 1488
b6c9286a 1489 else if (align_words < GP_ARG_NUM_REG)
39403d82 1490 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4697a36c
MM
1491
1492 return NULL_RTX;
1493}
1494\f
1495/* For an arg passed partly in registers and partly in memory,
1496 this is the number of registers used.
1497 For args passed entirely in registers or entirely in memory, zero. */
1498
1499int
1500function_arg_partial_nregs (cum, mode, type, named)
1501 CUMULATIVE_ARGS *cum;
1502 enum machine_mode mode;
1503 tree type;
1504 int named;
1505{
1506 if (! named)
1507 return 0;
1508
c81bebd7 1509 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c 1510 return 0;
4697a36c
MM
1511
1512 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1513 {
1514 if (cum->nargs_prototype >= 0)
1515 return 0;
1516 }
1517
1518 if (cum->words < GP_ARG_NUM_REG
1519 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
1520 {
1521 int ret = GP_ARG_NUM_REG - cum->words;
1522 if (ret && TARGET_DEBUG_ARG)
1523 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
1524
1525 return ret;
1526 }
1527
1528 return 0;
1529}
1530\f
1531/* A C expression that indicates when an argument must be passed by
1532 reference. If nonzero for an argument, a copy of that argument is
1533 made in memory and a pointer to the argument is passed instead of
1534 the argument itself. The pointer is passed in whatever way is
1535 appropriate for passing a pointer to that type.
1536
1537 Under V.4, structures and unions are passed by reference. */
1538
1539int
1540function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
1541 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
1542 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 1543 tree type;
296b8152 1544 int named ATTRIBUTE_UNUSED;
4697a36c 1545{
c81bebd7
MM
1546 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1547 && type && AGGREGATE_TYPE_P (type))
4697a36c
MM
1548 {
1549 if (TARGET_DEBUG_ARG)
1550 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
1551
1552 return 1;
1553 }
4697a36c
MM
1554
1555 return 0;
1556}
1557
1558\f
1559/* Perform any needed actions needed for a function that is receiving a
1560 variable number of arguments.
1561
1562 CUM is as above.
1563
1564 MODE and TYPE are the mode and type of the current parameter.
1565
1566 PRETEND_SIZE is a variable that should be set to the amount of stack
1567 that must be pushed by the prolog to pretend that our caller pushed
1568 it.
1569
1570 Normally, this macro will push all remaining incoming registers on the
1571 stack and set PRETEND_SIZE to the length of the registers pushed. */
1572
1573void
1574setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
1575 CUMULATIVE_ARGS *cum;
1576 enum machine_mode mode;
1577 tree type;
1578 int *pretend_size;
1579 int no_rtl;
1580
1581{
1582 rtx save_area = virtual_incoming_args_rtx;
a260abc9 1583 int reg_size = TARGET_32BIT ? 4 : 8;
4697a36c
MM
1584
1585 if (TARGET_DEBUG_ARG)
1586 fprintf (stderr,
1587 "setup_vararg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, no_rtl= %d\n",
1588 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), no_rtl);
1589
60e2d0ca 1590 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4697a36c
MM
1591 {
1592 rs6000_sysv_varargs_p = 1;
60e2d0ca
RK
1593 if (! no_rtl)
1594 save_area = plus_constant (frame_pointer_rtx, RS6000_VARARGS_OFFSET);
4697a36c 1595 }
60e2d0ca
RK
1596 else
1597 rs6000_sysv_varargs_p = 0;
4697a36c
MM
1598
1599 if (cum->words < 8)
1600 {
1601 int first_reg_offset = cum->words;
1602
1603 if (MUST_PASS_IN_STACK (mode, type))
1604 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
1605
1606 if (first_reg_offset > GP_ARG_NUM_REG)
1607 first_reg_offset = GP_ARG_NUM_REG;
1608
1609 if (!no_rtl && first_reg_offset != GP_ARG_NUM_REG)
1610 move_block_from_reg
1611 (GP_ARG_MIN_REG + first_reg_offset,
39403d82 1612 gen_rtx_MEM (BLKmode,
4697a36c
MM
1613 plus_constant (save_area, first_reg_offset * reg_size)),
1614 GP_ARG_NUM_REG - first_reg_offset,
1615 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
1616
1617 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
1618 }
1619
4697a36c 1620 /* Save FP registers if needed. */
c81bebd7 1621 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && TARGET_HARD_FLOAT && !no_rtl)
4697a36c
MM
1622 {
1623 int fregno = cum->fregno;
1624 int num_fp_reg = FP_ARG_V4_MAX_REG + 1 - fregno;
1625
1626 if (num_fp_reg >= 0)
1627 {
39403d82 1628 rtx cr1 = gen_rtx_REG (CCmode, 69);
4697a36c
MM
1629 rtx lab = gen_label_rtx ();
1630 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
1631
39403d82 1632 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 1633 pc_rtx,
39403d82
DE
1634 gen_rtx_IF_THEN_ELSE (VOIDmode,
1635 gen_rtx_NE (VOIDmode, cr1, const0_rtx),
1636 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
1637 pc_rtx)));
1638
1639 while ( num_fp_reg-- >= 0)
1640 {
39403d82
DE
1641 emit_move_insn (gen_rtx_MEM (DFmode, plus_constant (save_area, off)),
1642 gen_rtx_REG (DFmode, fregno++));
4697a36c
MM
1643 off += 8;
1644 }
1645
1646 emit_label (lab);
1647 }
1648 }
4697a36c
MM
1649}
1650\f
1651/* If defined, is a C expression that produces the machine-specific
1652 code for a call to `__builtin_saveregs'. This code will be moved
1653 to the very beginning of the function, before any parameter access
1654 are made. The return value of this function should be an RTX that
1655 contains the value to use as the return of `__builtin_saveregs'.
1656
1657 The argument ARGS is a `tree_list' containing the arguments that
1658 were passed to `__builtin_saveregs'.
1659
1660 If this macro is not defined, the compiler will output an ordinary
1661 call to the library function `__builtin_saveregs'.
1662
1663 On the Power/PowerPC return the address of the area on the stack
1664 used to hold arguments. Under AIX, this includes the 8 word register
1665 save area. Under V.4 this does not. */
1666
1667struct rtx_def *
1668expand_builtin_saveregs (args)
296b8152 1669 tree args ATTRIBUTE_UNUSED;
4697a36c
MM
1670{
1671 return virtual_incoming_args_rtx;
1672}
1673
5b5040b9
RK
1674\f
1675/* Generate a memory reference for expand_block_move, copying volatile,
1676 and other bits from an original memory reference. */
1677
1678static rtx
1679expand_block_move_mem (mode, addr, orig_mem)
1680 enum machine_mode mode;
1681 rtx addr;
1682 rtx orig_mem;
1683{
39403d82 1684 rtx mem = gen_rtx_MEM (mode, addr);
b6c9286a
MM
1685
1686 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem);
5b5040b9
RK
1687 MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (orig_mem);
1688 MEM_IN_STRUCT_P (mem) = MEM_IN_STRUCT_P (orig_mem);
b6c9286a
MM
1689#ifdef MEM_UNALIGNED_P
1690 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
1691#endif
5b5040b9
RK
1692 return mem;
1693}
1694
7e69e155
MM
1695/* Expand a block move operation, and return 1 if successful. Return 0
1696 if we should let the compiler generate normal code.
1697
1698 operands[0] is the destination
1699 operands[1] is the source
1700 operands[2] is the length
1701 operands[3] is the alignment */
1702
3933e0e1
MM
1703#define MAX_MOVE_REG 4
1704
7e69e155
MM
1705int
1706expand_block_move (operands)
1707 rtx operands[];
1708{
b6c9286a
MM
1709 rtx orig_dest = operands[0];
1710 rtx orig_src = operands[1];
7e69e155 1711 rtx bytes_rtx = operands[2];
7e69e155 1712 rtx align_rtx = operands[3];
3933e0e1 1713 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
7e69e155 1714 int align = XINT (align_rtx, 0);
3933e0e1
MM
1715 int bytes;
1716 int offset;
1717 int num_reg;
1718 int i;
7e69e155
MM
1719 rtx src_reg;
1720 rtx dest_reg;
3933e0e1
MM
1721 rtx src_addr;
1722 rtx dest_addr;
7e69e155 1723 rtx tmp_reg;
3933e0e1 1724 rtx stores[MAX_MOVE_REG];
7e69e155
MM
1725 int move_bytes;
1726
3933e0e1
MM
1727 /* If this is not a fixed size move, just call memcpy */
1728 if (!constp)
1729 return 0;
1730
7e69e155 1731 /* Anything to move? */
3933e0e1
MM
1732 bytes = INTVAL (bytes_rtx);
1733 if (bytes <= 0)
7e69e155
MM
1734 return 1;
1735
3933e0e1
MM
1736 /* Don't support real large moves. If string instructions are not used,
1737 then don't generate more than 8 loads. */
1738 if (TARGET_STRING)
1739 {
1cab3be1 1740 if (bytes > 4*8)
3933e0e1
MM
1741 return 0;
1742 }
1743 else if (!STRICT_ALIGNMENT)
1744 {
1745 if (bytes > 4*8)
1746 return 0;
1747 }
1748 else if (bytes > 8*align)
7e69e155
MM
1749 return 0;
1750
1751 /* Move the address into scratch registers. */
b6c9286a
MM
1752 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
1753 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
7e69e155 1754
3933e0e1 1755 if (TARGET_STRING) /* string instructions are available */
7e69e155 1756 {
3933e0e1 1757 for ( ; bytes > 0; bytes -= move_bytes)
7e69e155 1758 {
3933e0e1
MM
1759 if (bytes > 24 /* move up to 32 bytes at a time */
1760 && !fixed_regs[5]
1761 && !fixed_regs[6]
1762 && !fixed_regs[7]
1763 && !fixed_regs[8]
1764 && !fixed_regs[9]
1765 && !fixed_regs[10]
1766 && !fixed_regs[11]
1767 && !fixed_regs[12])
1768 {
1769 move_bytes = (bytes > 32) ? 32 : bytes;
b6c9286a
MM
1770 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1771 expand_block_move_mem (BLKmode, src_reg, orig_src),
3933e0e1 1772 GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
4c64a852 1773 align_rtx));
3933e0e1
MM
1774 }
1775 else if (bytes > 16 /* move up to 24 bytes at a time */
1776 && !fixed_regs[7]
1777 && !fixed_regs[8]
1778 && !fixed_regs[9]
1779 && !fixed_regs[10]
1780 && !fixed_regs[11]
1781 && !fixed_regs[12])
1782 {
1783 move_bytes = (bytes > 24) ? 24 : bytes;
b6c9286a
MM
1784 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1785 expand_block_move_mem (BLKmode, src_reg, orig_src),
3933e0e1 1786 GEN_INT (move_bytes),
4c64a852 1787 align_rtx));
3933e0e1
MM
1788 }
1789 else if (bytes > 8 /* move up to 16 bytes at a time */
1790 && !fixed_regs[9]
1791 && !fixed_regs[10]
1792 && !fixed_regs[11]
1793 && !fixed_regs[12])
1794 {
1795 move_bytes = (bytes > 16) ? 16 : bytes;
b6c9286a
MM
1796 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1797 expand_block_move_mem (BLKmode, src_reg, orig_src),
3933e0e1 1798 GEN_INT (move_bytes),
4c64a852 1799 align_rtx));
3933e0e1 1800 }
d679bebf 1801 else if (bytes > 4 && !TARGET_64BIT)
3933e0e1
MM
1802 { /* move up to 8 bytes at a time */
1803 move_bytes = (bytes > 8) ? 8 : bytes;
b6c9286a
MM
1804 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1805 expand_block_move_mem (BLKmode, src_reg, orig_src),
3933e0e1 1806 GEN_INT (move_bytes),
4c64a852 1807 align_rtx));
3933e0e1
MM
1808 }
1809 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
1810 { /* move 4 bytes */
1811 move_bytes = 4;
1812 tmp_reg = gen_reg_rtx (SImode);
b6c9286a
MM
1813 emit_move_insn (tmp_reg, expand_block_move_mem (SImode, src_reg, orig_src));
1814 emit_move_insn (expand_block_move_mem (SImode, dest_reg, orig_dest), tmp_reg);
3933e0e1
MM
1815 }
1816 else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
1817 { /* move 2 bytes */
1818 move_bytes = 2;
1819 tmp_reg = gen_reg_rtx (HImode);
b6c9286a
MM
1820 emit_move_insn (tmp_reg, expand_block_move_mem (HImode, src_reg, orig_src));
1821 emit_move_insn (expand_block_move_mem (HImode, dest_reg, orig_dest), tmp_reg);
3933e0e1
MM
1822 }
1823 else if (bytes == 1) /* move 1 byte */
1824 {
1825 move_bytes = 1;
1826 tmp_reg = gen_reg_rtx (QImode);
b6c9286a
MM
1827 emit_move_insn (tmp_reg, expand_block_move_mem (QImode, src_reg, orig_src));
1828 emit_move_insn (expand_block_move_mem (QImode, dest_reg, orig_dest), tmp_reg);
3933e0e1
MM
1829 }
1830 else
1831 { /* move up to 4 bytes at a time */
1832 move_bytes = (bytes > 4) ? 4 : bytes;
b6c9286a
MM
1833 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1834 expand_block_move_mem (BLKmode, src_reg, orig_src),
3933e0e1 1835 GEN_INT (move_bytes),
4c64a852 1836 align_rtx));
3933e0e1 1837 }
4c64a852 1838
015892ee
RK
1839 if (bytes > move_bytes)
1840 {
1841 emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes)));
1842 emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes)));
1843 }
4c64a852 1844 }
3933e0e1
MM
1845 }
1846
1847 else /* string instructions not available */
1848 {
1849 num_reg = offset = 0;
1850 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
7e69e155 1851 {
3933e0e1
MM
1852 /* Calculate the correct offset for src/dest */
1853 if (offset == 0)
7e69e155 1854 {
3933e0e1
MM
1855 src_addr = src_reg;
1856 dest_addr = dest_reg;
1857 }
1858 else
1859 {
39403d82
DE
1860 src_addr = gen_rtx_PLUS (Pmode, src_reg, GEN_INT (offset));
1861 dest_addr = gen_rtx_PLUS (Pmode, dest_reg, GEN_INT (offset));
3933e0e1
MM
1862 }
1863
1864 /* Generate the appropriate load and store, saving the stores for later */
b6c9286a
MM
1865 if (bytes >= 8 && TARGET_64BIT && (align >= 8 || !STRICT_ALIGNMENT))
1866 {
1867 move_bytes = 8;
1868 tmp_reg = gen_reg_rtx (DImode);
1869 emit_insn (gen_movdi (tmp_reg, expand_block_move_mem (DImode, src_addr, orig_src)));
1870 stores[ num_reg++ ] = gen_movdi (expand_block_move_mem (DImode, dest_addr, orig_dest), tmp_reg);
1871 }
1872 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
3933e0e1
MM
1873 {
1874 move_bytes = 4;
1875 tmp_reg = gen_reg_rtx (SImode);
b6c9286a
MM
1876 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (SImode, src_addr, orig_src)));
1877 stores[ num_reg++ ] = gen_movsi (expand_block_move_mem (SImode, dest_addr, orig_dest), tmp_reg);
3933e0e1
MM
1878 }
1879 else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
1880 {
1881 move_bytes = 2;
1882 tmp_reg = gen_reg_rtx (HImode);
b6c9286a
MM
1883 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (HImode, src_addr, orig_src)));
1884 stores[ num_reg++ ] = gen_movhi (expand_block_move_mem (HImode, dest_addr, orig_dest), tmp_reg);
3933e0e1
MM
1885 }
1886 else
1887 {
1888 move_bytes = 1;
1889 tmp_reg = gen_reg_rtx (QImode);
b6c9286a
MM
1890 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (QImode, src_addr, orig_src)));
1891 stores[ num_reg++ ] = gen_movqi (expand_block_move_mem (QImode, dest_addr, orig_dest), tmp_reg);
3933e0e1
MM
1892 }
1893
1894 if (num_reg >= MAX_MOVE_REG)
1895 {
1896 for (i = 0; i < num_reg; i++)
1897 emit_insn (stores[i]);
1898 num_reg = 0;
7e69e155
MM
1899 }
1900 }
3933e0e1 1901
b6c9286a
MM
1902 for (i = 0; i < num_reg; i++)
1903 emit_insn (stores[i]);
7e69e155
MM
1904 }
1905
1906 return 1;
1907}
1908
9878760c
RK
1909\f
1910/* Return 1 if OP is a load multiple operation. It is known to be a
1911 PARALLEL and the first section will be tested. */
1912
1913int
1914load_multiple_operation (op, mode)
1915 rtx op;
296b8152 1916 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
1917{
1918 int count = XVECLEN (op, 0);
1919 int dest_regno;
1920 rtx src_addr;
1921 int i;
1922
1923 /* Perform a quick check so we don't blow up below. */
1924 if (count <= 1
1925 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1926 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1927 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1928 return 0;
1929
1930 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1931 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1932
1933 for (i = 1; i < count; i++)
1934 {
1935 rtx elt = XVECEXP (op, 0, i);
1936
1937 if (GET_CODE (elt) != SET
1938 || GET_CODE (SET_DEST (elt)) != REG
1939 || GET_MODE (SET_DEST (elt)) != SImode
1940 || REGNO (SET_DEST (elt)) != dest_regno + i
1941 || GET_CODE (SET_SRC (elt)) != MEM
1942 || GET_MODE (SET_SRC (elt)) != SImode
1943 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
1944 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
1945 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
1946 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
1947 return 0;
1948 }
1949
1950 return 1;
1951}
1952
1953/* Similar, but tests for store multiple. Here, the second vector element
1954 is a CLOBBER. It will be tested later. */
1955
1956int
1957store_multiple_operation (op, mode)
1958 rtx op;
296b8152 1959 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
1960{
1961 int count = XVECLEN (op, 0) - 1;
1962 int src_regno;
1963 rtx dest_addr;
1964 int i;
1965
1966 /* Perform a quick check so we don't blow up below. */
1967 if (count <= 1
1968 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1969 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1970 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1971 return 0;
1972
1973 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1974 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1975
1976 for (i = 1; i < count; i++)
1977 {
1978 rtx elt = XVECEXP (op, 0, i + 1);
1979
1980 if (GET_CODE (elt) != SET
1981 || GET_CODE (SET_SRC (elt)) != REG
1982 || GET_MODE (SET_SRC (elt)) != SImode
1983 || REGNO (SET_SRC (elt)) != src_regno + i
1984 || GET_CODE (SET_DEST (elt)) != MEM
1985 || GET_MODE (SET_DEST (elt)) != SImode
1986 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
1987 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
1988 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
1989 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
1990 return 0;
1991 }
1992
1993 return 1;
1994}
1995\f
1996/* Return 1 if OP is a comparison operation that is valid for a branch insn.
1997 We only check the opcode against the mode of the CC value here. */
1998
1999int
2000branch_comparison_operator (op, mode)
2001 register rtx op;
296b8152 2002 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
2003{
2004 enum rtx_code code = GET_CODE (op);
2005 enum machine_mode cc_mode;
2006
2007 if (GET_RTX_CLASS (code) != '<')
2008 return 0;
2009
2010 cc_mode = GET_MODE (XEXP (op, 0));
2011 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
2012 return 0;
2013
2014 if ((code == GT || code == LT || code == GE || code == LE)
2015 && cc_mode == CCUNSmode)
2016 return 0;
2017
2018 if ((code == GTU || code == LTU || code == GEU || code == LEU)
2019 && (cc_mode != CCUNSmode))
2020 return 0;
2021
2022 return 1;
2023}
2024
2025/* Return 1 if OP is a comparison operation that is valid for an scc insn.
2026 We check the opcode against the mode of the CC value and disallow EQ or
2027 NE comparisons for integers. */
2028
2029int
2030scc_comparison_operator (op, mode)
2031 register rtx op;
2032 enum machine_mode mode;
2033{
2034 enum rtx_code code = GET_CODE (op);
2035 enum machine_mode cc_mode;
2036
2037 if (GET_MODE (op) != mode && mode != VOIDmode)
2038 return 0;
2039
2040 if (GET_RTX_CLASS (code) != '<')
2041 return 0;
2042
2043 cc_mode = GET_MODE (XEXP (op, 0));
2044 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
2045 return 0;
2046
2047 if (code == NE && cc_mode != CCFPmode)
2048 return 0;
2049
2050 if ((code == GT || code == LT || code == GE || code == LE)
2051 && cc_mode == CCUNSmode)
2052 return 0;
2053
2054 if ((code == GTU || code == LTU || code == GEU || code == LEU)
2055 && (cc_mode != CCUNSmode))
2056 return 0;
2057
c5defebb
RK
2058 if (cc_mode == CCEQmode && code != EQ && code != NE)
2059 return 0;
2060
9878760c
RK
2061 return 1;
2062}
e0cd0770
JC
2063
2064int
2065trap_comparison_operator (op, mode)
2066 rtx op;
2067 enum machine_mode mode;
2068{
2069 if (mode != VOIDmode && mode != GET_MODE (op))
2070 return 0;
2071 return (GET_RTX_CLASS (GET_CODE (op)) == '<'
2072 || GET_CODE (op) == EQ || GET_CODE (op) == NE);
2073}
9878760c
RK
2074\f
2075/* Return 1 if ANDOP is a mask that has no bits on that are not in the
2076 mask required to convert the result of a rotate insn into a shift
2077 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
2078
2079int
2080includes_lshift_p (shiftop, andop)
2081 register rtx shiftop;
2082 register rtx andop;
2083{
2084 int shift_mask = (~0 << INTVAL (shiftop));
2085
2086 return (INTVAL (andop) & ~shift_mask) == 0;
2087}
2088
2089/* Similar, but for right shift. */
2090
2091int
2092includes_rshift_p (shiftop, andop)
2093 register rtx shiftop;
2094 register rtx andop;
2095{
a7653a2c 2096 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
2097
2098 shift_mask >>= INTVAL (shiftop);
2099
2100 return (INTVAL (andop) & ~ shift_mask) == 0;
2101}
35068b43
RK
2102
2103/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
2104 for lfq and stfq insns.
2105
2106 Note reg1 and reg2 *must* be hard registers. To be sure we will
2107 abort if we are passed pseudo registers. */
2108
2109int
2110registers_ok_for_quad_peep (reg1, reg2)
2111 rtx reg1, reg2;
2112{
2113 /* We might have been passed a SUBREG. */
2114 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
2115 return 0;
2116
2117 return (REGNO (reg1) == REGNO (reg2) - 1);
2118}
2119
2120/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
2121 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
2122
2123int
2124addrs_ok_for_quad_peep (addr1, addr2)
2125 register rtx addr1;
2126 register rtx addr2;
2127{
2128 int reg1;
2129 int offset1;
2130
2131 /* Extract an offset (if used) from the first addr. */
2132 if (GET_CODE (addr1) == PLUS)
2133 {
2134 /* If not a REG, return zero. */
2135 if (GET_CODE (XEXP (addr1, 0)) != REG)
2136 return 0;
2137 else
2138 {
2139 reg1 = REGNO (XEXP (addr1, 0));
2140 /* The offset must be constant! */
2141 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
2142 return 0;
2143 offset1 = INTVAL (XEXP (addr1, 1));
2144 }
2145 }
2146 else if (GET_CODE (addr1) != REG)
2147 return 0;
2148 else
2149 {
2150 reg1 = REGNO (addr1);
2151 /* This was a simple (mem (reg)) expression. Offset is 0. */
2152 offset1 = 0;
2153 }
2154
2155 /* Make sure the second address is a (mem (plus (reg) (const_int). */
2156 if (GET_CODE (addr2) != PLUS)
2157 return 0;
2158
2159 if (GET_CODE (XEXP (addr2, 0)) != REG
2160 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
2161 return 0;
2162
2163 if (reg1 != REGNO (XEXP (addr2, 0)))
2164 return 0;
2165
2166 /* The offset for the second addr must be 8 more than the first addr. */
2167 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
2168 return 0;
2169
2170 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
2171 instructions. */
2172 return 1;
2173}
9878760c
RK
2174\f
2175/* Return the register class of a scratch register needed to copy IN into
2176 or out of a register in CLASS in MODE. If it can be done directly,
2177 NO_REGS is returned. */
2178
2179enum reg_class
2180secondary_reload_class (class, mode, in)
2181 enum reg_class class;
296b8152 2182 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
2183 rtx in;
2184{
2185 int regno = true_regnum (in);
2186
2187 if (regno >= FIRST_PSEUDO_REGISTER)
2188 regno = -1;
2189
e7b7998a
JL
2190 /* We can not copy a symbolic operand directly into anyting other than
2191 BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS
2192 is needed as an intermediate register. */
2193 if (TARGET_ELF
2194 && class != BASE_REGS
2195 && (GET_CODE (in) == SYMBOL_REF
2196 || GET_CODE (in) == LABEL_REF
2197 || GET_CODE (in) == CONST))
2198 return BASE_REGS;
2199
9878760c
RK
2200 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
2201 into anything. */
2202 if (class == GENERAL_REGS || class == BASE_REGS
2203 || (regno >= 0 && INT_REGNO_P (regno)))
2204 return NO_REGS;
2205
2206 /* Constants, memory, and FP registers can go into FP registers. */
2207 if ((regno == -1 || FP_REGNO_P (regno))
2208 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
2209 return NO_REGS;
2210
2211 /* We can copy among the CR registers. */
2212 if ((class == CR_REGS || class == CR0_REGS)
2213 && regno >= 0 && CR_REGNO_P (regno))
2214 return NO_REGS;
2215
2216 /* Otherwise, we need GENERAL_REGS. */
2217 return GENERAL_REGS;
2218}
2219\f
2220/* Given a comparison operation, return the bit number in CCR to test. We
2221 know this is a valid comparison.
2222
2223 SCC_P is 1 if this is for an scc. That means that %D will have been
2224 used instead of %C, so the bits will be in different places.
2225
b4ac57ab 2226 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
2227
2228int
2229ccr_bit (op, scc_p)
2230 register rtx op;
2231 int scc_p;
2232{
2233 enum rtx_code code = GET_CODE (op);
2234 enum machine_mode cc_mode;
2235 int cc_regnum;
2236 int base_bit;
2237
2238 if (GET_RTX_CLASS (code) != '<')
2239 return -1;
2240
2241 cc_mode = GET_MODE (XEXP (op, 0));
2242 cc_regnum = REGNO (XEXP (op, 0));
2243 base_bit = 4 * (cc_regnum - 68);
2244
c5defebb
RK
2245 /* In CCEQmode cases we have made sure that the result is always in the
2246 third bit of the CR field. */
2247
2248 if (cc_mode == CCEQmode)
2249 return base_bit + 3;
2250
9878760c
RK
2251 switch (code)
2252 {
2253 case NE:
2254 return scc_p ? base_bit + 3 : base_bit + 2;
2255 case EQ:
2256 return base_bit + 2;
2257 case GT: case GTU:
2258 return base_bit + 1;
2259 case LT: case LTU:
2260 return base_bit;
2261
2262 case GE: case GEU:
2263 /* If floating-point, we will have done a cror to put the bit in the
2264 unordered position. So test that bit. For integer, this is ! LT
2265 unless this is an scc insn. */
2266 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
2267
2268 case LE: case LEU:
2269 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
2270
2271 default:
2272 abort ();
2273 }
2274}
1ff7789b
MM
2275\f
2276/* Return the GOT register, creating it if needed. */
2277
2278struct rtx_def *
2279rs6000_got_register (value)
2280 rtx value;
2281{
da39823a 2282 if (!current_function_uses_pic_offset_table || !pic_offset_table_rtx)
1ff7789b
MM
2283 {
2284 if (reload_in_progress || reload_completed)
2285 fatal_insn ("internal error -- needed new GOT register during reload phase to load:", value);
2286
2287 current_function_uses_pic_offset_table = 1;
39403d82 2288 pic_offset_table_rtx = gen_rtx_REG (Pmode, GOT_TOC_REGNUM);
1ff7789b
MM
2289 }
2290
2291 return pic_offset_table_rtx;
2292}
2293
2294\f
956d6950 2295/* Replace all occurrences of register FROM with an new pseudo register in an insn X.
1ff7789b
MM
2296 Store the pseudo register used in REG.
2297 This is only safe during FINALIZE_PIC, since the registers haven't been setup
2298 yet. */
2299
2300static rtx
2301rs6000_replace_regno (x, from, reg)
2302 rtx x;
2303 int from;
2304 rtx *reg;
2305{
2306 register int i, j;
2307 register char *fmt;
2308
2309 /* Allow this function to make replacements in EXPR_LISTs. */
2310 if (!x)
2311 return x;
2312
2313 switch (GET_CODE (x))
2314 {
2315 case SCRATCH:
2316 case PC:
2317 case CC0:
2318 case CONST_INT:
2319 case CONST_DOUBLE:
2320 case CONST:
2321 case SYMBOL_REF:
2322 case LABEL_REF:
2323 return x;
2324
2325 case REG:
2326 if (REGNO (x) == from)
2327 {
2328 if (! *reg)
84f414bc 2329 *reg = pic_offset_table_rtx = gen_reg_rtx (Pmode);
1ff7789b
MM
2330
2331 return *reg;
2332 }
2333
2334 return x;
c4d38ccb
MM
2335
2336 default:
2337 break;
1ff7789b
MM
2338 }
2339
2340 fmt = GET_RTX_FORMAT (GET_CODE (x));
2341 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2342 {
2343 if (fmt[i] == 'e')
2344 XEXP (x, i) = rs6000_replace_regno (XEXP (x, i), from, reg);
2345 else if (fmt[i] == 'E')
2346 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2347 XVECEXP (x, i, j) = rs6000_replace_regno (XVECEXP (x, i, j), from, reg);
2348 }
2349
2350 return x;
2351}
2352
d266da75
MM
2353\f
2354/* By generating position-independent code, when two different
2355 programs (A and B) share a common library (libC.a), the text of
2356 the library can be shared whether or not the library is linked at
2357 the same address for both programs. In some of these
2358 environments, position-independent code requires not only the use
2359 of different addressing modes, but also special code to enable the
2360 use of these addressing modes.
2361
2362 The `FINALIZE_PIC' macro serves as a hook to emit these special
2363 codes once the function is being compiled into assembly code, but
2364 not before. (It is not done before, because in the case of
2365 compiling an inline function, it would lead to multiple PIC
2366 prologues being included in functions which used inline functions
2367 and were compiled to assembly language.) */
2368
2369void
2370rs6000_finalize_pic ()
2371{
30ea98f1 2372 /* Loop through all of the insns, replacing the special GOT_TOC_REGNUM
956d6950 2373 with an appropriate pseudo register. If we find we need GOT/TOC,
30ea98f1
MM
2374 add the appropriate init code. */
2375 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
d266da75 2376 {
30ea98f1
MM
2377 rtx insn = get_insns ();
2378 rtx reg = NULL_RTX;
2379 rtx first_insn;
38c1f2d7 2380 rtx last_insn = NULL_RTX;
d266da75 2381
30ea98f1
MM
2382 if (GET_CODE (insn) == NOTE)
2383 insn = next_nonnote_insn (insn);
d266da75 2384
30ea98f1
MM
2385 first_insn = insn;
2386 for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
2387 {
2388 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1ff7789b 2389 {
30ea98f1
MM
2390 PATTERN (insn) = rs6000_replace_regno (PATTERN (insn),
2391 GOT_TOC_REGNUM,
2392 &reg);
2393
2394 if (REG_NOTES (insn))
2395 REG_NOTES (insn) = rs6000_replace_regno (REG_NOTES (insn),
1ff7789b
MM
2396 GOT_TOC_REGNUM,
2397 &reg);
1ff7789b 2398 }
38c1f2d7
MM
2399
2400 if (GET_CODE (insn) != NOTE)
2401 last_insn = insn;
30ea98f1 2402 }
1ff7789b 2403
30ea98f1
MM
2404 if (reg)
2405 {
2406 rtx init = gen_init_v4_pic (reg);
2407 emit_insn_before (init, first_insn);
38c1f2d7 2408 if (!optimize && last_insn)
39403d82 2409 emit_insn_after (gen_rtx_USE (VOIDmode, reg), last_insn);
d266da75
MM
2410 }
2411 }
2412}
2413
30ea98f1 2414\f
956d6950 2415/* Search for any occurrence of the GOT_TOC register marker that should
30ea98f1
MM
2416 have been eliminated, but may have crept back in. */
2417
2418void
2419rs6000_reorg (insn)
2420 rtx insn;
2421{
2422 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
2423 {
39403d82 2424 rtx got_reg = gen_rtx_REG (Pmode, GOT_TOC_REGNUM);
30ea98f1
MM
2425 for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
2426 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2427 && reg_mentioned_p (got_reg, PATTERN (insn)))
2428 fatal_insn ("GOT/TOC register marker not removed:", PATTERN (insn));
2429 }
2430}
2431
a7df97e6
MM
2432\f
2433/* Define the structure for the machine field in struct function. */
2434struct machine_function
2435{
2436 int sysv_varargs_p;
2437 int save_toc_p;
2438 int fpmem_size;
2439 int fpmem_offset;
a04232e5 2440 rtx pic_offset_table_rtx;
a7df97e6
MM
2441};
2442
2443/* Functions to save and restore rs6000_fpmem_size.
2444 These will be called, via pointer variables,
2445 from push_function_context and pop_function_context. */
2446
2447void
2448rs6000_save_machine_status (p)
2449 struct function *p;
2450{
2451 struct machine_function *machine =
2452 (struct machine_function *) xmalloc (sizeof (struct machine_function));
2453
2454 p->machine = machine;
2455 machine->sysv_varargs_p = rs6000_sysv_varargs_p;
a7df97e6
MM
2456 machine->fpmem_size = rs6000_fpmem_size;
2457 machine->fpmem_offset = rs6000_fpmem_offset;
a04232e5 2458 machine->pic_offset_table_rtx = pic_offset_table_rtx;
a7df97e6
MM
2459}
2460
2461void
2462rs6000_restore_machine_status (p)
2463 struct function *p;
2464{
2465 struct machine_function *machine = p->machine;
2466
2467 rs6000_sysv_varargs_p = machine->sysv_varargs_p;
a7df97e6
MM
2468 rs6000_fpmem_size = machine->fpmem_size;
2469 rs6000_fpmem_offset = machine->fpmem_offset;
a04232e5 2470 pic_offset_table_rtx = machine->pic_offset_table_rtx;
a7df97e6
MM
2471
2472 free (machine);
2473 p->machine = (struct machine_function *)0;
2474}
2475
2476/* Do anything needed before RTL is emitted for each function. */
2477
2478void
2479rs6000_init_expanders ()
2480{
2481 /* Reset varargs and save TOC indicator */
2482 rs6000_sysv_varargs_p = 0;
a7df97e6
MM
2483 rs6000_fpmem_size = 0;
2484 rs6000_fpmem_offset = 0;
2485 pic_offset_table_rtx = (rtx)0;
2486
2487 /* Arrange to save and restore machine status around nested functions. */
2488 save_machine_status = rs6000_save_machine_status;
2489 restore_machine_status = rs6000_restore_machine_status;
2490}
2491
9878760c
RK
2492\f
2493/* Print an operand. Recognize special options, documented below. */
2494
38c1f2d7 2495#if TARGET_ELF
d9407988 2496#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 2497#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
2498#else
2499#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 2500#define SMALL_DATA_REG 0
ba5e43aa
MM
2501#endif
2502
9878760c
RK
2503void
2504print_operand (file, x, code)
2505 FILE *file;
2506 rtx x;
2507 char code;
2508{
2509 int i;
a260abc9 2510 HOST_WIDE_INT val;
9878760c
RK
2511
2512 /* These macros test for integers and extract the low-order bits. */
2513#define INT_P(X) \
2514((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
2515 && GET_MODE (X) == VOIDmode)
2516
2517#define INT_LOWPART(X) \
2518 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
2519
2520 switch (code)
2521 {
a8b3aeda 2522 case '.':
a85d226b
RK
2523 /* Write out an instruction after the call which may be replaced
2524 with glue code by the loader. This depends on the AIX version. */
2525 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
2526 return;
2527
cfaaaf2e
RK
2528 case '*':
2529 /* Write the register number of the TOC register. */
4697a36c 2530 fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2], file);
cfaaaf2e
RK
2531 return;
2532
c81bebd7
MM
2533 case '$':
2534 /* Write out either a '.' or '$' for the current location, depending
2535 on whether this is Solaris or not. */
2536 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
2537 return;
2538
9854d9ed
RK
2539 case 'A':
2540 /* If X is a constant integer whose low-order 5 bits are zero,
2541 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 2542 in the AIX assembler where "sri" with a zero shift count
9854d9ed
RK
2543 write a trash instruction. */
2544 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 2545 putc ('l', file);
9854d9ed 2546 else
76229ac8 2547 putc ('r', file);
9854d9ed
RK
2548 return;
2549
2550 case 'b':
2551 /* Low-order 16 bits of constant, unsigned. */
cad12a8d 2552 if (! INT_P (x))
9854d9ed 2553 output_operand_lossage ("invalid %%b value");
cad12a8d 2554
9854d9ed 2555 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
cad12a8d
RK
2556 return;
2557
a260abc9
DE
2558 case 'B':
2559 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
2560 for 64-bit mask direction. */
296b8152 2561 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 2562 return;
a260abc9 2563
9854d9ed
RK
2564 case 'C':
2565 /* This is an optional cror needed for LE or GE floating-point
2566 comparisons. Otherwise write nothing. */
2567 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
2568 && GET_MODE (XEXP (x, 0)) == CCFPmode)
2569 {
2570 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2571
2572 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2573 base_bit + 2, base_bit + (GET_CODE (x) == GE));
2574 }
2575 return;
2576
2577 case 'D':
2578 /* Similar, except that this is for an scc, so we must be able to
2579 encode the test in a single bit that is one. We do the above
2580 for any LE, GE, GEU, or LEU and invert the bit for NE. */
2581 if (GET_CODE (x) == LE || GET_CODE (x) == GE
2582 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
2583 {
2584 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2585
2586 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2587 base_bit + 2,
2588 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
2589 }
2590
2591 else if (GET_CODE (x) == NE)
2592 {
2593 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2594
2595 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
2596 base_bit + 2, base_bit + 2);
2597 }
2598 return;
2599
2600 case 'E':
2601 /* X is a CR register. Print the number of the third bit of the CR */
2602 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2603 output_operand_lossage ("invalid %%E value");
2604
2605 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
a85d226b 2606 return;
9854d9ed
RK
2607
2608 case 'f':
2609 /* X is a CR register. Print the shift count needed to move it
2610 to the high-order four bits. */
2611 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2612 output_operand_lossage ("invalid %%f value");
2613 else
2614 fprintf (file, "%d", 4 * (REGNO (x) - 68));
2615 return;
2616
2617 case 'F':
2618 /* Similar, but print the count for the rotate in the opposite
2619 direction. */
2620 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2621 output_operand_lossage ("invalid %%F value");
2622 else
2623 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
2624 return;
2625
2626 case 'G':
2627 /* X is a constant integer. If it is negative, print "m",
2628 otherwise print "z". This is to make a aze or ame insn. */
2629 if (GET_CODE (x) != CONST_INT)
2630 output_operand_lossage ("invalid %%G value");
2631 else if (INTVAL (x) >= 0)
76229ac8 2632 putc ('z', file);
9854d9ed 2633 else
76229ac8 2634 putc ('m', file);
9854d9ed
RK
2635 return;
2636
9878760c 2637 case 'h':
df3d94ed
RK
2638 /* If constant, output low-order five bits. Otherwise,
2639 write normally. */
9878760c
RK
2640 if (INT_P (x))
2641 fprintf (file, "%d", INT_LOWPART (x) & 31);
2642 else
2643 print_operand (file, x, 0);
2644 return;
2645
64305719
DE
2646 case 'H':
2647 /* If constant, output low-order six bits. Otherwise,
2648 write normally. */
2649 if (INT_P (x))
2650 fprintf (file, "%d", INT_LOWPART (x) & 63);
2651 else
2652 print_operand (file, x, 0);
2653 return;
2654
9854d9ed
RK
2655 case 'I':
2656 /* Print `i' if this is a constant, else nothing. */
9878760c 2657 if (INT_P (x))
76229ac8 2658 putc ('i', file);
9878760c
RK
2659 return;
2660
9854d9ed
RK
2661 case 'j':
2662 /* Write the bit number in CCR for jump. */
2663 i = ccr_bit (x, 0);
2664 if (i == -1)
2665 output_operand_lossage ("invalid %%j code");
9878760c 2666 else
9854d9ed 2667 fprintf (file, "%d", i);
9878760c
RK
2668 return;
2669
9854d9ed
RK
2670 case 'J':
2671 /* Similar, but add one for shift count in rlinm for scc and pass
2672 scc flag to `ccr_bit'. */
2673 i = ccr_bit (x, 1);
2674 if (i == -1)
2675 output_operand_lossage ("invalid %%J code");
2676 else
a0466a68
RK
2677 /* If we want bit 31, write a shift count of zero, not 32. */
2678 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
2679 return;
2680
9854d9ed
RK
2681 case 'k':
2682 /* X must be a constant. Write the 1's complement of the
2683 constant. */
9878760c 2684 if (! INT_P (x))
9854d9ed 2685 output_operand_lossage ("invalid %%k value");
9878760c 2686
9854d9ed 2687 fprintf (file, "%d", ~ INT_LOWPART (x));
9878760c
RK
2688 return;
2689
9854d9ed
RK
2690 case 'L':
2691 /* Write second word of DImode or DFmode reference. Works on register
2692 or non-indexed memory only. */
2693 if (GET_CODE (x) == REG)
5ebfb2ba 2694 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
2695 else if (GET_CODE (x) == MEM)
2696 {
2697 /* Handle possible auto-increment. Since it is pre-increment and
2698 we have already done it, we can just use an offset of four. */
2699 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2700 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 2701 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
9854d9ed 2702 else
a54d04b7 2703 output_address (plus_constant (XEXP (x, 0), 4));
ba5e43aa 2704 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
2705 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
2706 reg_names[SMALL_DATA_REG]);
9854d9ed 2707 }
9878760c 2708 return;
9854d9ed 2709
9878760c
RK
2710 case 'm':
2711 /* MB value for a mask operand. */
2712 if (! mask_operand (x, VOIDmode))
2713 output_operand_lossage ("invalid %%m value");
2714
2715 val = INT_LOWPART (x);
2716
2717 /* If the high bit is set and the low bit is not, the value is zero.
2718 If the high bit is zero, the value is the first 1 bit we find from
2719 the left. */
2720 if (val < 0 && (val & 1) == 0)
2721 {
19d2d16f 2722 putc ('0', file);
9878760c
RK
2723 return;
2724 }
2725 else if (val >= 0)
2726 {
2727 for (i = 1; i < 32; i++)
2728 if ((val <<= 1) < 0)
2729 break;
2730 fprintf (file, "%d", i);
2731 return;
2732 }
2733
2734 /* Otherwise, look for the first 0 bit from the right. The result is its
2735 number plus 1. We know the low-order bit is one. */
2736 for (i = 0; i < 32; i++)
2737 if (((val >>= 1) & 1) == 0)
2738 break;
2739
a260abc9 2740 /* If we ended in ...01, i would be 0. The correct value is 31, so
9878760c
RK
2741 we want 31 - i. */
2742 fprintf (file, "%d", 31 - i);
2743 return;
2744
2745 case 'M':
2746 /* ME value for a mask operand. */
2747 if (! mask_operand (x, VOIDmode))
a260abc9 2748 output_operand_lossage ("invalid %%M value");
9878760c
RK
2749
2750 val = INT_LOWPART (x);
2751
2752 /* If the low bit is set and the high bit is not, the value is 31.
2753 If the low bit is zero, the value is the first 1 bit we find from
2754 the right. */
2755 if ((val & 1) && val >= 0)
2756 {
76229ac8 2757 fputs ("31", file);
9878760c
RK
2758 return;
2759 }
2760 else if ((val & 1) == 0)
2761 {
2762 for (i = 0; i < 32; i++)
2763 if ((val >>= 1) & 1)
2764 break;
2765
a260abc9 2766 /* If we had ....10, i would be 0. The result should be
9878760c
RK
2767 30, so we need 30 - i. */
2768 fprintf (file, "%d", 30 - i);
2769 return;
2770 }
2771
2772 /* Otherwise, look for the first 0 bit from the left. The result is its
2773 number minus 1. We know the high-order bit is one. */
2774 for (i = 0; i < 32; i++)
2775 if ((val <<= 1) >= 0)
2776 break;
2777
2778 fprintf (file, "%d", i);
2779 return;
2780
9878760c
RK
2781 case 'N':
2782 /* Write the number of elements in the vector times 4. */
2783 if (GET_CODE (x) != PARALLEL)
2784 output_operand_lossage ("invalid %%N value");
2785
2786 fprintf (file, "%d", XVECLEN (x, 0) * 4);
2787 return;
2788
2789 case 'O':
2790 /* Similar, but subtract 1 first. */
2791 if (GET_CODE (x) != PARALLEL)
2792 output_operand_lossage ("invalid %%N value");
2793
2794 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
2795 return;
2796
9854d9ed
RK
2797 case 'p':
2798 /* X is a CONST_INT that is a power of two. Output the logarithm. */
2799 if (! INT_P (x)
2800 || (i = exact_log2 (INT_LOWPART (x))) < 0)
2801 output_operand_lossage ("invalid %%p value");
2802
2803 fprintf (file, "%d", i);
2804 return;
2805
9878760c
RK
2806 case 'P':
2807 /* The operand must be an indirect memory reference. The result
2808 is the register number. */
2809 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
2810 || REGNO (XEXP (x, 0)) >= 32)
2811 output_operand_lossage ("invalid %%P value");
2812
2813 fprintf (file, "%d", REGNO (XEXP (x, 0)));
2814 return;
2815
9854d9ed
RK
2816 case 'R':
2817 /* X is a CR register. Print the mask for `mtcrf'. */
2818 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2819 output_operand_lossage ("invalid %%R value");
2820 else
2821 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
9878760c 2822 return;
9854d9ed
RK
2823
2824 case 's':
2825 /* Low 5 bits of 32 - value */
2826 if (! INT_P (x))
2827 output_operand_lossage ("invalid %%s value");
2828
2829 fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
9878760c 2830 return;
9854d9ed 2831
a260abc9
DE
2832 case 'S':
2833 /* PowerPC64 mask position. All 0's and all 1's are excluded.
2834 CONST_INT 32-bit mask is considered sign-extended so any
2835 transition must occur within the CONST_INT, not on the boundary. */
2836 if (! mask64_operand (x, VOIDmode))
2837 output_operand_lossage ("invalid %%S value");
2838
2839 val = INT_LOWPART (x);
2840
2841 if (val & 1) /* Clear Left */
2842 {
a238cd8b
DE
2843 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
2844 if (!((val >>= 1) & 1))
2845 break;
a260abc9 2846
a238cd8b
DE
2847#if HOST_BITS_PER_WIDE_INT == 32
2848 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
2849 {
2850 val = CONST_DOUBLE_HIGH (x);
2851
2852 if (val == 0)
2853 --i;
2854 else
2855 for (i = 32; i < 64; i++)
2856 if (!((val >>= 1) & 1))
2857 break;
2858 }
a260abc9 2859#endif
a238cd8b
DE
2860 /* i = index of last set bit from right
2861 mask begins at 63 - i from left */
2862 if (i > 63)
2863 output_operand_lossage ("%%S computed all 1's mask");
a260abc9
DE
2864 fprintf (file, "%d", 63 - i);
2865 return;
2866 }
2867 else /* Clear Right */
2868 {
a238cd8b
DE
2869 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
2870 if ((val >>= 1) & 1)
2871 break;
a260abc9 2872
a238cd8b 2873#if HOST_BITS_PER_WIDE_INT == 32
a260abc9
DE
2874 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
2875 {
a238cd8b 2876 val = CONST_DOUBLE_HIGH (x);
a260abc9 2877
a238cd8b 2878 if (val == (HOST_WIDE_INT) -1)
a260abc9 2879 --i;
a260abc9 2880 else
a238cd8b
DE
2881 for (i = 32; i < 64; i++)
2882 if ((val >>= 1) & 1)
a260abc9
DE
2883 break;
2884 }
2885#endif
a238cd8b
DE
2886 /* i = index of last clear bit from right
2887 mask ends at 62 - i from left */
2888 if (i > 62)
2889 output_operand_lossage ("%%S computed all 0's mask");
2890 fprintf (file, "%d", 62 - i);
a260abc9
DE
2891 return;
2892 }
2893
9878760c
RK
2894 case 't':
2895 /* Write 12 if this jump operation will branch if true, 4 otherwise.
2896 All floating-point operations except NE branch true and integer
2897 EQ, LT, GT, LTU and GTU also branch true. */
2898 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2899 output_operand_lossage ("invalid %%t value");
2900
2901 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2902 && GET_CODE (x) != NE)
2903 || GET_CODE (x) == EQ
2904 || GET_CODE (x) == LT || GET_CODE (x) == GT
2905 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 2906 fputs ("12", file);
9878760c 2907 else
76229ac8 2908 putc ('4', file);
9878760c
RK
2909 return;
2910
2911 case 'T':
2912 /* Opposite of 't': write 4 if this jump operation will branch if true,
2913 12 otherwise. */
2914 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2915 output_operand_lossage ("invalid %%t value");
2916
2917 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2918 && GET_CODE (x) != NE)
2919 || GET_CODE (x) == EQ
2920 || GET_CODE (x) == LT || GET_CODE (x) == GT
2921 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 2922 putc ('4', file);
9878760c 2923 else
76229ac8 2924 fputs ("12", file);
9878760c
RK
2925 return;
2926
9854d9ed 2927 case 'u':
802a0058 2928 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
2929 if (! INT_P (x))
2930 output_operand_lossage ("invalid %%u value");
9878760c 2931
76229ac8 2932 fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
2933 return;
2934
802a0058
MM
2935 case 'v':
2936 /* High-order 16 bits of constant for use in signed operand. */
2937 if (! INT_P (x))
2938 output_operand_lossage ("invalid %%v value");
2939
2940 {
2941 int value = (INT_LOWPART (x) >> 16) & 0xffff;
2942
2943 /* Solaris assembler doesn't like lis 0,0x80000 */
2944 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
2945 fprintf (file, "%d", value | (~0 << 16));
2946 else
2947 fprintf (file, "0x%x", value);
2948 return;
2949 }
2950
9854d9ed
RK
2951 case 'U':
2952 /* Print `u' if this has an auto-increment or auto-decrement. */
2953 if (GET_CODE (x) == MEM
2954 && (GET_CODE (XEXP (x, 0)) == PRE_INC
2955 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 2956 putc ('u', file);
9854d9ed 2957 return;
9878760c 2958
e0cd0770
JC
2959 case 'V':
2960 /* Print the trap code for this operand. */
2961 switch (GET_CODE (x))
2962 {
2963 case EQ:
2964 fputs ("eq", file); /* 4 */
2965 break;
2966 case NE:
2967 fputs ("ne", file); /* 24 */
2968 break;
2969 case LT:
2970 fputs ("lt", file); /* 16 */
2971 break;
2972 case LE:
2973 fputs ("le", file); /* 20 */
2974 break;
2975 case GT:
2976 fputs ("gt", file); /* 8 */
2977 break;
2978 case GE:
2979 fputs ("ge", file); /* 12 */
2980 break;
2981 case LTU:
2982 fputs ("llt", file); /* 2 */
2983 break;
2984 case LEU:
2985 fputs ("lle", file); /* 6 */
2986 break;
2987 case GTU:
2988 fputs ("lgt", file); /* 1 */
2989 break;
2990 case GEU:
2991 fputs ("lge", file); /* 5 */
2992 break;
2993 default:
2994 abort ();
2995 }
2996 break;
2997
9854d9ed
RK
2998 case 'w':
2999 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
3000 normally. */
3001 if (INT_P (x))
3002 fprintf (file, "%d",
3003 (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
3004 else
3005 print_operand (file, x, 0);
9878760c
RK
3006 return;
3007
9854d9ed
RK
3008 case 'W':
3009 /* If constant, low-order 16 bits of constant, unsigned.
3010 Otherwise, write normally. */
3011 if (INT_P (x))
3012 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
3013 else
3014 print_operand (file, x, 0);
3015 return;
9878760c 3016
9854d9ed
RK
3017 case 'X':
3018 if (GET_CODE (x) == MEM
3019 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
76229ac8 3020 putc ('x', file);
9854d9ed 3021 return;
9878760c 3022
9854d9ed
RK
3023 case 'Y':
3024 /* Like 'L', for third word of TImode */
3025 if (GET_CODE (x) == REG)
5ebfb2ba 3026 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 3027 else if (GET_CODE (x) == MEM)
9878760c 3028 {
9854d9ed
RK
3029 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3030 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 3031 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 3032 else
a54d04b7 3033 output_address (plus_constant (XEXP (x, 0), 8));
ba5e43aa 3034 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
3035 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3036 reg_names[SMALL_DATA_REG]);
9878760c
RK
3037 }
3038 return;
9854d9ed 3039
9878760c 3040 case 'z':
b4ac57ab
RS
3041 /* X is a SYMBOL_REF. Write out the name preceded by a
3042 period and without any trailing data in brackets. Used for function
4d30c363
MM
3043 names. If we are configured for System V (or the embedded ABI) on
3044 the PowerPC, do not emit the period, since those systems do not use
3045 TOCs and the like. */
9878760c
RK
3046 if (GET_CODE (x) != SYMBOL_REF)
3047 abort ();
3048
b6c9286a
MM
3049 if (XSTR (x, 0)[0] != '.')
3050 {
3051 switch (DEFAULT_ABI)
3052 {
3053 default:
3054 abort ();
3055
3056 case ABI_AIX:
3057 putc ('.', file);
3058 break;
3059
3060 case ABI_V4:
3061 case ABI_AIX_NODESC:
c81bebd7 3062 case ABI_SOLARIS:
b6c9286a
MM
3063 break;
3064
3065 case ABI_NT:
3066 fputs ("..", file);
3067 break;
3068 }
3069 }
9878760c
RK
3070 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
3071 return;
3072
9854d9ed
RK
3073 case 'Z':
3074 /* Like 'L', for last word of TImode. */
3075 if (GET_CODE (x) == REG)
5ebfb2ba 3076 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
3077 else if (GET_CODE (x) == MEM)
3078 {
3079 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3080 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 3081 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 3082 else
a54d04b7 3083 output_address (plus_constant (XEXP (x, 0), 12));
ba5e43aa 3084 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
3085 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3086 reg_names[SMALL_DATA_REG]);
9854d9ed 3087 }
5c23c401 3088 return;
9854d9ed 3089
9878760c
RK
3090 case 0:
3091 if (GET_CODE (x) == REG)
3092 fprintf (file, "%s", reg_names[REGNO (x)]);
3093 else if (GET_CODE (x) == MEM)
3094 {
3095 /* We need to handle PRE_INC and PRE_DEC here, since we need to
3096 know the width from the mode. */
3097 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
3098 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
3099 REGNO (XEXP (XEXP (x, 0), 0)));
3100 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
3101 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
3102 REGNO (XEXP (XEXP (x, 0), 0)));
3103 else
a54d04b7 3104 output_address (XEXP (x, 0));
9878760c
RK
3105 }
3106 else
a54d04b7 3107 output_addr_const (file, x);
a85d226b 3108 return;
9878760c
RK
3109
3110 default:
3111 output_operand_lossage ("invalid %%xn code");
3112 }
3113}
3114\f
3115/* Print the address of an operand. */
3116
3117void
3118print_operand_address (file, x)
3119 FILE *file;
3120 register rtx x;
3121{
3122 if (GET_CODE (x) == REG)
4697a36c 3123 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
24f30767 3124 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST || GET_CODE (x) == LABEL_REF)
9878760c
RK
3125 {
3126 output_addr_const (file, x);
ba5e43aa 3127 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
3128 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3129 reg_names[SMALL_DATA_REG]);
7509c759 3130
4697a36c 3131#ifdef TARGET_NO_TOC
7509c759 3132 else if (TARGET_NO_TOC)
4697a36c 3133 ;
4697a36c 3134#endif
7509c759 3135 else
4697a36c 3136 fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 ]);
9878760c
RK
3137 }
3138 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
3139 {
3140 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
3141 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
3142 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 3143 else
4697a36c
MM
3144 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
3145 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
3146 }
3147 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4697a36c
MM
3148 fprintf (file, "%d(%s)", INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3149 else if (TARGET_ELF && !TARGET_64BIT && GET_CODE (x) == LO_SUM
3150 && GET_CODE (XEXP (x, 0)) == REG && CONSTANT_P (XEXP (x, 1)))
3151 {
3152 output_addr_const (file, XEXP (x, 1));
3153 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
3154 }
9878760c
RK
3155 else
3156 abort ();
3157}
3158\f
3159/* This page contains routines that are used to determine what the function
3160 prologue and epilogue code will do and write them out. */
3161
3162/* Return the first fixed-point register that is required to be saved. 32 if
3163 none. */
3164
3165int
3166first_reg_to_save ()
3167{
3168 int first_reg;
3169
3170 /* Find lowest numbered live register. */
3171 for (first_reg = 13; first_reg <= 31; first_reg++)
3172 if (regs_ever_live[first_reg])
3173 break;
3174
e165f3f0 3175 /* If profiling, then we must save/restore every register that contains
9c849d2a 3176 a parameter before/after the .__mcount call. Use registers from 30 down
e165f3f0
RK
3177 to 23 to do this. Don't use the frame pointer in reg 31.
3178
3179 For now, save enough room for all of the parameter registers. */
b6c9286a 3180 if (DEFAULT_ABI == ABI_AIX && profile_flag)
e165f3f0
RK
3181 if (first_reg > 23)
3182 first_reg = 23;
3183
9878760c
RK
3184 return first_reg;
3185}
3186
3187/* Similar, for FP regs. */
3188
3189int
3190first_fp_reg_to_save ()
3191{
3192 int first_reg;
3193
3194 /* Find lowest numbered live register. */
3195 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
3196 if (regs_ever_live[first_reg])
3197 break;
3198
3199 return first_reg;
3200}
3201
9878760c
RK
3202/* Return non-zero if this function makes calls. */
3203
3204int
3205rs6000_makes_calls ()
3206{
3207 rtx insn;
3208
38c1f2d7
MM
3209 /* If we are profiling, we will be making a call to __mcount.
3210 Under the System V ABI's, we store the LR directly, so
3211 we don't need to do it here. */
3212 if (DEFAULT_ABI == ABI_AIX && profile_flag)
0c61c946
RK
3213 return 1;
3214
9878760c
RK
3215 for (insn = get_insns (); insn; insn = next_insn (insn))
3216 if (GET_CODE (insn) == CALL_INSN)
3217 return 1;
3218
3219 return 0;
3220}
3221
4697a36c
MM
3222\f
3223/* Calculate the stack information for the current function. This is
3224 complicated by having two separate calling sequences, the AIX calling
3225 sequence and the V.4 calling sequence.
3226
3227 AIX stack frames look like:
a260abc9 3228 32-bit 64-bit
4697a36c 3229 SP----> +---------------------------------------+
a260abc9 3230 | back chain to caller | 0 0
4697a36c 3231 +---------------------------------------+
a260abc9 3232 | saved CR | 4 8 (8-11)
4697a36c 3233 +---------------------------------------+
a260abc9 3234 | saved LR | 8 16
4697a36c 3235 +---------------------------------------+
a260abc9 3236 | reserved for compilers | 12 24
4697a36c 3237 +---------------------------------------+
a260abc9 3238 | reserved for binders | 16 32
4697a36c 3239 +---------------------------------------+
a260abc9 3240 | saved TOC pointer | 20 40
4697a36c 3241 +---------------------------------------+
a260abc9 3242 | Parameter save area (P) | 24 48
4697a36c 3243 +---------------------------------------+
a260abc9 3244 | Alloca space (A) | 24+P etc.
802a0058 3245 +---------------------------------------+
a7df97e6 3246 | Local variable space (L) | 24+P+A
4697a36c 3247 +---------------------------------------+
a7df97e6 3248 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 3249 +---------------------------------------+
a7df97e6 3250 | Save area for GP registers (G) | 24+P+A+X+L
4697a36c 3251 +---------------------------------------+
a7df97e6 3252 | Save area for FP registers (F) | 24+P+A+X+L+G
4697a36c
MM
3253 +---------------------------------------+
3254 old SP->| back chain to caller's caller |
3255 +---------------------------------------+
3256
3257 V.4 stack frames look like:
3258
3259 SP----> +---------------------------------------+
3260 | back chain to caller | 0
3261 +---------------------------------------+
5eb387b8 3262 | caller's saved LR | 4
4697a36c
MM
3263 +---------------------------------------+
3264 | Parameter save area (P) | 8
3265 +---------------------------------------+
a7df97e6
MM
3266 | Alloca space (A) | 8+P
3267 +---------------------------------------+
3268 | Varargs save area (V) | 8+P+A
3269 +---------------------------------------+
3270 | Local variable space (L) | 8+P+A+V
3271 +---------------------------------------+
3272 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 3273 +---------------------------------------+
a7df97e6
MM
3274 | saved CR (C) | 8+P+A+V+L+X
3275 +---------------------------------------+
3276 | Save area for GP registers (G) | 8+P+A+V+L+X+C
3277 +---------------------------------------+
3278 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
4697a36c
MM
3279 +---------------------------------------+
3280 old SP->| back chain to caller's caller |
3281 +---------------------------------------+
b6c9286a
MM
3282
3283
3284 A PowerPC Windows/NT frame looks like:
3285
3286 SP----> +---------------------------------------+
3287 | back chain to caller | 0
3288 +---------------------------------------+
3289 | reserved | 4
3290 +---------------------------------------+
3291 | reserved | 8
3292 +---------------------------------------+
3293 | reserved | 12
3294 +---------------------------------------+
3295 | reserved | 16
3296 +---------------------------------------+
3297 | reserved | 20
3298 +---------------------------------------+
3299 | Parameter save area (P) | 24
3300 +---------------------------------------+
a7df97e6
MM
3301 | Alloca space (A) | 24+P
3302 +---------------------------------------+
3303 | Local variable space (L) | 24+P+A
3304 +---------------------------------------+
3305 | Float/int conversion temporary (X) | 24+P+A+L
b6c9286a 3306 +---------------------------------------+
a7df97e6
MM
3307 | Save area for FP registers (F) | 24+P+A+L+X
3308 +---------------------------------------+
3309 | Possible alignment area (Y) | 24+P+A+L+X+F
3310 +---------------------------------------+
3311 | Save area for GP registers (G) | 24+P+A+L+X+F+Y
3312 +---------------------------------------+
3313 | Save area for CR (C) | 24+P+A+L+X+F+Y+G
3314 +---------------------------------------+
3315 | Save area for TOC (T) | 24+P+A+L+X+F+Y+G+C
3316 +---------------------------------------+
3317 | Save area for LR (R) | 24+P+A+L+X+F+Y+G+C+T
b6c9286a
MM
3318 +---------------------------------------+
3319 old SP->| back chain to caller's caller |
3320 +---------------------------------------+
3321
3322 For NT, there is no specific order to save the registers, but in
3323 order to support __builtin_return_address, the save area for the
3324 link register needs to be in a known place, so we use -4 off of the
3325 old SP. To support calls through pointers, we also allocate a
3326 fixed slot to store the TOC, -8 off the old SP. */
4697a36c 3327
61b2fbe7
MM
3328#ifndef ABI_STACK_BOUNDARY
3329#define ABI_STACK_BOUNDARY STACK_BOUNDARY
3330#endif
3331
4697a36c
MM
3332rs6000_stack_t *
3333rs6000_stack_info ()
3334{
3335 static rs6000_stack_t info, zero_info;
3336 rs6000_stack_t *info_ptr = &info;
a260abc9 3337 int reg_size = TARGET_32BIT ? 4 : 8;
24d304eb 3338 enum rs6000_abi abi;
b6c9286a 3339 int total_raw_size;
4697a36c
MM
3340
3341 /* Zero all fields portably */
3342 info = zero_info;
3343
3344 /* Select which calling sequence */
b6c9286a 3345 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 3346
4697a36c
MM
3347 /* Calculate which registers need to be saved & save area size */
3348 info_ptr->first_gp_reg_save = first_reg_to_save ();
3349 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
3350
3351 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
3352 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
3353
3354 /* Does this function call anything? */
3355 info_ptr->calls_p = rs6000_makes_calls ();
3356
62c0fb87 3357 /* Allocate space to save the toc. */
82280d5e 3358 if (abi == ABI_NT && info_ptr->calls_p)
b6c9286a
MM
3359 {
3360 info_ptr->toc_save_p = 1;
3361 info_ptr->toc_size = reg_size;
3362 }
3363
802a0058
MM
3364 /* Does this machine need the float/int conversion area? */
3365 info_ptr->fpmem_p = regs_ever_live[FPMEM_REGNUM];
3366
b6c9286a
MM
3367 /* If this is main and we need to call a function to set things up,
3368 save main's arguments around the call. */
c81bebd7
MM
3369#ifdef TARGET_EABI
3370 if (TARGET_EABI)
3371#endif
b6c9286a 3372 {
30ccf55d
MS
3373 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0
3374 && DECL_CONTEXT (current_function_decl) == NULL_TREE)
b6c9286a 3375 {
c81bebd7 3376 info_ptr->main_p = 1;
b6c9286a 3377
c81bebd7
MM
3378#ifdef NAME__MAIN
3379 info_ptr->calls_p = 1;
b6c9286a 3380
c81bebd7 3381 if (DECL_ARGUMENTS (current_function_decl))
b6c9286a 3382 {
c81bebd7
MM
3383 int i;
3384 tree arg;
3385
3386 info_ptr->main_save_p = 1;
3387 info_ptr->main_size = 0;
3388
3389 for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl));
3390 arg != NULL_TREE && i < 8;
3391 (arg = TREE_CHAIN (arg)), i++)
3392 {
3393 info_ptr->main_size += reg_size;
3394 }
b6c9286a 3395 }
b6c9286a 3396#endif
c81bebd7 3397 }
b6c9286a
MM
3398 }
3399
c81bebd7 3400
4697a36c 3401 /* Determine if we need to save the link register */
38c1f2d7
MM
3402 if (regs_ever_live[65]
3403 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4697a36c
MM
3404#ifdef TARGET_RELOCATABLE
3405 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
3406#endif
3407 || (info_ptr->first_fp_reg_save != 64
3408 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
24d304eb 3409 || (abi == ABI_V4 && current_function_calls_alloca)
c81bebd7 3410 || (abi == ABI_SOLARIS && current_function_calls_alloca)
4697a36c
MM
3411 || info_ptr->calls_p)
3412 {
3413 info_ptr->lr_save_p = 1;
3414 regs_ever_live[65] = 1;
b6c9286a
MM
3415 if (abi == ABI_NT)
3416 info_ptr->lr_size = reg_size;
4697a36c
MM
3417 }
3418
3419 /* Determine if we need to save the condition code registers */
3420 if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
3421 {
3422 info_ptr->cr_save_p = 1;
c81bebd7 3423 if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
4697a36c
MM
3424 info_ptr->cr_size = reg_size;
3425 }
3426
92834d7d
BM
3427 /* Ensure that fp_save_offset will be aligned to an 8-byte boundary. */
3428 if (info_ptr->fpmem_p)
3429 {
3430 info_ptr->gp_size = RS6000_ALIGN (info_ptr->gp_size, 8);
3431 info_ptr->main_size = RS6000_ALIGN (info_ptr->main_size, 8);
3432 }
3433
4697a36c
MM
3434 /* Determine various sizes */
3435 info_ptr->reg_size = reg_size;
3436 info_ptr->fixed_size = RS6000_SAVE_AREA;
3437 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3
DE
3438 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
3439 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
802a0058 3440 info_ptr->fpmem_size = (info_ptr->fpmem_p) ? 8 : 0;
189e03e3 3441 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
b6c9286a
MM
3442 + info_ptr->gp_size
3443 + info_ptr->cr_size
3444 + info_ptr->lr_size
3445 + info_ptr->toc_size
3446 + info_ptr->main_size, 8);
3447
3448 total_raw_size = (info_ptr->vars_size
3449 + info_ptr->parm_size
802a0058 3450 + info_ptr->fpmem_size
b6c9286a
MM
3451 + info_ptr->save_size
3452 + info_ptr->varargs_size
3453 + info_ptr->fixed_size);
3454
189e03e3 3455 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
4697a36c 3456
db72d7a1
DE
3457 /* Determine if we need to allocate any stack frame:
3458
3459 For AIX we need to push the stack if a frame pointer is needed (because
3460 the stack might be dynamically adjusted), if we are debugging, if we
3461 make calls, or if the sum of fp_save, gp_save, fpmem, and local variables
3462 are more than the space needed to save all non-volatile registers:
3463 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 19*8 = 296
4697a36c
MM
3464
3465 For V.4 we don't have the stack cushion that AIX uses, but assume that
3466 the debugger can handle stackless frames. */
3467
3468 if (info_ptr->calls_p)
3469 info_ptr->push_p = 1;
3470
c81bebd7 3471 else if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
b6c9286a 3472 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
1a986152
GK
3473 || (abi == ABI_NT ? info_ptr->lr_save_p
3474 : info_ptr->calls_p));
4697a36c
MM
3475
3476 else
3477 info_ptr->push_p = (frame_pointer_needed
3478 || write_symbols != NO_DEBUG
a260abc9 3479 || ((total_raw_size - info_ptr->fixed_size)
db72d7a1 3480 > (TARGET_32BIT ? 220 : 296)));
4697a36c
MM
3481
3482 /* Calculate the offsets */
24d304eb 3483 switch (abi)
4697a36c 3484 {
b6c9286a 3485 case ABI_NONE:
24d304eb 3486 default:
b6c9286a
MM
3487 abort ();
3488
3489 case ABI_AIX:
3490 case ABI_AIX_NODESC:
3491 info_ptr->fp_save_offset = - info_ptr->fp_size;
3492 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
3493 info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size;
a260abc9
DE
3494 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
3495 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
3496 break;
3497
3498 case ABI_V4:
c81bebd7 3499 case ABI_SOLARIS:
b6c9286a
MM
3500 info_ptr->fp_save_offset = - info_ptr->fp_size;
3501 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6
MM
3502 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
3503 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
3504 info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->main_size;
b6c9286a
MM
3505 info_ptr->lr_save_offset = reg_size;
3506 break;
3507
3508 case ABI_NT:
a260abc9 3509 info_ptr->lr_save_offset = -reg_size;
b6c9286a
MM
3510 info_ptr->toc_save_offset = info_ptr->lr_save_offset - info_ptr->lr_size;
3511 info_ptr->cr_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
3512 info_ptr->gp_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size;
3513 info_ptr->fp_save_offset = info_ptr->gp_save_offset - info_ptr->fp_size;
3514 if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0)
a260abc9 3515 info_ptr->fp_save_offset -= reg_size;
b6c9286a
MM
3516
3517 info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size;
24d304eb 3518 break;
4697a36c
MM
3519 }
3520
a7df97e6 3521 if (info_ptr->fpmem_p)
db72d7a1
DE
3522 {
3523 info_ptr->fpmem_offset = info_ptr->main_save_offset - info_ptr->fpmem_size;
3524 rs6000_fpmem_size = info_ptr->fpmem_size;
a260abc9
DE
3525 rs6000_fpmem_offset = (info_ptr->push_p
3526 ? info_ptr->total_size + info_ptr->fpmem_offset
3527 : info_ptr->fpmem_offset);
db72d7a1
DE
3528 }
3529 else
3530 info_ptr->fpmem_offset = 0;
a7df97e6 3531
4697a36c 3532 /* Zero offsets if we're not saving those registers */
a6c2a102 3533 if (info_ptr->fp_size == 0)
4697a36c
MM
3534 info_ptr->fp_save_offset = 0;
3535
a6c2a102 3536 if (info_ptr->gp_size == 0)
4697a36c
MM
3537 info_ptr->gp_save_offset = 0;
3538
3539 if (!info_ptr->lr_save_p)
3540 info_ptr->lr_save_offset = 0;
3541
3542 if (!info_ptr->cr_save_p)
3543 info_ptr->cr_save_offset = 0;
3544
b6c9286a
MM
3545 if (!info_ptr->toc_save_p)
3546 info_ptr->toc_save_offset = 0;
3547
3548 if (!info_ptr->main_save_p)
3549 info_ptr->main_save_offset = 0;
3550
4697a36c
MM
3551 return info_ptr;
3552}
3553
3554void
3555debug_stack_info (info)
3556 rs6000_stack_t *info;
9878760c 3557{
24d304eb
RK
3558 char *abi_string;
3559
4697a36c
MM
3560 if (!info)
3561 info = rs6000_stack_info ();
3562
3563 fprintf (stderr, "\nStack information for function %s:\n",
3564 ((current_function_decl && DECL_NAME (current_function_decl))
3565 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
3566 : "<unknown>"));
3567
24d304eb
RK
3568 switch (info->abi)
3569 {
b6c9286a
MM
3570 default: abi_string = "Unknown"; break;
3571 case ABI_NONE: abi_string = "NONE"; break;
3572 case ABI_AIX: abi_string = "AIX"; break;
3573 case ABI_AIX_NODESC: abi_string = "AIX"; break;
3574 case ABI_V4: abi_string = "V.4"; break;
c81bebd7 3575 case ABI_SOLARIS: abi_string = "Solaris"; break;
b6c9286a 3576 case ABI_NT: abi_string = "NT"; break;
24d304eb
RK
3577 }
3578
3579 fprintf (stderr, "\tABI = %5s\n", abi_string);
3580
4697a36c
MM
3581 if (info->first_gp_reg_save != 32)
3582 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
3583
3584 if (info->first_fp_reg_save != 64)
3585 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 3586
4697a36c
MM
3587 if (info->lr_save_p)
3588 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 3589
4697a36c
MM
3590 if (info->cr_save_p)
3591 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
3592
b6c9286a
MM
3593 if (info->toc_save_p)
3594 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
3595
4697a36c
MM
3596 if (info->push_p)
3597 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
3598
3599 if (info->calls_p)
3600 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
3601
b6c9286a
MM
3602 if (info->main_p)
3603 fprintf (stderr, "\tmain_p = %5d\n", info->main_p);
3604
3605 if (info->main_save_p)
3606 fprintf (stderr, "\tmain_save_p = %5d\n", info->main_save_p);
3607
802a0058
MM
3608 if (info->fpmem_p)
3609 fprintf (stderr, "\tfpmem_p = %5d\n", info->fpmem_p);
3610
4697a36c
MM
3611 if (info->gp_save_offset)
3612 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
3613
3614 if (info->fp_save_offset)
3615 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
3616
3617 if (info->lr_save_offset)
3618 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
3619
3620 if (info->cr_save_offset)
3621 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
3622
b6c9286a
MM
3623 if (info->toc_save_offset)
3624 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
3625
4697a36c
MM
3626 if (info->varargs_save_offset)
3627 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
3628
b6c9286a
MM
3629 if (info->main_save_offset)
3630 fprintf (stderr, "\tmain_save_offset = %5d\n", info->main_save_offset);
3631
802a0058
MM
3632 if (info->fpmem_offset)
3633 fprintf (stderr, "\tfpmem_offset = %5d\n", info->fpmem_offset);
3634
4697a36c
MM
3635 if (info->total_size)
3636 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
3637
3638 if (info->varargs_size)
3639 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
3640
3641 if (info->vars_size)
3642 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
3643
3644 if (info->parm_size)
3645 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
3646
802a0058
MM
3647 if (info->fpmem_size)
3648 fprintf (stderr, "\tfpmem_size = %5d\n", info->fpmem_size);
3649
4697a36c
MM
3650 if (info->fixed_size)
3651 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
3652
3653 if (info->gp_size)
3654 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
3655
3656 if (info->fp_size)
3657 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
3658
b6c9286a
MM
3659 if (info->lr_size)
3660 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
3661
4697a36c
MM
3662 if (info->cr_size)
3663 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
3664
b6c9286a
MM
3665 if (info->toc_size)
3666 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
3667
3668 if (info->main_size)
3669 fprintf (stderr, "\tmain_size = %5d\n", info->main_size);
3670
4697a36c
MM
3671 if (info->save_size)
3672 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
3673
3674 if (info->reg_size != 4)
3675 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
3676
3677 fprintf (stderr, "\n");
9878760c 3678}
4697a36c 3679\f
c7ca610e
RK
3680/* Write out an instruction to load the TOC_TABLE address into register 30.
3681 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
3682 a constant pool. */
3683
3684void
38c1f2d7 3685rs6000_output_load_toc_table (file, reg)
c7ca610e 3686 FILE *file;
38c1f2d7 3687 int reg;
c7ca610e
RK
3688{
3689 char buf[256];
3690
3691#ifdef USING_SVR4_H
3692 if (TARGET_RELOCATABLE)
3693 {
3694 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3695 fprintf (file, "\tbl ");
3696 assemble_name (file, buf);
3697 fprintf (file, "\n");
3698
38c1f2d7
MM
3699 /* possibly create the toc section */
3700 if (!toc_initialized)
3701 {
3702 toc_section ();
3703 function_section (current_function_decl);
3704 }
3705
3706 /* If not first call in this function, we need to put the
3707 different between .LCTOC1 and the address we get to right
3708 after the bl. It will mess up disassembling the instructions
3709 but that can't be helped. We will later need to bias the
3710 address before loading. */
3711 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
3712 {
a260abc9 3713 char *init_ptr = TARGET_32BIT ? ".long" : ".quad";
38c1f2d7
MM
3714 char *buf_ptr;
3715
3716 ASM_OUTPUT_INTERNAL_LABEL (file, "LCL", rs6000_pic_labelno);
3717
3718 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
3719 STRIP_NAME_ENCODING (buf_ptr, buf);
3720 fprintf (file, "\t%s %s-", init_ptr, buf_ptr);
3721
3722 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3723 fprintf (file, "%s\n", buf_ptr);
3724 }
3725
c7ca610e 3726 ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
38c1f2d7
MM
3727 fprintf (file, "\tmflr %s\n", reg_names[reg]);
3728
3729 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
a260abc9
DE
3730 asm_fprintf(file, "\t{cal|la} %s,%d(%s)\n", reg_names[reg],
3731 (TARGET_32BIT ? 4 : 8), reg_names[reg]);
c7ca610e 3732
a260abc9
DE
3733 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s,(" : "\tld %s,(",
3734 reg_names[0]);
38c1f2d7 3735 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
c7ca610e 3736 assemble_name (file, buf);
a260abc9 3737 fputs ("-", file);
c7ca610e
RK
3738 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3739 assemble_name (file, buf);
38c1f2d7 3740 fprintf (file, ")(%s)\n", reg_names[reg]);
c7ca610e 3741 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
38c1f2d7 3742 reg_names[reg], reg_names[0], reg_names[reg]);
c7ca610e
RK
3743 rs6000_pic_labelno++;
3744 }
3745 else if (!TARGET_64BIT)
3746 {
3747 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
a260abc9 3748 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[reg]);
c7ca610e 3749 assemble_name (file, buf);
dfdfa60f 3750 fputs ("@ha\n", file);
a260abc9
DE
3751 asm_fprintf (file, "\t{cal|la} %s,", reg_names[reg]);
3752 assemble_name (file, buf);
3753 asm_fprintf (file, "@l(%s)\n", reg_names[reg]);
c7ca610e
RK
3754 }
3755 else
3756 abort ();
3757
3758#else /* !USING_SVR4_H */
3759 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
13ded975
DE
3760 asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,",
3761 reg_names[reg]);
c7ca610e
RK
3762 assemble_name (file, buf);
3763 asm_fprintf (file, "(%s)\n", reg_names[2]);
3764#endif /* USING_SVR4_H */
3765}
3766
38c1f2d7
MM
3767\f
3768/* Emit the correct code for allocating stack space. If COPY_R12, make sure a copy
3769 of the old frame is left in r12. */
3770
3771void
3772rs6000_allocate_stack_space (file, size, copy_r12)
3773 FILE *file;
3774 int size;
3775 int copy_r12;
3776{
3777 int neg_size = -size;
3778 if (TARGET_UPDATE)
3779 {
3780 if (size < 32767)
3781 asm_fprintf (file,
3782 (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n",
3783 reg_names[1], neg_size, reg_names[1]);
3784 else
3785 {
3786 if (copy_r12)
3787 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3788
3789 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
3790 reg_names[0], (neg_size >> 16) & 0xffff,
3791 reg_names[0], reg_names[0], neg_size & 0xffff);
3792 asm_fprintf (file,
3793 (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n",
3794 reg_names[1], reg_names[1], reg_names[0]);
3795 }
3796 }
3797 else
3798 {
3799 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3800 if (size < 32767)
aa4201ad 3801 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
a260abc9 3802 reg_names[1], neg_size, reg_names[1]);
38c1f2d7
MM
3803 else
3804 {
3805 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
3806 reg_names[0], (neg_size >> 16) & 0xffff,
3807 reg_names[0], reg_names[0], neg_size & 0xffff);
3808 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", reg_names[1],
3809 reg_names[0], reg_names[1]);
3810 }
3811
3812 asm_fprintf (file,
3813 (TARGET_32BIT) ? "\t{st|stw} %s,0(%s)\n" : "\tstd %s,0(%s)\n",
3814 reg_names[12], reg_names[1]);
3815 }
3816}
3817
3818\f
9878760c 3819/* Write function prologue. */
9878760c
RK
3820void
3821output_prolog (file, size)
3822 FILE *file;
296b8152 3823 int size ATTRIBUTE_UNUSED;
9878760c 3824{
4697a36c 3825 rs6000_stack_t *info = rs6000_stack_info ();
b6c9286a
MM
3826 int reg_size = info->reg_size;
3827 char *store_reg;
3828 char *load_reg;
979721f8
MM
3829 int sp_reg = 1;
3830 int sp_offset = 0;
b6c9286a 3831
8f802bfb 3832 if (TARGET_32BIT)
b6c9286a 3833 {
8f802bfb
DE
3834 store_reg = "\t{st|stw} %s,%d(%s)\n";
3835 load_reg = "\t{l|lwz} %s,%d(%s)\n";
b6c9286a
MM
3836 }
3837 else
3838 {
8f802bfb
DE
3839 store_reg = "\tstd %s,%d(%s)\n";
3840 load_reg = "\tlld %s,%d(%s)\n";
b6c9286a 3841 }
9878760c 3842
4697a36c
MM
3843 if (TARGET_DEBUG_STACK)
3844 debug_stack_info (info);
9878760c
RK
3845
3846 /* Write .extern for any function we will call to save and restore fp
3847 values. */
b6c9286a 3848 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 3849 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c
MM
3850 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
3851 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
9878760c
RK
3852
3853 /* Write .extern for truncation routines, if needed. */
3854 if (rs6000_trunc_used && ! trunc_defined)
3855 {
e138174b
ILT
3856 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
3857 RS6000_ITRUNC, RS6000_UITRUNC);
9878760c
RK
3858 trunc_defined = 1;
3859 }
4697a36c 3860
c764f757
RK
3861 /* Write .extern for AIX common mode routines, if needed. */
3862 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
3863 {
f6709c70
JW
3864 fputs ("\t.extern __mulh\n", file);
3865 fputs ("\t.extern __mull\n", file);
3866 fputs ("\t.extern __divss\n", file);
3867 fputs ("\t.extern __divus\n", file);
3868 fputs ("\t.extern __quoss\n", file);
3869 fputs ("\t.extern __quous\n", file);
c764f757
RK
3870 common_mode_defined = 1;
3871 }
9878760c 3872
979721f8 3873 /* For V.4, update stack before we do any saving and set back pointer. */
c81bebd7 3874 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
979721f8
MM
3875 {
3876 if (info->total_size < 32767)
38c1f2d7 3877 sp_offset = info->total_size;
979721f8 3878 else
38c1f2d7
MM
3879 sp_reg = 12;
3880 rs6000_allocate_stack_space (file, info->total_size, sp_reg == 12);
979721f8
MM
3881 }
3882
9878760c 3883 /* If we use the link register, get it into r0. */
4697a36c
MM
3884 if (info->lr_save_p)
3885 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
9878760c
RK
3886
3887 /* If we need to save CR, put it into r12. */
979721f8 3888 if (info->cr_save_p && sp_reg != 12)
4697a36c 3889 asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
9878760c
RK
3890
3891 /* Do any required saving of fpr's. If only one or two to save, do it
53322b0c
RK
3892 ourself. Otherwise, call function. Note that since they are statically
3893 linked, we do not need a nop following them. */
4697a36c 3894 if (FP_SAVE_INLINE (info->first_fp_reg_save))
bacbde18 3895 {
4697a36c 3896 int regno = info->first_fp_reg_save;
979721f8 3897 int loc = info->fp_save_offset + sp_offset;
4697a36c
MM
3898
3899 for ( ; regno < 64; regno++, loc += 8)
979721f8 3900 asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
bacbde18 3901 }
4697a36c
MM
3902 else if (info->first_fp_reg_save != 64)
3903 asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX,
3904 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
9878760c
RK
3905
3906 /* Now save gpr's. */
4697a36c 3907 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
85638c0d 3908 {
4697a36c 3909 int regno = info->first_gp_reg_save;
979721f8 3910 int loc = info->gp_save_offset + sp_offset;
85638c0d 3911
4697a36c 3912 for ( ; regno < 32; regno++, loc += reg_size)
979721f8 3913 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
85638c0d
RK
3914 }
3915
4697a36c
MM
3916 else if (info->first_gp_reg_save != 32)
3917 asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n",
3918 reg_names[info->first_gp_reg_save],
979721f8
MM
3919 info->gp_save_offset + sp_offset,
3920 reg_names[sp_reg]);
9878760c 3921
b6c9286a
MM
3922 /* Save main's arguments if we need to call a function */
3923#ifdef NAME__MAIN
3924 if (info->main_save_p)
3925 {
3926 int regno;
5ebfb2ba 3927 int loc = info->main_save_offset + sp_offset;
b6c9286a
MM
3928 int size = info->main_size;
3929
2682eae9 3930 for (regno = 3; size > 0; regno++, loc += reg_size, size -= reg_size)
979721f8 3931 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
b6c9286a
MM
3932 }
3933#endif
3934
9878760c 3935 /* Save lr if we used it. */
4697a36c 3936 if (info->lr_save_p)
979721f8
MM
3937 asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset + sp_offset,
3938 reg_names[sp_reg]);
9878760c
RK
3939
3940 /* Save CR if we use any that must be preserved. */
4697a36c 3941 if (info->cr_save_p)
979721f8
MM
3942 {
3943 if (sp_reg == 12) /* If r12 is used to hold the original sp, copy cr now */
3944 {
3945 asm_fprintf (file, "\tmfcr %s\n", reg_names[0]);
3946 asm_fprintf (file, store_reg, reg_names[0],
3947 info->cr_save_offset + sp_offset,
3948 reg_names[sp_reg]);
3949 }
3950 else
3951 asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset + sp_offset,
3952 reg_names[sp_reg]);
3953 }
9878760c 3954
979721f8
MM
3955 /* NT needs us to probe the stack frame every 4k pages for large frames, so
3956 do it here. */
3957 if (DEFAULT_ABI == ABI_NT && info->total_size > 4096)
3958 {
3959 if (info->total_size < 32768)
3960 {
3961 int probe_offset = 4096;
3962 while (probe_offset < info->total_size)
3963 {
3964 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", reg_names[0], -probe_offset, reg_names[1]);
3965 probe_offset += 4096;
3966 }
3967 }
3968 else
3969 {
3970 int probe_iterations = info->total_size / 4096;
3971 static int probe_labelno = 0;
3972 char buf[256];
3973
3974 if (probe_iterations < 32768)
3975 asm_fprintf (file, "\tli %s,%d\n", reg_names[12], probe_iterations);
3976 else
3977 {
3978 asm_fprintf (file, "\tlis %s,%d\n", reg_names[12], probe_iterations >> 16);
3979 if (probe_iterations & 0xffff)
3980 asm_fprintf (file, "\tori %s,%s,%d\n", reg_names[12], reg_names[12],
3981 probe_iterations & 0xffff);
3982 }
3983 asm_fprintf (file, "\tmtctr %s\n", reg_names[12]);
3984 asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3985 ASM_OUTPUT_INTERNAL_LABEL (file, "LCprobe", probe_labelno);
3986 asm_fprintf (file, "\t{lu|lwzu} %s,-4096(%s)\n", reg_names[0], reg_names[12]);
2a50d6bc 3987 ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno++);
979721f8
MM
3988 fputs ("\tbdnz ", file);
3989 assemble_name (file, buf);
3990 fputs ("\n", file);
3991 }
3992 }
3993
38c1f2d7 3994 /* Update stack and set back pointer unless this is V.4, which was done previously */
c81bebd7 3995 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
38c1f2d7 3996 rs6000_allocate_stack_space (file, info->total_size, FALSE);
9878760c
RK
3997
3998 /* Set frame pointer, if needed. */
3999 if (frame_pointer_needed)
4697a36c 4000 asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]);
1875cc88 4001
b6c9286a
MM
4002#ifdef NAME__MAIN
4003 /* If we need to call a function to set things up for main, do so now
4004 before dealing with the TOC. */
4005 if (info->main_p)
4006 {
4007 char *prefix = "";
4008
4009 switch (DEFAULT_ABI)
4010 {
4011 case ABI_AIX: prefix = "."; break;
4012 case ABI_NT: prefix = ".."; break;
4013 }
4014
4015 fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN);
4016#ifdef RS6000_CALL_GLUE2
4017 fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN);
4018#else
4019#ifdef RS6000_CALL_GLUE
4020 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
4021 fprintf (file, "\t%s\n", RS6000_CALL_GLUE);
4022#endif
4023#endif
4024
4025 if (info->main_save_p)
4026 {
4027 int regno;
4028 int loc;
4029 int size = info->main_size;
4030
4031 if (info->total_size < 32767)
4032 {
4033 loc = info->total_size + info->main_save_offset;
2682eae9 4034 for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size)
b6c9286a
MM
4035 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
4036 }
4037 else
5ebfb2ba
MM
4038 {
4039 int neg_size = info->main_save_offset - info->total_size;
4040 loc = 0;
4041 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
4042 reg_names[0], (neg_size >> 16) & 0xffff,
4043 reg_names[0], reg_names[0], neg_size & 0xffff);
979721f8 4044
b6c9286a
MM
4045 asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0],
4046 reg_names[1]);
4047
2682eae9 4048 for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size)
b6c9286a
MM
4049 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]);
4050 }
4051 }
4052 }
4053#endif
4054
4055
1875cc88
JW
4056 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
4057 TOC_TABLE address into register 30. */
4697a36c 4058 if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
ab9eef41
MM
4059 {
4060#ifdef USING_SVR4_H
38c1f2d7
MM
4061 if (!profile_flag)
4062 rs6000_pic_func_labelno = rs6000_pic_labelno;
ab9eef41 4063#endif
38c1f2d7 4064 rs6000_output_load_toc_table (file, 30);
ab9eef41 4065 }
4697a36c 4066
b6c9286a
MM
4067 if (DEFAULT_ABI == ABI_NT)
4068 {
4069 assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4070 fputs (".b:\n", file);
3daf36a4 4071 }
9878760c
RK
4072}
4073
4074/* Write function epilogue. */
4075
4076void
4077output_epilog (file, size)
4078 FILE *file;
296b8152 4079 int size ATTRIBUTE_UNUSED;
9878760c 4080{
4697a36c 4081 rs6000_stack_t *info = rs6000_stack_info ();
8f802bfb 4082 char *load_reg = (TARGET_32BIT) ? "\t{l|lwz} %s,%d(%s)\n" : "\tld %s,%d(%s)\n";
9878760c 4083 rtx insn = get_last_insn ();
979721f8
MM
4084 int sp_reg = 1;
4085 int sp_offset = 0;
9878760c 4086
9878760c
RK
4087 /* If the last insn was a BARRIER, we don't have to write anything except
4088 the trace table. */
4089 if (GET_CODE (insn) == NOTE)
4090 insn = prev_nonnote_insn (insn);
4091 if (insn == 0 || GET_CODE (insn) != BARRIER)
4092 {
4093 /* If we have a frame pointer, a call to alloca, or a large stack
4094 frame, restore the old stack pointer using the backchain. Otherwise,
4095 we know what size to update it with. */
4096 if (frame_pointer_needed || current_function_calls_alloca
4697a36c 4097 || info->total_size > 32767)
979721f8
MM
4098 {
4099 /* Under V.4, don't reset the stack pointer until after we're done
4100 loading the saved registers. */
c81bebd7 4101 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
979721f8
MM
4102 sp_reg = 11;
4103
4104 asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]);
4105 }
4697a36c
MM
4106 else if (info->push_p)
4107 {
c81bebd7 4108 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
979721f8 4109 sp_offset = info->total_size;
4697a36c 4110 else
a260abc9
DE
4111 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
4112 reg_names[1], info->total_size, reg_names[1]);
4697a36c 4113 }
9878760c 4114
b4ac57ab 4115 /* Get the old lr if we saved it. */
4697a36c 4116 if (info->lr_save_p)
979721f8 4117 asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset + sp_offset, reg_names[sp_reg]);
9878760c
RK
4118
4119 /* Get the old cr if we saved it. */
4697a36c 4120 if (info->cr_save_p)
979721f8 4121 asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset + sp_offset, reg_names[sp_reg]);
9878760c 4122
b4ac57ab 4123 /* Set LR here to try to overlap restores below. */
4697a36c
MM
4124 if (info->lr_save_p)
4125 asm_fprintf (file, "\tmtlr %s\n", reg_names[0]);
b4ac57ab 4126
9878760c 4127 /* Restore gpr's. */
4697a36c 4128 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
85638c0d 4129 {
4697a36c 4130 int regno = info->first_gp_reg_save;
979721f8 4131 int loc = info->gp_save_offset + sp_offset;
8f802bfb 4132 int reg_size = (TARGET_32BIT) ? 4 : 8;
85638c0d 4133
4697a36c 4134 for ( ; regno < 32; regno++, loc += reg_size)
979721f8 4135 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[sp_reg]);
85638c0d
RK
4136 }
4137
4697a36c
MM
4138 else if (info->first_gp_reg_save != 32)
4139 asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n",
4140 reg_names[info->first_gp_reg_save],
979721f8
MM
4141 info->gp_save_offset + sp_offset,
4142 reg_names[sp_reg]);
9878760c 4143
b4ac57ab 4144 /* Restore fpr's if we can do it without calling a function. */
4697a36c
MM
4145 if (FP_SAVE_INLINE (info->first_fp_reg_save))
4146 {
4147 int regno = info->first_fp_reg_save;
979721f8 4148 int loc = info->fp_save_offset + sp_offset;
4697a36c
MM
4149
4150 for ( ; regno < 64; regno++, loc += 8)
979721f8 4151 asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
4697a36c 4152 }
9878760c 4153
28edebac
RK
4154 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
4155 that were used. */
4697a36c
MM
4156 if (info->cr_save_p)
4157 asm_fprintf (file, "\tmtcrf %d,%s\n",
85638c0d
RK
4158 (regs_ever_live[70] != 0) * 0x20
4159 + (regs_ever_live[71] != 0) * 0x10
4697a36c 4160 + (regs_ever_live[72] != 0) * 0x8, reg_names[12]);
9878760c 4161
a6c2a102
DE
4162 /* If this is V.4, unwind the stack pointer after all of the loads
4163 have been done */
4164 if (sp_offset != 0)
a260abc9
DE
4165 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
4166 reg_names[1], sp_offset, reg_names[1]);
979721f8
MM
4167 else if (sp_reg != 1)
4168 asm_fprintf (file, "\tmr %s,%s\n", reg_names[1], reg_names[sp_reg]);
4169
b4ac57ab
RS
4170 /* If we have to restore more than two FP registers, branch to the
4171 restore function. It will return to our caller. */
4697a36c
MM
4172 if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4173 asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX,
4174 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
b4ac57ab 4175 else
85638c0d 4176 asm_fprintf (file, "\t{br|blr}\n");
9878760c 4177 }
b4ac57ab 4178
9b30bae2 4179 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
4180 on its format.
4181
4182 We don't output a traceback table if -finhibit-size-directive was
4183 used. The documentation for -finhibit-size-directive reads
4184 ``don't output a @code{.size} assembler directive, or anything
4185 else that would cause trouble if the function is split in the
4186 middle, and the two halves are placed at locations far apart in
4187 memory.'' The traceback table has this property, since it
4188 includes the offset from the start of the function to the
4d30c363
MM
4189 traceback table itself.
4190
4191 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a
MM
4192 different traceback table. */
4193 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
9b30bae2 4194 {
314fc5a9
ILT
4195 char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
4196 int fixed_parms, float_parms, parm_info;
4197 int i;
4198
b6c9286a
MM
4199 while (*fname == '.') /* V.4 encodes . in the name */
4200 fname++;
4201
314fc5a9
ILT
4202 /* Need label immediately before tbtab, so we can compute its offset
4203 from the function start. */
4204 if (*fname == '*')
4205 ++fname;
4206 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
4207 ASM_OUTPUT_LABEL (file, fname);
4208
4209 /* The .tbtab pseudo-op can only be used for the first eight
4210 expressions, since it can't handle the possibly variable
4211 length fields that follow. However, if you omit the optional
4212 fields, the assembler outputs zeros for all optional fields
4213 anyways, giving each variable length field is minimum length
4214 (as defined in sys/debug.h). Thus we can not use the .tbtab
4215 pseudo-op at all. */
4216
4217 /* An all-zero word flags the start of the tbtab, for debuggers
4218 that have to find it by searching forward from the entry
4219 point or from the current pc. */
19d2d16f 4220 fputs ("\t.long 0\n", file);
314fc5a9
ILT
4221
4222 /* Tbtab format type. Use format type 0. */
19d2d16f 4223 fputs ("\t.byte 0,", file);
314fc5a9
ILT
4224
4225 /* Language type. Unfortunately, there doesn't seem to be any
4226 official way to get this info, so we use language_string. C
4227 is 0. C++ is 9. No number defined for Obj-C, so use the
4228 value for C for now. */
4229 if (! strcmp (language_string, "GNU C")
4230 || ! strcmp (language_string, "GNU Obj-C"))
4231 i = 0;
4232 else if (! strcmp (language_string, "GNU F77"))
4233 i = 1;
4234 else if (! strcmp (language_string, "GNU Ada"))
4235 i = 3;
8b83775b 4236 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
4237 i = 2;
4238 else if (! strcmp (language_string, "GNU C++"))
4239 i = 9;
4240 else
4241 abort ();
4242 fprintf (file, "%d,", i);
4243
4244 /* 8 single bit fields: global linkage (not set for C extern linkage,
4245 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
4246 from start of procedure stored in tbtab, internal function, function
4247 has controlled storage, function has no toc, function uses fp,
4248 function logs/aborts fp operations. */
4249 /* Assume that fp operations are used if any fp reg must be saved. */
4697a36c 4250 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
4251
4252 /* 6 bitfields: function is interrupt handler, name present in
4253 proc table, function calls alloca, on condition directives
4254 (controls stack walks, 3 bits), saves condition reg, saves
4255 link reg. */
4256 /* The `function calls alloca' bit seems to be set whenever reg 31 is
4257 set up as a frame pointer, even when there is no alloca call. */
4258 fprintf (file, "%d,",
4259 ((1 << 6) | (frame_pointer_needed << 5)
4697a36c 4260 | (info->cr_save_p << 1) | (info->lr_save_p)));
314fc5a9
ILT
4261
4262 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
4263 (6 bits). */
4264 fprintf (file, "%d,",
4697a36c 4265 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
4266
4267 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
4268 fprintf (file, "%d,", (32 - first_reg_to_save ()));
4269
4270 {
4271 /* Compute the parameter info from the function decl argument
4272 list. */
4273 tree decl;
4274 int next_parm_info_bit;
4275
4276 next_parm_info_bit = 31;
4277 parm_info = 0;
4278 fixed_parms = 0;
4279 float_parms = 0;
4280
4281 for (decl = DECL_ARGUMENTS (current_function_decl);
4282 decl; decl = TREE_CHAIN (decl))
4283 {
4284 rtx parameter = DECL_INCOMING_RTL (decl);
4285 enum machine_mode mode = GET_MODE (parameter);
4286
4287 if (GET_CODE (parameter) == REG)
4288 {
4289 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
4290 {
4291 int bits;
4292
4293 float_parms++;
4294
4295 if (mode == SFmode)
4296 bits = 0x2;
4297 else if (mode == DFmode)
4298 bits = 0x3;
4299 else
4300 abort ();
4301
4302 /* If only one bit will fit, don't or in this entry. */
4303 if (next_parm_info_bit > 0)
4304 parm_info |= (bits << (next_parm_info_bit - 1));
4305 next_parm_info_bit -= 2;
4306 }
4307 else
4308 {
4309 fixed_parms += ((GET_MODE_SIZE (mode)
4310 + (UNITS_PER_WORD - 1))
4311 / UNITS_PER_WORD);
4312 next_parm_info_bit -= 1;
4313 }
4314 }
4315 }
4316 }
4317
4318 /* Number of fixed point parameters. */
4319 /* This is actually the number of words of fixed point parameters; thus
4320 an 8 byte struct counts as 2; and thus the maximum value is 8. */
4321 fprintf (file, "%d,", fixed_parms);
4322
4323 /* 2 bitfields: number of floating point parameters (7 bits), parameters
4324 all on stack. */
4325 /* This is actually the number of fp registers that hold parameters;
4326 and thus the maximum value is 13. */
4327 /* Set parameters on stack bit if parameters are not in their original
4328 registers, regardless of whether they are on the stack? Xlc
4329 seems to set the bit when not optimizing. */
4330 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
4331
4332 /* Optional fields follow. Some are variable length. */
4333
4334 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
4335 11 double float. */
4336 /* There is an entry for each parameter in a register, in the order that
4337 they occur in the parameter list. Any intervening arguments on the
4338 stack are ignored. If the list overflows a long (max possible length
4339 34 bits) then completely leave off all elements that don't fit. */
4340 /* Only emit this long if there was at least one parameter. */
4341 if (fixed_parms || float_parms)
4342 fprintf (file, "\t.long %d\n", parm_info);
4343
4344 /* Offset from start of code to tb table. */
19d2d16f 4345 fputs ("\t.long ", file);
314fc5a9
ILT
4346 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
4347 RS6000_OUTPUT_BASENAME (file, fname);
19d2d16f 4348 fputs ("-.", file);
314fc5a9 4349 RS6000_OUTPUT_BASENAME (file, fname);
19d2d16f 4350 putc ('\n', file);
314fc5a9
ILT
4351
4352 /* Interrupt handler mask. */
4353 /* Omit this long, since we never set the interrupt handler bit
4354 above. */
4355
4356 /* Number of CTL (controlled storage) anchors. */
4357 /* Omit this long, since the has_ctl bit is never set above. */
4358
4359 /* Displacement into stack of each CTL anchor. */
4360 /* Omit this list of longs, because there are no CTL anchors. */
4361
4362 /* Length of function name. */
296b8152 4363 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
4364
4365 /* Function name. */
4366 assemble_string (fname, strlen (fname));
4367
4368 /* Register for alloca automatic storage; this is always reg 31.
4369 Only emit this if the alloca bit was set above. */
4370 if (frame_pointer_needed)
19d2d16f 4371 fputs ("\t.byte 31\n", file);
9b30bae2 4372 }
4697a36c 4373
b6c9286a
MM
4374 if (DEFAULT_ABI == ABI_NT)
4375 {
4376 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4377 fputs (".e:\nFE_MOT_RESVD..", file);
4378 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4379 fputs (":\n", file);
4380 }
9878760c
RK
4381}
4382\f
4383/* Output a TOC entry. We derive the entry name from what is
4384 being written. */
4385
4386void
4387output_toc (file, x, labelno)
4388 FILE *file;
4389 rtx x;
4390 int labelno;
4391{
4392 char buf[256];
4393 char *name = buf;
b6c9286a 4394 char *real_name;
9878760c
RK
4395 rtx base = x;
4396 int offset = 0;
4397
4697a36c
MM
4398 if (TARGET_NO_TOC)
4399 abort ();
4400
ff1720ed
RK
4401 /* if we're going to put a double constant in the TOC, make sure it's
4402 aligned properly when strict alignment is on. */
4403 if (GET_CODE (x) == CONST_DOUBLE
4404 && STRICT_ALIGNMENT
4405 && GET_MODE (x) == DFmode
4406 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
4407 ASM_OUTPUT_ALIGN (file, 3);
4408 }
4409
4410
b6c9286a 4411 if (TARGET_ELF && TARGET_MINIMAL_TOC)
d14a6d05
MM
4412 {
4413 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
4414 fprintf (file, "%d = .-", labelno);
4415 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
19d2d16f 4416 fputs ("1\n", file);
d14a6d05
MM
4417 }
4418 else
d14a6d05 4419 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
9878760c 4420
37c37a57
RK
4421 /* Handle FP constants specially. Note that if we have a minimal
4422 TOC, things we put here aren't actually in the TOC, so we can allow
4423 FP constants. */
042259f2 4424 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode
37c37a57 4425 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c 4426 {
042259f2
DE
4427 REAL_VALUE_TYPE rv;
4428 long k[2];
0adc764e 4429
042259f2
DE
4430 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
4431 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
13ded975
DE
4432 if (TARGET_64BIT)
4433 {
4434 if (TARGET_MINIMAL_TOC)
4435 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
4436 else
4437 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
4438 k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff);
4439 return;
4440 }
1875cc88 4441 else
13ded975
DE
4442 {
4443 if (TARGET_MINIMAL_TOC)
4444 fprintf (file, "\t.long %ld\n\t.long %ld\n", k[0], k[1]);
4445 else
4446 fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
4447 k[0], k[1], k[0], k[1]);
4448 return;
4449 }
9878760c
RK
4450 }
4451 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
37c37a57 4452 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c 4453 {
042259f2
DE
4454 REAL_VALUE_TYPE rv;
4455 long l;
9878760c 4456
042259f2
DE
4457 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
4458 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
4459
4460 if (TARGET_MINIMAL_TOC)
13ded975 4461 fprintf (file, TARGET_32BIT ? "\t.long %ld\n" : "\t.llong %ld\n", l);
042259f2 4462 else
1883e716 4463 fprintf (file, "\t.tc FS_%lx[TC],%ld\n", l, l);
042259f2
DE
4464 return;
4465 }
4466 else if (GET_MODE (x) == DImode
4467 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
4468 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
4469 {
4470 HOST_WIDE_INT low;
4471 HOST_WIDE_INT high;
4472
4473 if (GET_CODE (x) == CONST_DOUBLE)
4474 {
4475 low = CONST_DOUBLE_LOW (x);
4476 high = CONST_DOUBLE_HIGH (x);
4477 }
4478 else
4479#if HOST_BITS_PER_WIDE_INT == 32
4480 {
4481 low = INTVAL (x);
4482 high = (low < 0) ? ~0 : 0;
4483 }
4484#else
4485 {
4486 low = INTVAL (x) & 0xffffffff;
4487 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
4488 }
4489#endif
9878760c 4490
13ded975
DE
4491 if (TARGET_64BIT)
4492 {
4493 if (TARGET_MINIMAL_TOC)
4494 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
4495 else
4496 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
4497 (long)high, (long)low, (long)high, (long)low);
4498 return;
4499 }
1875cc88 4500 else
13ded975
DE
4501 {
4502 if (TARGET_MINIMAL_TOC)
4503 fprintf (file, "\t.long %ld\n\t.long %ld\n",
4504 (long)high, (long)low);
4505 else
4506 fprintf (file, "\t.tc ID_%lx_%lx[TC],%ld,%ld\n",
4507 (long)high, (long)low, (long)high, (long)low);
4508 return;
4509 }
9878760c
RK
4510 }
4511
4512 if (GET_CODE (x) == CONST)
4513 {
4514 base = XEXP (XEXP (x, 0), 0);
4515 offset = INTVAL (XEXP (XEXP (x, 0), 1));
4516 }
4517
4518 if (GET_CODE (base) == SYMBOL_REF)
4519 name = XSTR (base, 0);
4520 else if (GET_CODE (base) == LABEL_REF)
4521 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
4522 else if (GET_CODE (base) == CODE_LABEL)
4523 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
4524 else
4525 abort ();
4526
2e4eb9b0 4527 STRIP_NAME_ENCODING (real_name, name);
1875cc88 4528 if (TARGET_MINIMAL_TOC)
13ded975 4529 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
1875cc88
JW
4530 else
4531 {
b6c9286a 4532 fprintf (file, "\t.tc %s", real_name);
9878760c 4533
1875cc88
JW
4534 if (offset < 0)
4535 fprintf (file, ".N%d", - offset);
4536 else if (offset)
4537 fprintf (file, ".P%d", offset);
9878760c 4538
19d2d16f 4539 fputs ("[TC],", file);
1875cc88 4540 }
581bc4de
MM
4541
4542 /* Currently C++ toc references to vtables can be emitted before it
4543 is decided whether the vtable is public or private. If this is
4544 the case, then the linker will eventually complain that there is
4545 a TOC reference to an unknown section. Thus, for vtables only,
4546 we emit the TOC reference to reference the symbol and not the
4547 section. */
3807773b 4548 if (!strncmp ("_vt.", name, 4))
581bc4de 4549 {
3807773b 4550 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
4551 if (offset < 0)
4552 fprintf (file, "%d", offset);
4553 else if (offset > 0)
4554 fprintf (file, "+%d", offset);
4555 }
4556 else
4557 output_addr_const (file, x);
19d2d16f 4558 putc ('\n', file);
9878760c
RK
4559}
4560\f
4561/* Output an assembler pseudo-op to write an ASCII string of N characters
4562 starting at P to FILE.
4563
4564 On the RS/6000, we have to do this using the .byte operation and
4565 write out special characters outside the quoted string.
4566 Also, the assembler is broken; very long strings are truncated,
4567 so we must artificially break them up early. */
4568
4569void
4570output_ascii (file, p, n)
4571 FILE *file;
4572 char *p;
4573 int n;
4574{
4575 char c;
4576 int i, count_string;
4577 char *for_string = "\t.byte \"";
4578 char *for_decimal = "\t.byte ";
4579 char *to_close = NULL;
4580
4581 count_string = 0;
4582 for (i = 0; i < n; i++)
4583 {
4584 c = *p++;
4585 if (c >= ' ' && c < 0177)
4586 {
4587 if (for_string)
4588 fputs (for_string, file);
4589 putc (c, file);
4590
4591 /* Write two quotes to get one. */
4592 if (c == '"')
4593 {
4594 putc (c, file);
4595 ++count_string;
4596 }
4597
4598 for_string = NULL;
4599 for_decimal = "\"\n\t.byte ";
4600 to_close = "\"\n";
4601 ++count_string;
4602
4603 if (count_string >= 512)
4604 {
4605 fputs (to_close, file);
4606
4607 for_string = "\t.byte \"";
4608 for_decimal = "\t.byte ";
4609 to_close = NULL;
4610 count_string = 0;
4611 }
4612 }
4613 else
4614 {
4615 if (for_decimal)
4616 fputs (for_decimal, file);
4617 fprintf (file, "%d", c);
4618
4619 for_string = "\n\t.byte \"";
4620 for_decimal = ", ";
4621 to_close = "\n";
4622 count_string = 0;
4623 }
4624 }
4625
4626 /* Now close the string if we have written one. Then end the line. */
4627 if (to_close)
4628 fprintf (file, to_close);
4629}
4630\f
4631/* Generate a unique section name for FILENAME for a section type
4632 represented by SECTION_DESC. Output goes into BUF.
4633
4634 SECTION_DESC can be any string, as long as it is different for each
4635 possible section type.
4636
4637 We name the section in the same manner as xlc. The name begins with an
4638 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
4639 names) with the last period replaced by the string SECTION_DESC. If
4640 FILENAME does not contain a period, SECTION_DESC is appended to the end of
4641 the name. */
9878760c
RK
4642
4643void
4644rs6000_gen_section_name (buf, filename, section_desc)
4645 char **buf;
4646 char *filename;
4647 char *section_desc;
4648{
11e5fe42 4649 char *q, *after_last_slash, *last_period;
9878760c
RK
4650 char *p;
4651 int len;
9878760c
RK
4652
4653 after_last_slash = filename;
4654 for (q = filename; *q; q++)
11e5fe42
RK
4655 {
4656 if (*q == '/')
4657 after_last_slash = q + 1;
4658 else if (*q == '.')
4659 last_period = q;
4660 }
9878760c 4661
11e5fe42 4662 len = strlen (after_last_slash) + strlen (section_desc) + 2;
9878760c
RK
4663 *buf = (char *) permalloc (len);
4664
4665 p = *buf;
4666 *p++ = '_';
4667
4668 for (q = after_last_slash; *q; q++)
4669 {
11e5fe42 4670 if (q == last_period)
9878760c
RK
4671 {
4672 strcpy (p, section_desc);
4673 p += strlen (section_desc);
9878760c
RK
4674 }
4675
e9a780ec 4676 else if (ISALNUM (*q))
9878760c
RK
4677 *p++ = *q;
4678 }
4679
11e5fe42 4680 if (last_period == 0)
9878760c
RK
4681 strcpy (p, section_desc);
4682 else
4683 *p = '\0';
4684}
e165f3f0
RK
4685\f
4686/* Write function profiler code. */
4687
4688void
4689output_function_profiler (file, labelno)
4690 FILE *file;
4691 int labelno;
4692{
4693 /* The last used parameter register. */
4694 int last_parm_reg;
4695 int i, j;
3daf36a4 4696 char buf[100];
e165f3f0 4697
3daf36a4 4698 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 4699 switch (DEFAULT_ABI)
3daf36a4 4700 {
38c1f2d7
MM
4701 default:
4702 abort ();
4703
4704 case ABI_V4:
4705 case ABI_SOLARIS:
4706 case ABI_AIX_NODESC:
4707 fprintf (file, "\tmflr %s\n", reg_names[0]);
4708 if (flag_pic == 1)
4709 {
dfdfa60f
DE
4710 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
4711 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
4712 reg_names[0], reg_names[1]);
4713 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
4714 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 4715 assemble_name (file, buf);
dfdfa60f 4716 asm_fprintf (file, "@got(%s)\n", reg_names[11]);
38c1f2d7
MM
4717 }
4718#if TARGET_ELF
4719 else if (flag_pic > 1 || TARGET_RELOCATABLE)
4720 {
dfdfa60f
DE
4721 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
4722 reg_names[0], reg_names[1]);
38c1f2d7
MM
4723 rs6000_pic_func_labelno = rs6000_pic_labelno;
4724 rs6000_output_load_toc_table (file, 11);
dfdfa60f 4725 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[11]);
38c1f2d7 4726 assemble_name (file, buf);
dfdfa60f
DE
4727 asm_fprintf (file, "X(%s)\n", reg_names[11]);
4728 asm_fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
034e84c4 4729 assemble_name (file, buf);
dfdfa60f
DE
4730 fputs ("X = .-.LCTOC1\n", file);
4731 fputs ("\t.long ", file);
034e84c4
MM
4732 assemble_name (file, buf);
4733 fputs ("\n\t.previous\n", file);
38c1f2d7
MM
4734 }
4735#endif
38c1f2d7
MM
4736 else
4737 {
a260abc9 4738 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[11]);
38c1f2d7 4739 assemble_name (file, buf);
dfdfa60f 4740 fputs ("@ha\n", file);
a260abc9
DE
4741 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", reg_names[0], reg_names[1]);
4742 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 4743 assemble_name (file, buf);
a260abc9 4744 asm_fprintf (file, "@l(%s)\n", reg_names[11]);
38c1f2d7
MM
4745 }
4746
4747 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
4748 break;
4749
4750 case ABI_AIX:
4751 /* Set up a TOC entry for the profiler label. */
4752 toc_section ();
4753 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
4754 if (TARGET_MINIMAL_TOC)
4755 {
13ded975 4756 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
38c1f2d7
MM
4757 assemble_name (file, buf);
4758 putc ('\n', file);
4759 }
4760 else
4761 {
4762 fputs ("\t.tc\t", file);
4763 assemble_name (file, buf);
4764 fputs ("[TC],", file);
4765 assemble_name (file, buf);
4766 putc ('\n', file);
4767 }
4768 text_section ();
e165f3f0
RK
4769
4770 /* Figure out last used parameter register. The proper thing to do is
4771 to walk incoming args of the function. A function might have live
4772 parameter registers even if it has no incoming args. */
4773
38c1f2d7
MM
4774 for (last_parm_reg = 10;
4775 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4776 last_parm_reg--)
4777 ;
e165f3f0
RK
4778
4779 /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since
4780 it might be set up as the frame pointer. */
4781
38c1f2d7
MM
4782 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
4783 asm_fprintf (file, "\tmr %d,%d\n", j, i);
e165f3f0
RK
4784
4785 /* Load location address into r3, and call mcount. */
4786
38c1f2d7 4787 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
13ded975
DE
4788 asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,",
4789 reg_names[3]);
38c1f2d7 4790 assemble_name (file, buf);
a260abc9
DE
4791 asm_fprintf (file, "(%s)\n\tbl %s\n\t%s\n",
4792 reg_names[2], RS6000_MCOUNT, RS6000_CALL_GLUE);
e165f3f0
RK
4793
4794 /* Restore parameter registers. */
4795
38c1f2d7
MM
4796 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
4797 asm_fprintf (file, "\tmr %d,%d\n", i, j);
4798 break;
4799 }
e165f3f0 4800}
a251ffd0
TG
4801
4802/* Adjust the cost of a scheduling dependency. Return the new cost of
4803 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4804
4805int
a06faf84 4806rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
4807 rtx insn;
4808 rtx link;
296b8152 4809 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
4810 int cost;
4811{
4812 if (! recog_memoized (insn))
4813 return 0;
4814
4815 if (REG_NOTE_KIND (link) != 0)
4816 return 0;
4817
4818 if (REG_NOTE_KIND (link) == 0)
4819 {
4820 /* Data dependency; DEP_INSN writes a register that INSN reads some
4821 cycles later. */
4822
4823 /* Tell the first scheduling pass about the latency between a mtctr
4824 and bctr (and mtlr and br/blr). The first scheduling pass will not
4825 know about this latency since the mtctr instruction, which has the
4826 latency associated to it, will be generated by reload. */
4827 if (get_attr_type (insn) == TYPE_JMPREG)
4828 return TARGET_POWER ? 5 : 4;
4829
4830 /* Fall out to return default cost. */
4831 }
4832
4833 return cost;
4834}
b6c9286a
MM
4835
4836/* Return how many instructions the machine can issue per cycle */
4837int get_issue_rate()
4838{
4839 switch (rs6000_cpu_attr) {
4840 case CPU_RIOS1:
4841 return 3; /* ? */
4842 case CPU_RIOS2:
4843 return 4;
4844 case CPU_PPC601:
4845 return 3; /* ? */
b6c9286a
MM
4846 case CPU_PPC603:
4847 return 2;
4848 case CPU_PPC604:
4849 return 4;
4850 case CPU_PPC620:
4851 return 4;
4852 default:
4853 return 1;
4854 }
4855}
4856
b6c9286a
MM
4857
4858\f
4859/* Output assembler code for a block containing the constant parts
4860 of a trampoline, leaving space for the variable parts.
4861
4862 The trampoline should set the static chain pointer to value placed
4863 into the trampoline and should branch to the specified routine. */
4864
4865void
4866rs6000_trampoline_template (file)
4867 FILE *file;
4868{
4869 char *sc = reg_names[STATIC_CHAIN_REGNUM];
4870 char *r0 = reg_names[0];
7c59dc5d 4871 char *r2 = reg_names[2];
b6c9286a
MM
4872
4873 switch (DEFAULT_ABI)
4874 {
4875 default:
4876 abort ();
4877
4878 /* Under AIX, this is not code at all, but merely a data area,
4879 since that is the way all functions are called. The first word is
4880 the address of the function, the second word is the TOC pointer (r2),
4881 and the third word is the static chain value. */
4882 case ABI_AIX:
b6c9286a
MM
4883 break;
4884
4885
4886 /* V.4/eabi function pointers are just a single pointer, so we need to
4887 do the full gory code to load up the static chain. */
4888 case ABI_V4:
c81bebd7 4889 case ABI_SOLARIS:
b6c9286a 4890 case ABI_AIX_NODESC:
b6c9286a
MM
4891 break;
4892
4893 /* NT function pointers point to a two word area (real address, TOC)
4894 which unfortunately does not include a static chain field. So we
7c59dc5d
MM
4895 use the function field to point to ..LTRAMP1 and the toc field
4896 to point to the whole table. */
b6c9286a 4897 case ABI_NT:
7c59dc5d
MM
4898 if (STATIC_CHAIN_REGNUM == 0
4899 || STATIC_CHAIN_REGNUM == 2
4900 || TARGET_64BIT
4901 || !TARGET_NEW_MNEMONICS)
b6c9286a
MM
4902 abort ();
4903
7c59dc5d
MM
4904 fprintf (file, "\t.ualong 0\n"); /* offset 0 */
4905 fprintf (file, "\t.ualong 0\n"); /* offset 4 */
4906 fprintf (file, "\t.ualong 0\n"); /* offset 8 */
4907 fprintf (file, "\t.ualong 0\n"); /* offset 12 */
4908 fprintf (file, "\t.ualong 0\n"); /* offset 16 */
8bd04c56 4909 fprintf (file, "..LTRAMP1..0:\n"); /* offset 20 */
7c59dc5d
MM
4910 fprintf (file, "\tlwz %s,8(%s)\n", r0, r2); /* offset 24 */
4911 fprintf (file, "\tlwz %s,12(%s)\n", sc, r2); /* offset 28 */
4912 fprintf (file, "\tmtctr %s\n", r0); /* offset 32 */
4913 fprintf (file, "\tlwz %s,16(%s)\n", r2, r2); /* offset 36 */
4914 fprintf (file, "\tbctr\n"); /* offset 40 */
b6c9286a
MM
4915 break;
4916 }
4917
4918 return;
4919}
4920
4921/* Length in units of the trampoline for entering a nested function. */
4922
4923int
4924rs6000_trampoline_size ()
4925{
4926 int ret = 0;
4927
4928 switch (DEFAULT_ABI)
4929 {
4930 default:
4931 abort ();
4932
4933 case ABI_AIX:
8f802bfb 4934 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
4935 break;
4936
4937 case ABI_V4:
c81bebd7 4938 case ABI_SOLARIS:
b6c9286a 4939 case ABI_AIX_NODESC:
03a7e1a5 4940 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a
MM
4941 break;
4942
4943 case ABI_NT:
7c59dc5d 4944 ret = 20;
b6c9286a
MM
4945 break;
4946 }
4947
4948 return ret;
4949}
4950
4951/* Emit RTL insns to initialize the variable parts of a trampoline.
4952 FNADDR is an RTX for the address of the function's pure code.
4953 CXT is an RTX for the static chain value for the function. */
4954
4955void
4956rs6000_initialize_trampoline (addr, fnaddr, cxt)
4957 rtx addr;
4958 rtx fnaddr;
4959 rtx cxt;
4960{
ac2a93a1 4961 enum machine_mode pmode = Pmode;
8bd04c56
MM
4962 int regsize = (TARGET_32BIT) ? 4 : 8;
4963 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
4964
4965 switch (DEFAULT_ABI)
4966 {
4967 default:
4968 abort ();
4969
8bd04c56 4970/* Macros to shorten the code expansions below. */
39403d82
DE
4971#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
4972#define MEM_PLUS(addr,offset) gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 4973
b6c9286a
MM
4974 /* Under AIX, just build the 3 word function descriptor */
4975 case ABI_AIX:
8bd04c56
MM
4976 {
4977 rtx fn_reg = gen_reg_rtx (pmode);
4978 rtx toc_reg = gen_reg_rtx (pmode);
4979 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
4980 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
4981 emit_move_insn (MEM_DEREF (addr), fn_reg);
4982 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
4983 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
4984 }
b6c9286a
MM
4985 break;
4986
eaf1bcf1 4987 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
b6c9286a 4988 case ABI_V4:
c81bebd7 4989 case ABI_SOLARIS:
b6c9286a 4990 case ABI_AIX_NODESC:
39403d82 4991 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
4992 FALSE, VOIDmode, 4,
4993 addr, pmode,
4994 GEN_INT (rs6000_trampoline_size ()), SImode,
4995 fnaddr, pmode,
4996 ctx_reg, pmode);
b6c9286a
MM
4997 break;
4998
8bd04c56
MM
4999 /* Under NT, update the first word to point to the ..LTRAMP1..0 header,
5000 the second word will point to the whole trampoline, third-fifth words
7c59dc5d 5001 will then have the real address, static chain, and toc value. */
b6c9286a 5002 case ABI_NT:
8bd04c56
MM
5003 {
5004 rtx tramp_reg = gen_reg_rtx (pmode);
5005 rtx fn_reg = gen_reg_rtx (pmode);
5006 rtx toc_reg = gen_reg_rtx (pmode);
5007
39403d82 5008 emit_move_insn (tramp_reg, gen_rtx_SYMBOL_REF (pmode, "..LTRAMP1..0"));
8bd04c56
MM
5009 addr = force_reg (pmode, addr);
5010 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
5011 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
5012 emit_move_insn (MEM_DEREF (addr), tramp_reg);
5013 emit_move_insn (MEM_PLUS (addr, regsize), addr);
5014 emit_move_insn (MEM_PLUS (addr, 2*regsize), fn_reg);
5015 emit_move_insn (MEM_PLUS (addr, 3*regsize), ctx_reg);
39403d82 5016 emit_move_insn (MEM_PLUS (addr, 4*regsize), gen_rtx_REG (pmode, 2));
8bd04c56 5017 }
b6c9286a
MM
5018 break;
5019 }
5020
5021 return;
5022}
7509c759
MM
5023
5024\f
5025/* If defined, a C expression whose value is nonzero if IDENTIFIER
5026 with arguments ARGS is a valid machine specific attribute for DECL.
5027 The attributes in ATTRIBUTES have previously been assigned to DECL. */
5028
5029int
5030rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
296b8152
KG
5031 tree decl ATTRIBUTE_UNUSED;
5032 tree attributes ATTRIBUTE_UNUSED;
5033 tree identifier ATTRIBUTE_UNUSED;
5034 tree args ATTRIBUTE_UNUSED;
7509c759
MM
5035{
5036 return 0;
5037}
5038
5039/* If defined, a C expression whose value is nonzero if IDENTIFIER
5040 with arguments ARGS is a valid machine specific attribute for TYPE.
5041 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
5042
5043int
5044rs6000_valid_type_attribute_p (type, attributes, identifier, args)
5045 tree type;
296b8152 5046 tree attributes ATTRIBUTE_UNUSED;
7509c759
MM
5047 tree identifier;
5048 tree args;
5049{
5050 if (TREE_CODE (type) != FUNCTION_TYPE
5051 && TREE_CODE (type) != FIELD_DECL
5052 && TREE_CODE (type) != TYPE_DECL)
5053 return 0;
5054
6a4cee5f
MM
5055 /* Longcall attribute says that the function is not within 2**26 bytes
5056 of the current function, and to do an indirect call. */
5057 if (is_attribute_p ("longcall", identifier))
5058 return (args == NULL_TREE);
5059
7509c759
MM
5060 if (DEFAULT_ABI == ABI_NT)
5061 {
5062 /* Stdcall attribute says callee is responsible for popping arguments
5063 if they are not variable. */
5064 if (is_attribute_p ("stdcall", identifier))
5065 return (args == NULL_TREE);
5066
5067 /* Cdecl attribute says the callee is a normal C declaration */
5068 if (is_attribute_p ("cdecl", identifier))
5069 return (args == NULL_TREE);
5070
38e01259 5071 /* Dllimport attribute says the caller is to call the function
7509c759
MM
5072 indirectly through a __imp_<name> pointer. */
5073 if (is_attribute_p ("dllimport", identifier))
5074 return (args == NULL_TREE);
5075
38e01259 5076 /* Dllexport attribute says the callee is to create a __imp_<name>
7509c759
MM
5077 pointer. */
5078 if (is_attribute_p ("dllexport", identifier))
5079 return (args == NULL_TREE);
e56bb9ed
MM
5080
5081 /* Exception attribute allows the user to specify 1-2 strings or identifiers
5082 that will fill in the 3rd and 4th fields of the structured exception
5083 table. */
5084 if (is_attribute_p ("exception", identifier))
5085 {
5086 int i;
5087
5088 if (args == NULL_TREE)
5089 return 0;
5090
5091 for (i = 0; i < 2 && args != NULL_TREE; i++)
5092 {
5093 tree this_arg = TREE_VALUE (args);
5094 args = TREE_PURPOSE (args);
5095
5096 if (TREE_CODE (this_arg) != STRING_CST
5097 && TREE_CODE (this_arg) != IDENTIFIER_NODE)
5098 return 0;
5099 }
5100
5101 return (args == NULL_TREE);
5102 }
7509c759
MM
5103 }
5104
5105 return 0;
5106}
5107
5108/* If defined, a C expression whose value is zero if the attributes on
5109 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
5110 two if they are nearly compatible (which causes a warning to be
5111 generated). */
5112
5113int
5114rs6000_comp_type_attributes (type1, type2)
296b8152
KG
5115 tree type1 ATTRIBUTE_UNUSED;
5116 tree type2 ATTRIBUTE_UNUSED;
7509c759
MM
5117{
5118 return 1;
5119}
5120
5121/* If defined, a C statement that assigns default attributes to newly
5122 defined TYPE. */
5123
5124void
5125rs6000_set_default_type_attributes (type)
296b8152 5126 tree type ATTRIBUTE_UNUSED;
7509c759
MM
5127{
5128}
5129
38e01259 5130/* Return a dll import reference corresponding to a call's SYMBOL_REF */
7509c759
MM
5131struct rtx_def *
5132rs6000_dll_import_ref (call_ref)
5133 rtx call_ref;
5134{
5135 char *call_name;
5136 int len;
5137 char *p;
5138 rtx reg1, reg2;
5139 tree node;
5140
5141 if (GET_CODE (call_ref) != SYMBOL_REF)
5142 abort ();
5143
5144 call_name = XSTR (call_ref, 0);
5145 len = sizeof ("__imp_") + strlen (call_name);
5146 p = alloca (len);
5147 reg2 = gen_reg_rtx (Pmode);
5148
5149 strcpy (p, "__imp_");
5150 strcat (p, call_name);
5151 node = get_identifier (p);
5152
39403d82
DE
5153 reg1 = force_reg (Pmode, gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)));
5154 emit_move_insn (reg2, gen_rtx_MEM (Pmode, reg1));
7509c759
MM
5155
5156 return reg2;
5157}
5158
6a4cee5f
MM
5159/* Return a reference suitable for calling a function with the longcall attribute. */
5160struct rtx_def *
5161rs6000_longcall_ref (call_ref)
5162 rtx call_ref;
5163{
5164 char *call_name;
6a4cee5f
MM
5165 tree node;
5166
5167 if (GET_CODE (call_ref) != SYMBOL_REF)
5168 return call_ref;
5169
5170 /* System V adds '.' to the internal name, so skip them. */
5171 call_name = XSTR (call_ref, 0);
5172 if (*call_name == '.')
5173 {
5174 while (*call_name == '.')
5175 call_name++;
5176
5177 node = get_identifier (call_name);
39403d82 5178 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
5179 }
5180
5181 return force_reg (Pmode, call_ref);
5182}
5183
7509c759
MM
5184\f
5185/* A C statement or statements to switch to the appropriate section
5186 for output of RTX in mode MODE. You can assume that RTX is some
5187 kind of constant in RTL. The argument MODE is redundant except in
5188 the case of a `const_int' rtx. Select the section by calling
5189 `text_section' or one of the alternatives for other sections.
5190
5191 Do not define this macro if you put all constants in the read-only
5192 data section. */
5193
5194#ifdef USING_SVR4_H
5195
5196void
5197rs6000_select_rtx_section (mode, x)
5198 enum machine_mode mode;
5199 rtx x;
5200{
5201 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x))
5202 toc_section ();
7509c759
MM
5203 else
5204 const_section ();
5205}
5206
5207/* A C statement or statements to switch to the appropriate
5208 section for output of DECL. DECL is either a `VAR_DECL' node
5209 or a constant of some sort. RELOC indicates whether forming
5210 the initial value of DECL requires link-time relocations. */
5211
5212void
5213rs6000_select_section (decl, reloc)
5214 tree decl;
5215 int reloc;
5216{
5217 int size = int_size_in_bytes (TREE_TYPE (decl));
5218
5219 if (TREE_CODE (decl) == STRING_CST)
5220 {
88228c4b 5221 if (! flag_writable_strings)
7509c759 5222 const_section ();
7509c759
MM
5223 else
5224 data_section ();
5225 }
5226 else if (TREE_CODE (decl) == VAR_DECL)
5227 {
5228 if ((flag_pic && reloc)
5229 || !TREE_READONLY (decl)
5230 || TREE_SIDE_EFFECTS (decl)
5231 || !DECL_INITIAL (decl)
5232 || (DECL_INITIAL (decl) != error_mark_node
5233 && !TREE_CONSTANT (DECL_INITIAL (decl))))
5234 {
d9407988 5235 if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
7509c759
MM
5236 sdata_section ();
5237 else
5238 data_section ();
5239 }
5240 else
5241 {
d9407988 5242 if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
c81bebd7 5243 {
d9407988 5244 if (rs6000_sdata == SDATA_EABI)
c81bebd7
MM
5245 sdata2_section ();
5246 else
5247 sdata_section (); /* System V doesn't have .sdata2/.sbss2 */
5248 }
7509c759
MM
5249 else
5250 const_section ();
5251 }
5252 }
5253 else
5254 const_section ();
5255}
d9407988
MM
5256
5257\f
5258
5259/* If we are referencing a function that is static or is known to be
5260 in this file, make the SYMBOL_REF special. We can use this to indicate
5261 that we can branch to this function without emitting a no-op after the
5262 call. For real AIX and NT calling sequences, we also replace the
5263 function name with the real name (1 or 2 leading .'s), rather than
5264 the function descriptor name. This saves a lot of overriding code
a260abc9 5265 to read the prefixes. */
d9407988
MM
5266
5267void
5268rs6000_encode_section_info (decl)
5269 tree decl;
5270{
5271 if (TREE_CODE (decl) == FUNCTION_DECL)
5272 {
5273 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
5274 if (TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
5275 SYMBOL_REF_FLAG (sym_ref) = 1;
5276
5277 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
5278 {
5279 char *prefix = (DEFAULT_ABI == ABI_AIX) ? "." : "..";
5280 char *str = permalloc (strlen (prefix) + 1
5281 + strlen (XSTR (sym_ref, 0)));
5282 strcpy (str, prefix);
5283 strcat (str, XSTR (sym_ref, 0));
5284 XSTR (sym_ref, 0) = str;
5285 }
5286 }
5287 else if (rs6000_sdata != SDATA_NONE
5288 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5289 && TREE_CODE (decl) == VAR_DECL)
5290 {
5291 int size = int_size_in_bytes (TREE_TYPE (decl));
5292 tree section_name = DECL_SECTION_NAME (decl);
5293 char *name = (char *)0;
5294 int len = 0;
5295
5296 if (section_name)
5297 {
5298 if (TREE_CODE (section_name) == STRING_CST)
5299 {
5300 name = TREE_STRING_POINTER (section_name);
5301 len = TREE_STRING_LENGTH (section_name);
5302 }
5303 else
5304 abort ();
5305 }
5306
5307 if ((size > 0 && size <= g_switch_value)
5308 || (name
5309 && ((len == sizeof (".sdata")-1 && strcmp (name, ".sdata") == 0)
5310 || (len == sizeof (".sdata2")-1 && strcmp (name, ".sdata2") == 0)
5311 || (len == sizeof (".sbss")-1 && strcmp (name, ".sbss") == 0)
5312 || (len == sizeof (".sbss2")-1 && strcmp (name, ".sbss2") == 0)
5313 || (len == sizeof (".PPC.EMB.sdata0")-1 && strcmp (name, ".PPC.EMB.sdata0") == 0)
5314 || (len == sizeof (".PPC.EMB.sbss0")-1 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
5315 {
5316 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
5317 char *str = permalloc (2 + strlen (XSTR (sym_ref, 0)));
5318 strcpy (str, "@");
5319 strcat (str, XSTR (sym_ref, 0));
5320 XSTR (sym_ref, 0) = str;
5321 }
5322 }
5323}
5324
7509c759 5325#endif /* USING_SVR4_H */
a6c2a102
DE
5326\f
5327void
5328rs6000_fatal_bad_address (op)
5329 rtx op;
5330{
5331 fatal_insn ("bad address", op);
5332}