* rtl.h (rtunion_def): Constify member `rtstr'.
[official-gcc.git] / gcc / config / rs6000 / rs6000.c
bloba408d7e5921ccd4e37792380531f2129ea10c4a9
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "obstack.h"
36 #include "tree.h"
37 #include "expr.h"
38 #include "except.h"
39 #include "function.h"
40 #include "output.h"
41 #include "toplev.h"
42 #include "ggc.h"
44 #ifndef TARGET_NO_PROTOTYPE
45 #define TARGET_NO_PROTOTYPE 0
46 #endif
48 extern int profile_block_flag;
50 #define min(A,B) ((A) < (B) ? (A) : (B))
51 #define max(A,B) ((A) > (B) ? (A) : (B))
53 /* Target cpu type */
55 enum processor_type rs6000_cpu;
56 struct rs6000_cpu_select rs6000_select[3] =
58 /* switch name, tune arch */
59 { (const char *)0, "--with-cpu=", 1, 1 },
60 { (const char *)0, "-mcpu=", 1, 1 },
61 { (const char *)0, "-mtune=", 1, 0 },
64 /* Set to non-zero by "fix" operation to indicate that itrunc and
65 uitrunc must be defined. */
67 int rs6000_trunc_used;
69 /* Set to non-zero once they have been defined. */
71 static int trunc_defined;
73 /* Set to non-zero once AIX common-mode calls have been defined. */
74 static int common_mode_defined;
76 /* Save information from a "cmpxx" operation until the branch or scc is
77 emitted. */
78 rtx rs6000_compare_op0, rs6000_compare_op1;
79 int rs6000_compare_fp_p;
81 #ifdef USING_SVR4_H
82 /* Label number of label created for -mrelocatable, to call to so we can
83 get the address of the GOT section */
84 int rs6000_pic_labelno;
85 int rs6000_pic_func_labelno;
87 /* Which abi to adhere to */
88 const char *rs6000_abi_name = RS6000_ABI_NAME;
90 /* Semantics of the small data area */
91 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
93 /* Which small data model to use */
94 const char *rs6000_sdata_name = (char *)0;
95 #endif
97 /* Whether a System V.4 varargs area was created. */
98 int rs6000_sysv_varargs_p;
100 /* ABI enumeration available for subtarget to use. */
101 enum rs6000_abi rs6000_current_abi;
103 /* Offset & size for fpmem stack locations used for converting between
104 float and integral types. */
105 int rs6000_fpmem_offset;
106 int rs6000_fpmem_size;
108 /* Debug flags */
109 const char *rs6000_debug_name;
110 int rs6000_debug_stack; /* debug stack applications */
111 int rs6000_debug_arg; /* debug argument handling */
113 /* Flag to say the TOC is initialized */
114 int toc_initialized;
116 static void rs6000_add_gc_roots PARAMS ((void));
119 /* Default register names. */
120 char rs6000_reg_names[][8] =
122 "0", "1", "2", "3", "4", "5", "6", "7",
123 "8", "9", "10", "11", "12", "13", "14", "15",
124 "16", "17", "18", "19", "20", "21", "22", "23",
125 "24", "25", "26", "27", "28", "29", "30", "31",
126 "0", "1", "2", "3", "4", "5", "6", "7",
127 "8", "9", "10", "11", "12", "13", "14", "15",
128 "16", "17", "18", "19", "20", "21", "22", "23",
129 "24", "25", "26", "27", "28", "29", "30", "31",
130 "mq", "lr", "ctr","ap",
131 "0", "1", "2", "3", "4", "5", "6", "7",
132 "fpmem"
135 #ifdef TARGET_REGNAMES
136 static char alt_reg_names[][8] =
138 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
139 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
140 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
141 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
142 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
143 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
144 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
145 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
146 "mq", "lr", "ctr", "ap",
147 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
148 "fpmem"
150 #endif
152 #ifndef MASK_STRICT_ALIGN
153 #define MASK_STRICT_ALIGN 0
154 #endif
156 /* Override command line options. Mostly we process the processor
157 type and sometimes adjust other TARGET_ options. */
159 void
160 rs6000_override_options (default_cpu)
161 const char *default_cpu;
163 size_t i, j;
164 struct rs6000_cpu_select *ptr;
166 /* Simplify the entries below by making a mask for any POWER
167 variant and any PowerPC variant. */
169 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
170 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
171 | MASK_PPC_GFXOPT | MASK_POWERPC64)
172 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
174 static struct ptt
176 const char *name; /* Canonical processor name. */
177 enum processor_type processor; /* Processor type enum value. */
178 int target_enable; /* Target flags to enable. */
179 int target_disable; /* Target flags to disable. */
180 } processor_target_table[]
181 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
182 POWER_MASKS | POWERPC_MASKS},
183 {"power", PROCESSOR_POWER,
184 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
185 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
186 {"power2", PROCESSOR_POWER,
187 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
188 POWERPC_MASKS | MASK_NEW_MNEMONICS},
189 {"power3", PROCESSOR_PPC630,
190 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
191 POWER_MASKS | MASK_PPC_GPOPT},
192 {"powerpc", PROCESSOR_POWERPC,
193 MASK_POWERPC | MASK_NEW_MNEMONICS,
194 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
195 {"powerpc64", PROCESSOR_POWERPC64,
196 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
197 POWER_MASKS | POWERPC_OPT_MASKS},
198 {"rios", PROCESSOR_RIOS1,
199 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
200 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
201 {"rios1", PROCESSOR_RIOS1,
202 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
203 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
204 {"rsc", PROCESSOR_PPC601,
205 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
206 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
207 {"rsc1", PROCESSOR_PPC601,
208 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
209 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
210 {"rios2", PROCESSOR_RIOS2,
211 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
212 POWERPC_MASKS | MASK_NEW_MNEMONICS},
213 {"rs64a", PROCESSOR_RS64A,
214 MASK_POWERPC | MASK_NEW_MNEMONICS,
215 POWER_MASKS | POWERPC_OPT_MASKS},
216 {"401", PROCESSOR_PPC403,
217 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
218 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
219 {"403", PROCESSOR_PPC403,
220 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
221 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
222 {"505", PROCESSOR_MPCCORE,
223 MASK_POWERPC | MASK_NEW_MNEMONICS,
224 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
225 {"601", PROCESSOR_PPC601,
226 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
227 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
228 {"602", PROCESSOR_PPC603,
229 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
230 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
231 {"603", PROCESSOR_PPC603,
232 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
233 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
234 {"603e", PROCESSOR_PPC603,
235 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
236 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
237 {"ec603e", PROCESSOR_PPC603,
238 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
239 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
240 {"604", PROCESSOR_PPC604,
241 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
242 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
243 {"604e", PROCESSOR_PPC604e,
244 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
245 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
246 {"620", PROCESSOR_PPC620,
247 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
248 POWER_MASKS | MASK_PPC_GPOPT},
249 {"630", PROCESSOR_PPC630,
250 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
251 POWER_MASKS | MASK_PPC_GPOPT},
252 {"740", PROCESSOR_PPC750,
253 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
254 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
255 {"750", PROCESSOR_PPC750,
256 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
257 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
258 {"801", PROCESSOR_MPCCORE,
259 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
260 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
261 {"821", PROCESSOR_MPCCORE,
262 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
263 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
264 {"823", PROCESSOR_MPCCORE,
265 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
266 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
267 {"860", PROCESSOR_MPCCORE,
268 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
269 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
271 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
273 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
274 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
276 profile_block_flag = 0;
278 /* Identify the processor type */
279 rs6000_select[0].string = default_cpu;
280 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
282 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
284 ptr = &rs6000_select[i];
285 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
287 for (j = 0; j < ptt_size; j++)
288 if (! strcmp (ptr->string, processor_target_table[j].name))
290 if (ptr->set_tune_p)
291 rs6000_cpu = processor_target_table[j].processor;
293 if (ptr->set_arch_p)
295 target_flags |= processor_target_table[j].target_enable;
296 target_flags &= ~processor_target_table[j].target_disable;
298 break;
301 if (j == ptt_size)
302 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
306 /* If we are optimizing big endian systems for space, use the
307 store multiple instructions. */
308 if (BYTES_BIG_ENDIAN && optimize_size)
309 target_flags |= MASK_MULTIPLE;
311 /* If -mmultiple or -mno-multiple was explicitly used, don't
312 override with the processor default */
313 if (TARGET_MULTIPLE_SET)
314 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
316 /* If -mstring or -mno-string was explicitly used, don't
317 override with the processor default */
318 if (TARGET_STRING_SET)
319 target_flags = (target_flags & ~MASK_STRING) | string;
321 /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu
322 is a 750, because the hardware doesn't support the instructions used in
323 little endian mode, and causes an alignment trap. The 750 does not cause
324 an alignment trap (except when the target is unaligned). */
326 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
328 if (TARGET_MULTIPLE)
330 target_flags &= ~MASK_MULTIPLE;
331 if (TARGET_MULTIPLE_SET)
332 warning ("-mmultiple is not supported on little endian systems");
335 if (TARGET_STRING)
337 target_flags &= ~MASK_STRING;
338 if (TARGET_STRING_SET)
339 warning ("-mstring is not supported on little endian systems");
343 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
345 warning ("-f%s ignored for AIX (all code is position independent)",
346 (flag_pic > 1) ? "PIC" : "pic");
347 flag_pic = 0;
350 /* Set debug flags */
351 if (rs6000_debug_name)
353 if (! strcmp (rs6000_debug_name, "all"))
354 rs6000_debug_stack = rs6000_debug_arg = 1;
355 else if (! strcmp (rs6000_debug_name, "stack"))
356 rs6000_debug_stack = 1;
357 else if (! strcmp (rs6000_debug_name, "arg"))
358 rs6000_debug_arg = 1;
359 else
360 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
363 #ifdef TARGET_REGNAMES
364 /* If the user desires alternate register names, copy in the alternate names
365 now. */
366 if (TARGET_REGNAMES)
367 bcopy ((char *)alt_reg_names, (char *)rs6000_reg_names,
368 sizeof (rs6000_reg_names));
369 #endif
371 #ifdef SUBTARGET_OVERRIDE_OPTIONS
372 SUBTARGET_OVERRIDE_OPTIONS;
373 #endif
375 /* Register global variables with the garbage collector. */
376 rs6000_add_gc_roots ();
379 void
380 optimization_options (level, size)
381 int level;
382 int size ATTRIBUTE_UNUSED;
384 #ifdef HAVE_decrement_and_branch_on_count
385 /* When optimizing, enable use of BCT instruction. */
386 if (level >= 1)
387 flag_branch_on_count_reg = 1;
388 #endif
391 /* Do anything needed at the start of the asm file. */
393 void
394 rs6000_file_start (file, default_cpu)
395 FILE *file;
396 const char *default_cpu;
398 size_t i;
399 char buffer[80];
400 const char *start = buffer;
401 struct rs6000_cpu_select *ptr;
403 if (flag_verbose_asm)
405 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
406 rs6000_select[0].string = default_cpu;
408 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
410 ptr = &rs6000_select[i];
411 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
413 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
414 start = "";
418 #ifdef USING_SVR4_H
419 switch (rs6000_sdata)
421 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
422 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
423 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
424 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
427 if (rs6000_sdata && g_switch_value)
429 fprintf (file, "%s -G %d", start, g_switch_value);
430 start = "";
432 #endif
434 if (*start == '\0')
435 putc ('\n', file);
440 /* Create a CONST_DOUBLE from a string. */
442 struct rtx_def *
443 rs6000_float_const (string, mode)
444 const char *string;
445 enum machine_mode mode;
447 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
448 return immed_real_const_1 (value, mode);
451 /* Return non-zero if this function is known to have a null epilogue. */
454 direct_return ()
456 if (reload_completed)
458 rs6000_stack_t *info = rs6000_stack_info ();
460 if (info->first_gp_reg_save == 32
461 && info->first_fp_reg_save == 64
462 && ! info->lr_save_p
463 && ! info->cr_save_p
464 && ! info->push_p)
465 return 1;
468 return 0;
471 /* Returns 1 always. */
474 any_operand (op, mode)
475 register rtx op ATTRIBUTE_UNUSED;
476 enum machine_mode mode ATTRIBUTE_UNUSED;
478 return 1;
481 /* Returns 1 if op is the count register */
483 count_register_operand(op, mode)
484 register rtx op;
485 enum machine_mode mode ATTRIBUTE_UNUSED;
487 if (GET_CODE (op) != REG)
488 return 0;
490 if (REGNO (op) == COUNT_REGISTER_REGNUM)
491 return 1;
493 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
494 return 1;
496 return 0;
499 /* Returns 1 if op is memory location for float/int conversions that masquerades
500 as a register. */
502 fpmem_operand(op, mode)
503 register rtx op;
504 enum machine_mode mode ATTRIBUTE_UNUSED;
506 if (GET_CODE (op) != REG)
507 return 0;
509 if (FPMEM_REGNO_P (REGNO (op)))
510 return 1;
512 #if 0
513 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
514 return 1;
515 #endif
517 return 0;
520 /* Return 1 if OP is a constant that can fit in a D field. */
523 short_cint_operand (op, mode)
524 register rtx op;
525 enum machine_mode mode ATTRIBUTE_UNUSED;
527 return (GET_CODE (op) == CONST_INT
528 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
531 /* Similar for a unsigned D field. */
534 u_short_cint_operand (op, mode)
535 register rtx op;
536 enum machine_mode mode ATTRIBUTE_UNUSED;
538 return (GET_CODE (op) == CONST_INT
539 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
542 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
545 non_short_cint_operand (op, mode)
546 register rtx op;
547 enum machine_mode mode ATTRIBUTE_UNUSED;
549 return (GET_CODE (op) == CONST_INT
550 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
553 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
554 ctr, or lr). */
557 gpc_reg_operand (op, mode)
558 register rtx op;
559 enum machine_mode mode;
561 return (register_operand (op, mode)
562 && (GET_CODE (op) != REG
563 || (REGNO (op) >= 67 && !FPMEM_REGNO_P (REGNO (op)))
564 || REGNO (op) < 64));
567 /* Returns 1 if OP is either a pseudo-register or a register denoting a
568 CR field. */
571 cc_reg_operand (op, mode)
572 register rtx op;
573 enum machine_mode mode;
575 return (register_operand (op, mode)
576 && (GET_CODE (op) != REG
577 || REGNO (op) >= FIRST_PSEUDO_REGISTER
578 || CR_REGNO_P (REGNO (op))));
581 /* Returns 1 if OP is either a pseudo-register or a register denoting a
582 CR field that isn't CR0. */
585 cc_reg_not_cr0_operand (op, mode)
586 register rtx op;
587 enum machine_mode mode;
589 return (register_operand (op, mode)
590 && (GET_CODE (op) != REG
591 || REGNO (op) >= FIRST_PSEUDO_REGISTER
592 || CR_REGNO_NOT_CR0_P (REGNO (op))));
595 /* Returns 1 if OP is either a constant integer valid for a D-field or a
596 non-special register. If a register, it must be in the proper mode unless
597 MODE is VOIDmode. */
600 reg_or_short_operand (op, mode)
601 register rtx op;
602 enum machine_mode mode;
604 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
607 /* Similar, except check if the negation of the constant would be valid for
608 a D-field. */
611 reg_or_neg_short_operand (op, mode)
612 register rtx op;
613 enum machine_mode mode;
615 if (GET_CODE (op) == CONST_INT)
616 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
618 return gpc_reg_operand (op, mode);
621 /* Return 1 if the operand is either a register or an integer whose high-order
622 16 bits are zero. */
625 reg_or_u_short_operand (op, mode)
626 register rtx op;
627 enum machine_mode mode;
629 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
632 /* Return 1 is the operand is either a non-special register or ANY
633 constant integer. */
636 reg_or_cint_operand (op, mode)
637 register rtx op;
638 enum machine_mode mode;
640 return (GET_CODE (op) == CONST_INT
641 || gpc_reg_operand (op, mode));
644 /* Return 1 if the operand is an operand that can be loaded via the GOT */
647 got_operand (op, mode)
648 register rtx op;
649 enum machine_mode mode ATTRIBUTE_UNUSED;
651 return (GET_CODE (op) == SYMBOL_REF
652 || GET_CODE (op) == CONST
653 || GET_CODE (op) == LABEL_REF);
656 /* Return 1 if the operand is a simple references that can be loaded via
657 the GOT (labels involving addition aren't allowed). */
660 got_no_const_operand (op, mode)
661 register rtx op;
662 enum machine_mode mode ATTRIBUTE_UNUSED;
664 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
667 /* Return the number of instructions it takes to form a constant in an
668 integer register. */
670 static int
671 num_insns_constant_wide (value)
672 HOST_WIDE_INT value;
674 /* signed constant loadable with {cal|addi} */
675 if (CONST_OK_FOR_LETTER_P (value, 'I'))
676 return 1;
678 /* constant loadable with {cau|addis} */
679 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
680 return 1;
682 #if HOST_BITS_PER_WIDE_INT == 64
683 else if (TARGET_POWERPC64)
685 HOST_WIDE_INT low = value & 0xffffffff;
686 HOST_WIDE_INT high = value >> 32;
688 if (high == 0 && (low & 0x80000000) == 0)
689 return 2;
691 else if (high == -1 && (low & 0x80000000) != 0)
692 return 2;
694 else if (! low)
695 return num_insns_constant_wide (high) + 1;
697 else
698 return (num_insns_constant_wide (high)
699 + num_insns_constant_wide (low) + 1);
701 #endif
703 else
704 return 2;
708 num_insns_constant (op, mode)
709 rtx op;
710 enum machine_mode mode;
712 if (GET_CODE (op) == CONST_INT)
713 return num_insns_constant_wide (INTVAL (op));
715 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
717 long l;
718 REAL_VALUE_TYPE rv;
720 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
721 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
722 return num_insns_constant_wide ((HOST_WIDE_INT)l);
725 else if (GET_CODE (op) == CONST_DOUBLE)
727 HOST_WIDE_INT low;
728 HOST_WIDE_INT high;
729 long l[2];
730 REAL_VALUE_TYPE rv;
731 int endian = (WORDS_BIG_ENDIAN == 0);
733 if (mode == VOIDmode || mode == DImode)
735 high = CONST_DOUBLE_HIGH (op);
736 low = CONST_DOUBLE_LOW (op);
738 else
740 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
741 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
742 high = l[endian];
743 low = l[1 - endian];
746 if (TARGET_32BIT)
747 return (num_insns_constant_wide (low)
748 + num_insns_constant_wide (high));
750 else
752 if (high == 0 && (low & 0x80000000) == 0)
753 return num_insns_constant_wide (low);
755 else if (high == -1 && (low & 0x80000000) != 0)
756 return num_insns_constant_wide (low);
758 else if (mask64_operand (op, mode))
759 return 2;
761 else if (low == 0)
762 return num_insns_constant_wide (high) + 1;
764 else
765 return (num_insns_constant_wide (high)
766 + num_insns_constant_wide (low) + 1);
770 else
771 abort ();
774 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
775 with one instruction per word. We only do this if we can safely read
776 CONST_DOUBLE_{LOW,HIGH}. */
779 easy_fp_constant (op, mode)
780 register rtx op;
781 register enum machine_mode mode;
783 if (GET_CODE (op) != CONST_DOUBLE
784 || GET_MODE (op) != mode
785 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
786 return 0;
788 /* Consider all constants with -msoft-float to be easy */
789 if (TARGET_SOFT_FLOAT && mode != DImode)
790 return 1;
792 /* If we are using V.4 style PIC, consider all constants to be hard */
793 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
794 return 0;
796 #ifdef TARGET_RELOCATABLE
797 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
798 if (TARGET_RELOCATABLE)
799 return 0;
800 #endif
802 if (mode == DFmode)
804 long k[2];
805 REAL_VALUE_TYPE rv;
807 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
808 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
810 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
811 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
814 else if (mode == SFmode)
816 long l;
817 REAL_VALUE_TYPE rv;
819 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
820 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
822 return num_insns_constant_wide (l) == 1;
825 else if (mode == DImode)
826 return ((TARGET_POWERPC64
827 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
828 || (num_insns_constant (op, DImode) <= 2));
830 else
831 abort ();
834 /* Return 1 if the operand is in volatile memory. Note that during the
835 RTL generation phase, memory_operand does not return TRUE for
836 volatile memory references. So this function allows us to
837 recognize volatile references where its safe. */
840 volatile_mem_operand (op, mode)
841 register rtx op;
842 enum machine_mode mode;
844 if (GET_CODE (op) != MEM)
845 return 0;
847 if (!MEM_VOLATILE_P (op))
848 return 0;
850 if (mode != GET_MODE (op))
851 return 0;
853 if (reload_completed)
854 return memory_operand (op, mode);
856 if (reload_in_progress)
857 return strict_memory_address_p (mode, XEXP (op, 0));
859 return memory_address_p (mode, XEXP (op, 0));
862 /* Return 1 if the operand is an offsettable memory operand. */
865 offsettable_mem_operand (op, mode)
866 register rtx op;
867 enum machine_mode mode;
869 return ((GET_CODE (op) == MEM)
870 && offsettable_address_p (reload_completed || reload_in_progress,
871 mode, XEXP (op, 0)));
874 /* Return 1 if the operand is either an easy FP constant (see above) or
875 memory. */
878 mem_or_easy_const_operand (op, mode)
879 register rtx op;
880 enum machine_mode mode;
882 return memory_operand (op, mode) || easy_fp_constant (op, mode);
885 /* Return 1 if the operand is either a non-special register or an item
886 that can be used as the operand of a `mode' add insn. */
889 add_operand (op, mode)
890 register rtx op;
891 enum machine_mode mode;
893 return (reg_or_short_operand (op, mode)
894 || (GET_CODE (op) == CONST_INT
895 && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')));
898 /* Return 1 if OP is a constant but not a valid add_operand. */
901 non_add_cint_operand (op, mode)
902 register rtx op;
903 enum machine_mode mode ATTRIBUTE_UNUSED;
905 return (GET_CODE (op) == CONST_INT
906 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
907 && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'));
910 /* Return 1 if the operand is a non-special register or a constant that
911 can be used as the operand of an OR or XOR insn on the RS/6000. */
914 logical_operand (op, mode)
915 register rtx op;
916 enum machine_mode mode;
918 return (gpc_reg_operand (op, mode)
919 || (GET_CODE (op) == CONST_INT
920 && ((INTVAL (op) & GET_MODE_MASK (mode)
921 & (~ (HOST_WIDE_INT) 0xffff)) == 0
922 || (INTVAL (op) & GET_MODE_MASK (mode)
923 & (~ (HOST_WIDE_INT) 0xffff0000)) == 0)));
926 /* Return 1 if C is a constant that is not a logical operand (as
927 above). */
930 non_logical_cint_operand (op, mode)
931 register rtx op;
932 enum machine_mode mode;
934 return (GET_CODE (op) == CONST_INT
935 && (INTVAL (op) & GET_MODE_MASK (mode) &
936 (~ (HOST_WIDE_INT) 0xffff)) != 0
937 && (INTVAL (op) & GET_MODE_MASK (mode) &
938 (~ (HOST_WIDE_INT) 0xffff0000)) != 0);
941 /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
942 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
943 Reject all ones and all zeros, since these should have been optimized
944 away and confuse the making of MB and ME. */
947 mask_operand (op, mode)
948 register rtx op;
949 enum machine_mode mode ATTRIBUTE_UNUSED;
951 HOST_WIDE_INT c;
952 int i;
953 int last_bit_value;
954 int transitions = 0;
956 if (GET_CODE (op) != CONST_INT)
957 return 0;
959 c = INTVAL (op);
961 if (c == 0 || c == ~0)
962 return 0;
964 last_bit_value = c & 1;
966 for (i = 1; i < 32; i++)
967 if (((c >>= 1) & 1) != last_bit_value)
968 last_bit_value ^= 1, transitions++;
970 return transitions <= 2;
973 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
974 It is if there are no more than one 1->0 or 0->1 transitions.
975 Reject all ones and all zeros, since these should have been optimized
976 away and confuse the making of MB and ME. */
979 mask64_operand (op, mode)
980 register rtx op;
981 enum machine_mode mode;
983 if (GET_CODE (op) == CONST_INT)
985 HOST_WIDE_INT c = INTVAL (op);
986 int i;
987 int last_bit_value;
988 int transitions = 0;
990 if (c == 0 || c == ~0)
991 return 0;
993 last_bit_value = c & 1;
995 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
996 if (((c >>= 1) & 1) != last_bit_value)
997 last_bit_value ^= 1, transitions++;
999 #if HOST_BITS_PER_WIDE_INT == 32
1000 /* Consider CONST_INT sign-extended. */
1001 transitions += (last_bit_value != 1);
1002 #endif
1004 return transitions <= 1;
1006 else if (GET_CODE (op) == CONST_DOUBLE
1007 && (mode == VOIDmode || mode == DImode))
1009 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1010 #if HOST_BITS_PER_WIDE_INT == 32
1011 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1012 #endif
1013 int i;
1014 int last_bit_value;
1015 int transitions = 0;
1017 if ((low == 0
1018 #if HOST_BITS_PER_WIDE_INT == 32
1019 && high == 0
1020 #endif
1022 || (low == ~0
1023 #if HOST_BITS_PER_WIDE_INT == 32
1024 && high == ~0
1025 #endif
1027 return 0;
1029 last_bit_value = low & 1;
1031 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1032 if (((low >>= 1) & 1) != last_bit_value)
1033 last_bit_value ^= 1, transitions++;
1035 #if HOST_BITS_PER_WIDE_INT == 32
1036 if ((high & 1) != last_bit_value)
1037 last_bit_value ^= 1, transitions++;
1039 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1040 if (((high >>= 1) & 1) != last_bit_value)
1041 last_bit_value ^= 1, transitions++;
1042 #endif
1044 return transitions <= 1;
1046 else
1047 return 0;
1050 /* Return 1 if the operand is either a non-special register or a constant
1051 that can be used as the operand of a PowerPC64 logical AND insn. */
1054 and64_operand (op, mode)
1055 register rtx op;
1056 enum machine_mode mode;
1058 if (fixed_regs[68]) /* CR0 not available, don't do andi./andis. */
1059 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1061 return (logical_operand (op, mode) || mask64_operand (op, mode));
1064 /* Return 1 if the operand is either a non-special register or a
1065 constant that can be used as the operand of an RS/6000 logical AND insn. */
1068 and_operand (op, mode)
1069 register rtx op;
1070 enum machine_mode mode;
1072 if (fixed_regs[68]) /* CR0 not available, don't do andi./andis. */
1073 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1075 return (logical_operand (op, mode) || mask_operand (op, mode));
1078 /* Return 1 if the operand is a general register or memory operand. */
1081 reg_or_mem_operand (op, mode)
1082 register rtx op;
1083 register enum machine_mode mode;
1085 return (gpc_reg_operand (op, mode)
1086 || memory_operand (op, mode)
1087 || volatile_mem_operand (op, mode));
1090 /* Return 1 if the operand is a general register or memory operand without
1091 pre_inc or pre_dec which produces invalid form of PowerPC lwa
1092 instruction. */
1095 lwa_operand (op, mode)
1096 register rtx op;
1097 register enum machine_mode mode;
1099 rtx inner = op;
1101 if (reload_completed && GET_CODE (inner) == SUBREG)
1102 inner = SUBREG_REG (inner);
1104 return gpc_reg_operand (inner, mode)
1105 || (memory_operand (inner, mode)
1106 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1107 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1110 /* Return 1 if the operand, used inside a MEM, is a valid first argument
1111 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1112 forced to lr. */
1115 call_operand (op, mode)
1116 register rtx op;
1117 enum machine_mode mode;
1119 if (mode != VOIDmode && GET_MODE (op) != mode)
1120 return 0;
1122 return (GET_CODE (op) == SYMBOL_REF
1123 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1127 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
1128 this file and the function is not weakly defined. */
1131 current_file_function_operand (op, mode)
1132 register rtx op;
1133 enum machine_mode mode ATTRIBUTE_UNUSED;
1135 return (GET_CODE (op) == SYMBOL_REF
1136 && (SYMBOL_REF_FLAG (op)
1137 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1138 && ! DECL_WEAK (current_function_decl))));
1142 /* Return 1 if this operand is a valid input for a move insn. */
1145 input_operand (op, mode)
1146 register rtx op;
1147 enum machine_mode mode;
1149 /* Memory is always valid. */
1150 if (memory_operand (op, mode))
1151 return 1;
1153 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1154 if (GET_CODE (op) == CONSTANT_P_RTX)
1155 return 1;
1157 /* For floating-point, easy constants are valid. */
1158 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1159 && CONSTANT_P (op)
1160 && easy_fp_constant (op, mode))
1161 return 1;
1163 /* Allow any integer constant. */
1164 if (GET_MODE_CLASS (mode) == MODE_INT
1165 && (GET_CODE (op) == CONST_INT
1166 || GET_CODE (op) == CONST_DOUBLE))
1167 return 1;
1169 /* For floating-point or multi-word mode, the only remaining valid type
1170 is a register. */
1171 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1172 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1173 return register_operand (op, mode);
1175 /* The only cases left are integral modes one word or smaller (we
1176 do not get called for MODE_CC values). These can be in any
1177 register. */
1178 if (register_operand (op, mode))
1179 return 1;
1181 /* A SYMBOL_REF referring to the TOC is valid. */
1182 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
1183 return 1;
1185 /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC
1186 directly in the instruction stream */
1187 if (DEFAULT_ABI == ABI_NT
1188 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF))
1189 return 1;
1191 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1192 to be valid. */
1193 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1194 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1195 && small_data_operand (op, Pmode))
1196 return 1;
1198 return 0;
1201 /* Return 1 for an operand in small memory on V.4/eabi */
1204 small_data_operand (op, mode)
1205 rtx op ATTRIBUTE_UNUSED;
1206 enum machine_mode mode ATTRIBUTE_UNUSED;
1208 #if TARGET_ELF
1209 rtx sym_ref;
1211 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
1212 return 0;
1214 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1215 return 0;
1217 if (GET_CODE (op) == SYMBOL_REF)
1218 sym_ref = op;
1220 else if (GET_CODE (op) != CONST
1221 || GET_CODE (XEXP (op, 0)) != PLUS
1222 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1223 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
1224 return 0;
1226 else
1228 rtx sum = XEXP (op, 0);
1229 HOST_WIDE_INT summand;
1231 /* We have to be careful here, because it is the referenced address
1232 that must be 32k from _SDA_BASE_, not just the symbol. */
1233 summand = INTVAL (XEXP (sum, 1));
1234 if (summand < 0 || summand > g_switch_value)
1235 return 0;
1237 sym_ref = XEXP (sum, 0);
1240 if (*XSTR (sym_ref, 0) != '@')
1241 return 0;
1243 return 1;
1245 #else
1246 return 0;
1247 #endif
1251 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1252 for a call to a function whose data type is FNTYPE.
1253 For a library call, FNTYPE is 0.
1255 For incoming args we set the number of arguments in the prototype large
1256 so we never return a PARALLEL. */
1258 void
1259 init_cumulative_args (cum, fntype, libname, incoming)
1260 CUMULATIVE_ARGS *cum;
1261 tree fntype;
1262 rtx libname ATTRIBUTE_UNUSED;
1263 int incoming;
1265 static CUMULATIVE_ARGS zero_cumulative;
1266 enum rs6000_abi abi = DEFAULT_ABI;
1268 *cum = zero_cumulative;
1269 cum->words = 0;
1270 cum->fregno = FP_ARG_MIN_REG;
1271 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
1272 cum->call_cookie = CALL_NORMAL;
1273 cum->sysv_gregno = GP_ARG_MIN_REG;
1275 if (incoming)
1276 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
1278 else if (cum->prototype)
1279 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1280 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1281 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1283 else
1284 cum->nargs_prototype = 0;
1286 cum->orig_nargs = cum->nargs_prototype;
1288 /* Check for DLL import functions */
1289 if (abi == ABI_NT
1290 && fntype
1291 && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype)))
1292 cum->call_cookie = CALL_NT_DLLIMPORT;
1294 /* Also check for longcall's */
1295 else if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1296 cum->call_cookie = CALL_LONG;
1298 if (TARGET_DEBUG_ARG)
1300 fprintf (stderr, "\ninit_cumulative_args:");
1301 if (fntype)
1303 tree ret_type = TREE_TYPE (fntype);
1304 fprintf (stderr, " ret code = %s,",
1305 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1308 if (cum->call_cookie & CALL_NT_DLLIMPORT)
1309 fprintf (stderr, " dllimport,");
1311 if (cum->call_cookie & CALL_LONG)
1312 fprintf (stderr, " longcall,");
1314 fprintf (stderr, " proto = %d, nargs = %d\n",
1315 cum->prototype, cum->nargs_prototype);
1319 /* If defined, a C expression which determines whether, and in which
1320 direction, to pad out an argument with extra space. The value
1321 should be of type `enum direction': either `upward' to pad above
1322 the argument, `downward' to pad below, or `none' to inhibit
1323 padding.
1325 For the AIX ABI structs are always stored left shifted in their
1326 argument slot. */
1329 function_arg_padding (mode, type)
1330 enum machine_mode mode;
1331 tree type;
1333 if (type != 0 && AGGREGATE_TYPE_P (type))
1334 return (int)upward;
1336 /* This is the default definition. */
1337 return (! BYTES_BIG_ENDIAN
1338 ? (int)upward
1339 : ((mode == BLKmode
1340 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1341 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1342 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
1343 ? (int)downward : (int)upward));
1346 /* If defined, a C expression that gives the alignment boundary, in bits,
1347 of an argument with the specified mode and type. If it is not defined,
1348 PARM_BOUNDARY is used for all arguments.
1350 Windows NT wants anything >= 8 bytes to be double word aligned.
1352 V.4 wants long longs to be double word aligned. */
1355 function_arg_boundary (mode, type)
1356 enum machine_mode mode;
1357 tree type;
1359 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1360 && (mode == DImode || mode == DFmode))
1361 return 64;
1363 if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
1364 return PARM_BOUNDARY;
1366 if (mode != BLKmode)
1367 return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32;
1369 return (int_size_in_bytes (type) >= 8) ? 64 : 32;
1372 /* Update the data in CUM to advance over an argument
1373 of mode MODE and data type TYPE.
1374 (TYPE is null for libcalls where that information may not be available.) */
1376 void
1377 function_arg_advance (cum, mode, type, named)
1378 CUMULATIVE_ARGS *cum;
1379 enum machine_mode mode;
1380 tree type;
1381 int named;
1383 cum->nargs_prototype--;
1385 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1387 if (TARGET_HARD_FLOAT
1388 && (mode == SFmode || mode == DFmode))
1390 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1391 cum->fregno++;
1392 else
1394 if (mode == DFmode)
1395 cum->words += cum->words & 1;
1396 cum->words += RS6000_ARG_SIZE (mode, type, 1);
1399 else
1401 int n_words;
1402 int gregno = cum->sysv_gregno;
1404 /* Aggregates and IEEE quad get passed by reference. */
1405 if ((type && AGGREGATE_TYPE_P (type))
1406 || mode == TFmode)
1407 n_words = 1;
1408 else
1409 n_words = RS6000_ARG_SIZE (mode, type, 1);
1411 /* Long long is put in odd registers. */
1412 if (n_words == 2 && (gregno & 1) == 0)
1413 gregno += 1;
1415 /* Long long is not split between registers and stack. */
1416 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
1418 /* Long long is aligned on the stack. */
1419 if (n_words == 2)
1420 cum->words += cum->words & 1;
1421 cum->words += n_words;
1424 /* Note: continuing to accumulate gregno past when we've started
1425 spilling to the stack indicates the fact that we've started
1426 spilling to the stack to expand_builtin_saveregs. */
1427 cum->sysv_gregno = gregno + n_words;
1430 if (TARGET_DEBUG_ARG)
1432 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1433 cum->words, cum->fregno);
1434 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
1435 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
1436 fprintf (stderr, "mode = %4s, named = %d\n",
1437 GET_MODE_NAME (mode), named);
1440 else
1442 int align = (TARGET_32BIT && (cum->words & 1) != 0
1443 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1444 cum->words += align;
1446 if (named)
1448 cum->words += RS6000_ARG_SIZE (mode, type, named);
1449 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
1450 cum->fregno++;
1453 if (TARGET_DEBUG_ARG)
1455 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1456 cum->words, cum->fregno);
1457 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
1458 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
1459 fprintf (stderr, "named = %d, align = %d\n", named, align);
1464 /* Determine where to put an argument to a function.
1465 Value is zero to push the argument on the stack,
1466 or a hard register in which to store the argument.
1468 MODE is the argument's machine mode.
1469 TYPE is the data type of the argument (as a tree).
1470 This is null for libcalls where that information may
1471 not be available.
1472 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1473 the preceding args and about the function being called.
1474 NAMED is nonzero if this argument is a named parameter
1475 (otherwise it is an extra parameter matching an ellipsis).
1477 On RS/6000 the first eight words of non-FP are normally in registers
1478 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
1479 Under V.4, the first 8 FP args are in registers.
1481 If this is floating-point and no prototype is specified, we use
1482 both an FP and integer register (or possibly FP reg and stack). Library
1483 functions (when TYPE is zero) always have the proper types for args,
1484 so we can pass the FP value just in one register. emit_library_function
1485 doesn't support PARALLEL anyway. */
1487 struct rtx_def *
1488 function_arg (cum, mode, type, named)
1489 CUMULATIVE_ARGS *cum;
1490 enum machine_mode mode;
1491 tree type;
1492 int named;
1494 enum rs6000_abi abi = DEFAULT_ABI;
1496 /* Return a marker to indicate whether CR1 needs to set or clear the bit
1497 that V.4 uses to say fp args were passed in registers. Assume that we
1498 don't need the marker for software floating point, or compiler generated
1499 library calls. */
1500 if (mode == VOIDmode)
1502 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
1503 && TARGET_HARD_FLOAT
1504 && cum->nargs_prototype < 0
1505 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
1507 return GEN_INT (cum->call_cookie
1508 | ((cum->fregno == FP_ARG_MIN_REG)
1509 ? CALL_V4_SET_FP_ARGS
1510 : CALL_V4_CLEAR_FP_ARGS));
1513 return GEN_INT (cum->call_cookie);
1516 if (abi == ABI_V4 || abi == ABI_SOLARIS)
1518 if (TARGET_HARD_FLOAT
1519 && (mode == SFmode || mode == DFmode))
1521 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1522 return gen_rtx_REG (mode, cum->fregno);
1523 else
1524 return NULL;
1526 else
1528 int n_words;
1529 int gregno = cum->sysv_gregno;
1531 /* Aggregates and IEEE quad get passed by reference. */
1532 if ((type && AGGREGATE_TYPE_P (type))
1533 || mode == TFmode)
1534 n_words = 1;
1535 else
1536 n_words = RS6000_ARG_SIZE (mode, type, 1);
1538 /* Long long is put in odd registers. */
1539 if (n_words == 2 && (gregno & 1) == 0)
1540 gregno += 1;
1542 /* Long long is not split between registers and stack. */
1543 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
1544 return gen_rtx_REG (mode, gregno);
1545 else
1546 return NULL;
1549 else
1551 int align = (TARGET_32BIT && (cum->words & 1) != 0
1552 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1553 int align_words = cum->words + align;
1555 if (! named)
1556 return NULL_RTX;
1558 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1559 return NULL_RTX;
1561 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1563 if (! type
1564 || ((cum->nargs_prototype > 0)
1565 /* IBM AIX extended its linkage convention definition always
1566 to require FP args after register save area hole on the
1567 stack. */
1568 && (DEFAULT_ABI != ABI_AIX
1569 || ! TARGET_XL_CALL
1570 || (align_words < GP_ARG_NUM_REG))))
1571 return gen_rtx_REG (mode, cum->fregno);
1573 return gen_rtx_PARALLEL (mode,
1574 gen_rtvec (2,
1575 gen_rtx_EXPR_LIST (VOIDmode,
1576 ((align_words >= GP_ARG_NUM_REG)
1577 ? NULL_RTX
1578 : (align_words
1579 + RS6000_ARG_SIZE (mode, type, named)
1580 > GP_ARG_NUM_REG
1581 /* If this is partially on the stack, then
1582 we only include the portion actually
1583 in registers here. */
1584 ? gen_rtx_REG (SImode,
1585 GP_ARG_MIN_REG + align_words)
1586 : gen_rtx_REG (mode,
1587 GP_ARG_MIN_REG + align_words))),
1588 const0_rtx),
1589 gen_rtx_EXPR_LIST (VOIDmode,
1590 gen_rtx_REG (mode, cum->fregno),
1591 const0_rtx)));
1593 else if (align_words < GP_ARG_NUM_REG)
1594 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
1595 else
1596 return NULL_RTX;
1600 /* For an arg passed partly in registers and partly in memory,
1601 this is the number of registers used.
1602 For args passed entirely in registers or entirely in memory, zero. */
1605 function_arg_partial_nregs (cum, mode, type, named)
1606 CUMULATIVE_ARGS *cum;
1607 enum machine_mode mode;
1608 tree type;
1609 int named;
1611 if (! named)
1612 return 0;
1614 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1615 return 0;
1617 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1619 if (cum->nargs_prototype >= 0)
1620 return 0;
1623 if (cum->words < GP_ARG_NUM_REG
1624 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
1626 int ret = GP_ARG_NUM_REG - cum->words;
1627 if (ret && TARGET_DEBUG_ARG)
1628 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
1630 return ret;
1633 return 0;
1636 /* A C expression that indicates when an argument must be passed by
1637 reference. If nonzero for an argument, a copy of that argument is
1638 made in memory and a pointer to the argument is passed instead of
1639 the argument itself. The pointer is passed in whatever way is
1640 appropriate for passing a pointer to that type.
1642 Under V.4, structures and unions are passed by reference. */
1645 function_arg_pass_by_reference (cum, mode, type, named)
1646 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
1647 enum machine_mode mode ATTRIBUTE_UNUSED;
1648 tree type;
1649 int named ATTRIBUTE_UNUSED;
1651 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1652 && ((type && AGGREGATE_TYPE_P (type))
1653 || mode == TFmode))
1655 if (TARGET_DEBUG_ARG)
1656 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
1658 return 1;
1661 return 0;
1665 /* Perform any needed actions needed for a function that is receiving a
1666 variable number of arguments.
1668 CUM is as above.
1670 MODE and TYPE are the mode and type of the current parameter.
1672 PRETEND_SIZE is a variable that should be set to the amount of stack
1673 that must be pushed by the prolog to pretend that our caller pushed
1676 Normally, this macro will push all remaining incoming registers on the
1677 stack and set PRETEND_SIZE to the length of the registers pushed. */
1679 void
1680 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
1681 CUMULATIVE_ARGS *cum;
1682 enum machine_mode mode;
1683 tree type;
1684 int *pretend_size;
1685 int no_rtl;
1688 CUMULATIVE_ARGS next_cum;
1689 int reg_size = TARGET_32BIT ? 4 : 8;
1690 rtx save_area, mem;
1691 int first_reg_offset, set;
1693 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1695 tree fntype;
1696 int stdarg_p;
1698 fntype = TREE_TYPE (current_function_decl);
1699 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
1700 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1701 != void_type_node));
1703 /* For varargs, we do not want to skip the dummy va_dcl argument.
1704 For stdargs, we do want to skip the last named argument. */
1705 next_cum = *cum;
1706 if (stdarg_p)
1707 function_arg_advance (&next_cum, mode, type, 1);
1709 /* Indicate to allocate space on the stack for varargs save area. */
1710 /* ??? Does this really have to be located at a magic spot on the
1711 stack, or can we allocate this with assign_stack_local instead. */
1712 rs6000_sysv_varargs_p = 1;
1713 if (! no_rtl)
1714 save_area = plus_constant (virtual_stack_vars_rtx,
1715 - RS6000_VARARGS_SIZE);
1717 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
1719 else
1721 save_area = virtual_incoming_args_rtx;
1722 rs6000_sysv_varargs_p = 0;
1724 first_reg_offset = cum->words;
1725 if (MUST_PASS_IN_STACK (mode, type))
1726 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
1729 set = get_varargs_alias_set ();
1730 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
1732 mem = gen_rtx_MEM (BLKmode,
1733 plus_constant (save_area,
1734 first_reg_offset * reg_size)),
1735 MEM_ALIAS_SET (mem) = set;
1737 move_block_from_reg
1738 (GP_ARG_MIN_REG + first_reg_offset, mem,
1739 GP_ARG_NUM_REG - first_reg_offset,
1740 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
1742 /* ??? Does ABI_V4 need this at all? */
1743 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
1746 /* Save FP registers if needed. */
1747 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1748 && TARGET_HARD_FLOAT && ! no_rtl
1749 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
1751 int fregno = next_cum.fregno;
1752 rtx cr1 = gen_rtx_REG (CCmode, 69);
1753 rtx lab = gen_label_rtx ();
1754 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
1756 emit_jump_insn (gen_rtx_SET (VOIDmode,
1757 pc_rtx,
1758 gen_rtx_IF_THEN_ELSE (VOIDmode,
1759 gen_rtx_NE (VOIDmode, cr1,
1760 const0_rtx),
1761 gen_rtx_LABEL_REF (VOIDmode, lab),
1762 pc_rtx)));
1764 while (fregno <= FP_ARG_V4_MAX_REG)
1766 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
1767 MEM_ALIAS_SET (mem) = set;
1768 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
1769 fregno++;
1770 off += 8;
1773 emit_label (lab);
1777 /* Create the va_list data type. */
1779 tree
1780 rs6000_build_va_list ()
1782 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
1783 tree uchar_type_node;
1785 /* Only SVR4 needs something special. */
1786 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1787 return ptr_type_node;
1789 record = make_lang_type (RECORD_TYPE);
1790 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
1791 uchar_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
1793 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), uchar_type_node);
1794 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), uchar_type_node);
1795 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
1796 ptr_type_node);
1797 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
1798 ptr_type_node);
1800 DECL_FIELD_CONTEXT (f_gpr) = record;
1801 DECL_FIELD_CONTEXT (f_fpr) = record;
1802 DECL_FIELD_CONTEXT (f_ovf) = record;
1803 DECL_FIELD_CONTEXT (f_sav) = record;
1805 TREE_CHAIN (record) = type_decl;
1806 TYPE_NAME (record) = type_decl;
1807 TYPE_FIELDS (record) = f_gpr;
1808 TREE_CHAIN (f_gpr) = f_fpr;
1809 TREE_CHAIN (f_fpr) = f_ovf;
1810 TREE_CHAIN (f_ovf) = f_sav;
1812 layout_type (record);
1814 /* The correct type is an array type of one element. */
1815 return build_array_type (record, build_index_type (size_zero_node));
1818 /* Implement va_start. */
1820 void
1821 rs6000_va_start (stdarg_p, valist, nextarg)
1822 int stdarg_p;
1823 tree valist;
1824 rtx nextarg;
1826 HOST_WIDE_INT words, n_gpr, n_fpr;
1827 tree f_gpr, f_fpr, f_ovf, f_sav;
1828 tree gpr, fpr, ovf, sav, t;
1830 /* Only SVR4 needs something special. */
1831 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1833 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
1834 return;
1837 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
1838 f_fpr = TREE_CHAIN (f_gpr);
1839 f_ovf = TREE_CHAIN (f_fpr);
1840 f_sav = TREE_CHAIN (f_ovf);
1842 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
1843 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
1844 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
1845 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
1846 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
1848 /* Count number of gp and fp argument registers used. */
1849 words = current_function_args_info.words;
1850 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
1851 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
1853 if (TARGET_DEBUG_ARG)
1854 fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n",
1855 words, n_gpr, n_fpr);
1857 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
1858 TREE_SIDE_EFFECTS (t) = 1;
1859 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1861 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
1862 TREE_SIDE_EFFECTS (t) = 1;
1863 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1865 /* Find the overflow area. */
1866 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
1867 if (words != 0)
1868 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
1869 build_int_2 (words * UNITS_PER_WORD, 0));
1870 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
1871 TREE_SIDE_EFFECTS (t) = 1;
1872 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1874 /* Find the register save area. */
1875 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
1876 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
1877 build_int_2 (-RS6000_VARARGS_SIZE, -1));
1878 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
1879 TREE_SIDE_EFFECTS (t) = 1;
1880 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1883 /* Implement va_arg. */
1886 rs6000_va_arg (valist, type)
1887 tree valist, type;
1889 tree f_gpr, f_fpr, f_ovf, f_sav;
1890 tree gpr, fpr, ovf, sav, reg, t, u;
1891 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
1892 rtx lab_false, lab_over, addr_rtx, r;
1894 /* Only SVR4 needs something special. */
1895 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1896 return std_expand_builtin_va_arg (valist, type);
1898 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
1899 f_fpr = TREE_CHAIN (f_gpr);
1900 f_ovf = TREE_CHAIN (f_fpr);
1901 f_sav = TREE_CHAIN (f_ovf);
1903 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
1904 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
1905 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
1906 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
1907 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
1909 size = int_size_in_bytes (type);
1910 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1912 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
1914 /* Aggregates and long doubles are passed by reference. */
1915 indirect_p = 1;
1916 reg = gpr;
1917 n_reg = 1;
1918 sav_ofs = 0;
1919 sav_scale = 4;
1920 size = rsize = UNITS_PER_WORD;
1922 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
1924 /* FP args go in FP registers, if present. */
1925 indirect_p = 0;
1926 reg = fpr;
1927 n_reg = 1;
1928 sav_ofs = 8*4;
1929 sav_scale = 8;
1931 else
1933 /* Otherwise into GP registers. */
1934 indirect_p = 0;
1935 reg = gpr;
1936 n_reg = rsize;
1937 sav_ofs = 0;
1938 sav_scale = 4;
1942 * Pull the value out of the saved registers ...
1945 lab_false = gen_label_rtx ();
1946 lab_over = gen_label_rtx ();
1947 addr_rtx = gen_reg_rtx (Pmode);
1949 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
1950 GEN_INT (8 - n_reg + 1),
1951 GE, const1_rtx, QImode, 1, 1, lab_false);
1953 /* Long long is aligned in the registers. */
1954 if (n_reg > 1)
1956 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
1957 build_int_2 (n_reg - 1, 0));
1958 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
1959 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
1960 TREE_SIDE_EFFECTS (u) = 1;
1961 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
1964 if (sav_ofs)
1965 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
1966 else
1967 t = sav;
1969 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
1970 TREE_SIDE_EFFECTS (u) = 1;
1972 u = build1 (CONVERT_EXPR, integer_type_node, u);
1973 TREE_SIDE_EFFECTS (u) = 1;
1975 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
1976 TREE_SIDE_EFFECTS (u) = 1;
1978 t = build (PLUS_EXPR, ptr_type_node, t, u);
1979 TREE_SIDE_EFFECTS (t) = 1;
1981 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
1982 if (r != addr_rtx)
1983 emit_move_insn (addr_rtx, r);
1985 emit_jump_insn (gen_jump (lab_over));
1986 emit_barrier ();
1987 emit_label (lab_false);
1990 * ... otherwise out of the overflow area.
1993 /* Make sure we don't find reg 7 for the next int arg. */
1994 if (n_reg > 1)
1996 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
1997 TREE_SIDE_EFFECTS (t) = 1;
1998 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2001 /* Care for on-stack alignment if needed. */
2002 if (rsize <= 1)
2003 t = ovf;
2004 else
2006 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
2007 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
2009 t = save_expr (t);
2011 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2012 if (r != addr_rtx)
2013 emit_move_insn (addr_rtx, r);
2015 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
2016 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2017 TREE_SIDE_EFFECTS (t) = 1;
2018 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2020 emit_label (lab_over);
2022 if (indirect_p)
2024 r = gen_rtx_MEM (Pmode, addr_rtx);
2025 MEM_ALIAS_SET (r) = get_varargs_alias_set ();
2026 emit_move_insn (addr_rtx, r);
2029 return addr_rtx;
2032 /* Generate a memory reference for expand_block_move, copying volatile,
2033 and other bits from an original memory reference. */
2035 static rtx
2036 expand_block_move_mem (mode, addr, orig_mem)
2037 enum machine_mode mode;
2038 rtx addr;
2039 rtx orig_mem;
2041 rtx mem = gen_rtx_MEM (mode, addr);
2043 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem);
2044 MEM_COPY_ATTRIBUTES (mem, orig_mem);
2045 #ifdef MEM_UNALIGNED_P
2046 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
2047 #endif
2048 return mem;
2051 /* Expand a block move operation, and return 1 if successful. Return 0
2052 if we should let the compiler generate normal code.
2054 operands[0] is the destination
2055 operands[1] is the source
2056 operands[2] is the length
2057 operands[3] is the alignment */
2059 #define MAX_MOVE_REG 4
2062 expand_block_move (operands)
2063 rtx operands[];
2065 rtx orig_dest = operands[0];
2066 rtx orig_src = operands[1];
2067 rtx bytes_rtx = operands[2];
2068 rtx align_rtx = operands[3];
2069 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2070 int align;
2071 int bytes;
2072 int offset;
2073 int num_reg;
2074 int i;
2075 rtx src_reg;
2076 rtx dest_reg;
2077 rtx src_addr;
2078 rtx dest_addr;
2079 rtx tmp_reg;
2080 rtx stores[MAX_MOVE_REG];
2081 int move_bytes;
2083 /* If this is not a fixed size move, just call memcpy */
2084 if (! constp)
2085 return 0;
2087 /* If this is not a fixed size alignment, abort */
2088 if (GET_CODE (align_rtx) != CONST_INT)
2089 abort ();
2090 align = INTVAL (align_rtx);
2092 /* Anything to move? */
2093 bytes = INTVAL (bytes_rtx);
2094 if (bytes <= 0)
2095 return 1;
2097 /* Don't support real large moves. If string instructions are not used,
2098 then don't generate more than 8 loads. */
2099 if (TARGET_STRING)
2101 if (bytes > 8*4)
2102 return 0;
2104 else if (! STRICT_ALIGNMENT)
2106 if (TARGET_POWERPC64 && align >= 4)
2108 if (bytes > 8*8)
2109 return 0;
2111 else
2112 if (bytes > 8*4)
2113 return 0;
2115 else if (bytes > 8*align)
2116 return 0;
2118 /* Move the address into scratch registers. */
2119 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2120 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2122 if (TARGET_STRING) /* string instructions are available */
2124 for ( ; bytes > 0; bytes -= move_bytes)
2126 if (bytes > 24 /* move up to 32 bytes at a time */
2127 && ! fixed_regs[5]
2128 && ! fixed_regs[6]
2129 && ! fixed_regs[7]
2130 && ! fixed_regs[8]
2131 && ! fixed_regs[9]
2132 && ! fixed_regs[10]
2133 && ! fixed_regs[11]
2134 && ! fixed_regs[12])
2136 move_bytes = (bytes > 32) ? 32 : bytes;
2137 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
2138 dest_reg,
2139 orig_dest),
2140 expand_block_move_mem (BLKmode,
2141 src_reg,
2142 orig_src),
2143 GEN_INT ((move_bytes == 32)
2144 ? 0 : move_bytes),
2145 align_rtx));
2147 else if (bytes > 16 /* move up to 24 bytes at a time */
2148 && ! fixed_regs[5]
2149 && ! fixed_regs[6]
2150 && ! fixed_regs[7]
2151 && ! fixed_regs[8]
2152 && ! fixed_regs[9]
2153 && ! fixed_regs[10])
2155 move_bytes = (bytes > 24) ? 24 : bytes;
2156 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
2157 dest_reg,
2158 orig_dest),
2159 expand_block_move_mem (BLKmode,
2160 src_reg,
2161 orig_src),
2162 GEN_INT (move_bytes),
2163 align_rtx));
2165 else if (bytes > 8 /* move up to 16 bytes at a time */
2166 && ! fixed_regs[5]
2167 && ! fixed_regs[6]
2168 && ! fixed_regs[7]
2169 && ! fixed_regs[8])
2171 move_bytes = (bytes > 16) ? 16 : bytes;
2172 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
2173 dest_reg,
2174 orig_dest),
2175 expand_block_move_mem (BLKmode,
2176 src_reg,
2177 orig_src),
2178 GEN_INT (move_bytes),
2179 align_rtx));
2181 else if (bytes > 4 && ! TARGET_POWERPC64)
2182 { /* move up to 8 bytes at a time */
2183 move_bytes = (bytes > 8) ? 8 : bytes;
2184 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
2185 dest_reg,
2186 orig_dest),
2187 expand_block_move_mem (BLKmode,
2188 src_reg,
2189 orig_src),
2190 GEN_INT (move_bytes),
2191 align_rtx));
2193 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2194 { /* move 4 bytes */
2195 move_bytes = 4;
2196 tmp_reg = gen_reg_rtx (SImode);
2197 emit_move_insn (tmp_reg,
2198 expand_block_move_mem (SImode,
2199 src_reg, orig_src));
2200 emit_move_insn (expand_block_move_mem (SImode,
2201 dest_reg, orig_dest),
2202 tmp_reg);
2204 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2205 { /* move 2 bytes */
2206 move_bytes = 2;
2207 tmp_reg = gen_reg_rtx (HImode);
2208 emit_move_insn (tmp_reg,
2209 expand_block_move_mem (HImode,
2210 src_reg, orig_src));
2211 emit_move_insn (expand_block_move_mem (HImode,
2212 dest_reg, orig_dest),
2213 tmp_reg);
2215 else if (bytes == 1) /* move 1 byte */
2217 move_bytes = 1;
2218 tmp_reg = gen_reg_rtx (QImode);
2219 emit_move_insn (tmp_reg,
2220 expand_block_move_mem (QImode,
2221 src_reg, orig_src));
2222 emit_move_insn (expand_block_move_mem (QImode,
2223 dest_reg, orig_dest),
2224 tmp_reg);
2226 else
2227 { /* move up to 4 bytes at a time */
2228 move_bytes = (bytes > 4) ? 4 : bytes;
2229 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
2230 dest_reg,
2231 orig_dest),
2232 expand_block_move_mem (BLKmode,
2233 src_reg,
2234 orig_src),
2235 GEN_INT (move_bytes),
2236 align_rtx));
2239 if (bytes > move_bytes)
2241 if (! TARGET_POWERPC64)
2243 emit_insn (gen_addsi3 (src_reg, src_reg,
2244 GEN_INT (move_bytes)));
2245 emit_insn (gen_addsi3 (dest_reg, dest_reg,
2246 GEN_INT (move_bytes)));
2248 else
2250 emit_insn (gen_adddi3 (src_reg, src_reg,
2251 GEN_INT (move_bytes)));
2252 emit_insn (gen_adddi3 (dest_reg, dest_reg,
2253 GEN_INT (move_bytes)));
2259 else /* string instructions not available */
2261 num_reg = offset = 0;
2262 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2264 /* Calculate the correct offset for src/dest */
2265 if (offset == 0)
2267 src_addr = src_reg;
2268 dest_addr = dest_reg;
2270 else
2272 src_addr = plus_constant (src_reg, offset);
2273 dest_addr = plus_constant (dest_reg, offset);
2276 /* Generate the appropriate load and store, saving the stores
2277 for later. */
2278 if (bytes >= 8 && TARGET_POWERPC64
2279 /* 64-bit loads and stores require word-aligned displacements. */
2280 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2282 move_bytes = 8;
2283 tmp_reg = gen_reg_rtx (DImode);
2284 emit_insn (gen_movdi (tmp_reg,
2285 expand_block_move_mem (DImode,
2286 src_addr,
2287 orig_src)));
2288 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
2289 dest_addr,
2290 orig_dest),
2291 tmp_reg);
2293 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2295 move_bytes = 4;
2296 tmp_reg = gen_reg_rtx (SImode);
2297 emit_insn (gen_movsi (tmp_reg,
2298 expand_block_move_mem (SImode,
2299 src_addr,
2300 orig_src)));
2301 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
2302 dest_addr,
2303 orig_dest),
2304 tmp_reg);
2306 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2308 move_bytes = 2;
2309 tmp_reg = gen_reg_rtx (HImode);
2310 emit_insn (gen_movhi (tmp_reg,
2311 expand_block_move_mem (HImode,
2312 src_addr,
2313 orig_src)));
2314 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
2315 dest_addr,
2316 orig_dest),
2317 tmp_reg);
2319 else
2321 move_bytes = 1;
2322 tmp_reg = gen_reg_rtx (QImode);
2323 emit_insn (gen_movqi (tmp_reg,
2324 expand_block_move_mem (QImode,
2325 src_addr,
2326 orig_src)));
2327 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
2328 dest_addr,
2329 orig_dest),
2330 tmp_reg);
2333 if (num_reg >= MAX_MOVE_REG)
2335 for (i = 0; i < num_reg; i++)
2336 emit_insn (stores[i]);
2337 num_reg = 0;
2341 for (i = 0; i < num_reg; i++)
2342 emit_insn (stores[i]);
2345 return 1;
2349 /* Return 1 if OP is a load multiple operation. It is known to be a
2350 PARALLEL and the first section will be tested. */
2353 load_multiple_operation (op, mode)
2354 rtx op;
2355 enum machine_mode mode ATTRIBUTE_UNUSED;
2357 int count = XVECLEN (op, 0);
2358 int dest_regno;
2359 rtx src_addr;
2360 int i;
2362 /* Perform a quick check so we don't blow up below. */
2363 if (count <= 1
2364 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2365 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
2366 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
2367 return 0;
2369 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
2370 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
2372 for (i = 1; i < count; i++)
2374 rtx elt = XVECEXP (op, 0, i);
2376 if (GET_CODE (elt) != SET
2377 || GET_CODE (SET_DEST (elt)) != REG
2378 || GET_MODE (SET_DEST (elt)) != SImode
2379 || REGNO (SET_DEST (elt)) != dest_regno + i
2380 || GET_CODE (SET_SRC (elt)) != MEM
2381 || GET_MODE (SET_SRC (elt)) != SImode
2382 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2383 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2384 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2385 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
2386 return 0;
2389 return 1;
2392 /* Similar, but tests for store multiple. Here, the second vector element
2393 is a CLOBBER. It will be tested later. */
2396 store_multiple_operation (op, mode)
2397 rtx op;
2398 enum machine_mode mode ATTRIBUTE_UNUSED;
2400 int count = XVECLEN (op, 0) - 1;
2401 int src_regno;
2402 rtx dest_addr;
2403 int i;
2405 /* Perform a quick check so we don't blow up below. */
2406 if (count <= 1
2407 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2408 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
2409 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
2410 return 0;
2412 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
2413 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
2415 for (i = 1; i < count; i++)
2417 rtx elt = XVECEXP (op, 0, i + 1);
2419 if (GET_CODE (elt) != SET
2420 || GET_CODE (SET_SRC (elt)) != REG
2421 || GET_MODE (SET_SRC (elt)) != SImode
2422 || REGNO (SET_SRC (elt)) != src_regno + i
2423 || GET_CODE (SET_DEST (elt)) != MEM
2424 || GET_MODE (SET_DEST (elt)) != SImode
2425 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2426 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2427 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2428 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
2429 return 0;
2432 return 1;
2435 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
2436 We only check the opcode against the mode of the CC value here. */
2439 branch_comparison_operator (op, mode)
2440 register rtx op;
2441 enum machine_mode mode ATTRIBUTE_UNUSED;
2443 enum rtx_code code = GET_CODE (op);
2444 enum machine_mode cc_mode;
2446 if (GET_RTX_CLASS (code) != '<')
2447 return 0;
2449 cc_mode = GET_MODE (XEXP (op, 0));
2450 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
2451 return 0;
2453 if ((code == GT || code == LT || code == GE || code == LE)
2454 && cc_mode == CCUNSmode)
2455 return 0;
2457 if ((code == GTU || code == LTU || code == GEU || code == LEU)
2458 && (cc_mode != CCUNSmode))
2459 return 0;
2461 return 1;
2464 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
2465 We check the opcode against the mode of the CC value and disallow EQ or
2466 NE comparisons for integers. */
2469 scc_comparison_operator (op, mode)
2470 register rtx op;
2471 enum machine_mode mode;
2473 enum rtx_code code = GET_CODE (op);
2474 enum machine_mode cc_mode;
2476 if (GET_MODE (op) != mode && mode != VOIDmode)
2477 return 0;
2479 if (GET_RTX_CLASS (code) != '<')
2480 return 0;
2482 cc_mode = GET_MODE (XEXP (op, 0));
2483 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
2484 return 0;
2486 if (code == NE && cc_mode != CCFPmode)
2487 return 0;
2489 if ((code == GT || code == LT || code == GE || code == LE)
2490 && cc_mode == CCUNSmode)
2491 return 0;
2493 if ((code == GTU || code == LTU || code == GEU || code == LEU)
2494 && (cc_mode != CCUNSmode))
2495 return 0;
2497 if (cc_mode == CCEQmode && code != EQ && code != NE)
2498 return 0;
2500 return 1;
2504 trap_comparison_operator (op, mode)
2505 rtx op;
2506 enum machine_mode mode;
2508 if (mode != VOIDmode && mode != GET_MODE (op))
2509 return 0;
2510 return (GET_RTX_CLASS (GET_CODE (op)) == '<'
2511 || GET_CODE (op) == EQ || GET_CODE (op) == NE);
2514 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
2515 mask required to convert the result of a rotate insn into a shift
2516 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
2519 includes_lshift_p (shiftop, andop)
2520 register rtx shiftop;
2521 register rtx andop;
2523 int shift_mask = (~0 << INTVAL (shiftop));
2525 return (INTVAL (andop) & ~shift_mask) == 0;
2528 /* Similar, but for right shift. */
2531 includes_rshift_p (shiftop, andop)
2532 register rtx shiftop;
2533 register rtx andop;
2535 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
2537 shift_mask >>= INTVAL (shiftop);
2539 return (INTVAL (andop) & ~ shift_mask) == 0;
2542 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
2543 for lfq and stfq insns.
2545 Note reg1 and reg2 *must* be hard registers. To be sure we will
2546 abort if we are passed pseudo registers. */
2549 registers_ok_for_quad_peep (reg1, reg2)
2550 rtx reg1, reg2;
2552 /* We might have been passed a SUBREG. */
2553 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
2554 return 0;
2556 return (REGNO (reg1) == REGNO (reg2) - 1);
2559 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
2560 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
2563 addrs_ok_for_quad_peep (addr1, addr2)
2564 register rtx addr1;
2565 register rtx addr2;
2567 int reg1;
2568 int offset1;
2570 /* Extract an offset (if used) from the first addr. */
2571 if (GET_CODE (addr1) == PLUS)
2573 /* If not a REG, return zero. */
2574 if (GET_CODE (XEXP (addr1, 0)) != REG)
2575 return 0;
2576 else
2578 reg1 = REGNO (XEXP (addr1, 0));
2579 /* The offset must be constant! */
2580 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
2581 return 0;
2582 offset1 = INTVAL (XEXP (addr1, 1));
2585 else if (GET_CODE (addr1) != REG)
2586 return 0;
2587 else
2589 reg1 = REGNO (addr1);
2590 /* This was a simple (mem (reg)) expression. Offset is 0. */
2591 offset1 = 0;
2594 /* Make sure the second address is a (mem (plus (reg) (const_int). */
2595 if (GET_CODE (addr2) != PLUS)
2596 return 0;
2598 if (GET_CODE (XEXP (addr2, 0)) != REG
2599 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
2600 return 0;
2602 if (reg1 != REGNO (XEXP (addr2, 0)))
2603 return 0;
2605 /* The offset for the second addr must be 8 more than the first addr. */
2606 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
2607 return 0;
2609 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
2610 instructions. */
2611 return 1;
2614 /* Return the register class of a scratch register needed to copy IN into
2615 or out of a register in CLASS in MODE. If it can be done directly,
2616 NO_REGS is returned. */
2618 enum reg_class
2619 secondary_reload_class (class, mode, in)
2620 enum reg_class class;
2621 enum machine_mode mode ATTRIBUTE_UNUSED;
2622 rtx in;
2624 int regno;
2626 #if TARGET_ELF
2627 /* We can not copy a symbolic operand directly into anything other than
2628 BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS
2629 is needed as an intermediate register. */
2630 if (class != BASE_REGS
2631 && (GET_CODE (in) == SYMBOL_REF
2632 || GET_CODE (in) == HIGH
2633 || GET_CODE (in) == LABEL_REF
2634 || GET_CODE (in) == CONST))
2635 return BASE_REGS;
2636 #endif
2638 if (GET_CODE (in) == REG)
2640 regno = REGNO (in);
2641 if (regno >= FIRST_PSEUDO_REGISTER)
2643 regno = true_regnum (in);
2644 if (regno >= FIRST_PSEUDO_REGISTER)
2645 regno = -1;
2648 else if (GET_CODE (in) == SUBREG)
2650 regno = true_regnum (in);
2651 if (regno >= FIRST_PSEUDO_REGISTER)
2652 regno = -1;
2654 else
2655 regno = -1;
2657 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
2658 into anything. */
2659 if (class == GENERAL_REGS || class == BASE_REGS
2660 || (regno >= 0 && INT_REGNO_P (regno)))
2661 return NO_REGS;
2663 /* Constants, memory, and FP registers can go into FP registers. */
2664 if ((regno == -1 || FP_REGNO_P (regno))
2665 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
2666 return NO_REGS;
2668 /* We can copy among the CR registers. */
2669 if ((class == CR_REGS || class == CR0_REGS)
2670 && regno >= 0 && CR_REGNO_P (regno))
2671 return NO_REGS;
2673 /* Otherwise, we need GENERAL_REGS. */
2674 return GENERAL_REGS;
2677 /* Given a comparison operation, return the bit number in CCR to test. We
2678 know this is a valid comparison.
2680 SCC_P is 1 if this is for an scc. That means that %D will have been
2681 used instead of %C, so the bits will be in different places.
2683 Return -1 if OP isn't a valid comparison for some reason. */
2686 ccr_bit (op, scc_p)
2687 register rtx op;
2688 int scc_p;
2690 enum rtx_code code = GET_CODE (op);
2691 enum machine_mode cc_mode;
2692 int cc_regnum;
2693 int base_bit;
2695 if (GET_RTX_CLASS (code) != '<')
2696 return -1;
2698 cc_mode = GET_MODE (XEXP (op, 0));
2699 cc_regnum = REGNO (XEXP (op, 0));
2700 base_bit = 4 * (cc_regnum - 68);
2702 /* In CCEQmode cases we have made sure that the result is always in the
2703 third bit of the CR field. */
2705 if (cc_mode == CCEQmode)
2706 return base_bit + 3;
2708 switch (code)
2710 case NE:
2711 return scc_p ? base_bit + 3 : base_bit + 2;
2712 case EQ:
2713 return base_bit + 2;
2714 case GT: case GTU:
2715 return base_bit + 1;
2716 case LT: case LTU:
2717 return base_bit;
2719 case GE: case GEU:
2720 /* If floating-point, we will have done a cror to put the bit in the
2721 unordered position. So test that bit. For integer, this is ! LT
2722 unless this is an scc insn. */
2723 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
2725 case LE: case LEU:
2726 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
2728 default:
2729 abort ();
2733 /* Return the GOT register. */
2735 struct rtx_def *
2736 rs6000_got_register (value)
2737 rtx value ATTRIBUTE_UNUSED;
2739 /* The second flow pass currently (June 1999) can't update regs_ever_live
2740 without disturbing other parts of the compiler, so update it here to
2741 make the prolog/epilogue code happy. */
2742 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
2743 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
2745 current_function_uses_pic_offset_table = 1;
2747 return pic_offset_table_rtx;
2750 /* Search for any occurrence of the GOT_TOC register marker that should
2751 have been eliminated, but may have crept back in.
2753 This function could completely go away now (June 1999), but we leave it
2754 in for a while until all the possible issues with the new -fpic handling
2755 are resolved. */
2757 void
2758 rs6000_reorg (insn)
2759 rtx insn;
2761 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
2763 rtx got_reg = gen_rtx_REG (Pmode, 2);
2764 for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
2765 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2766 && reg_mentioned_p (got_reg, PATTERN (insn)))
2767 fatal_insn ("GOT/TOC register marker not removed:", PATTERN (insn));
2772 /* Define the structure for the machine field in struct function. */
2773 struct machine_function
2775 int sysv_varargs_p;
2776 int save_toc_p;
2777 int fpmem_size;
2778 int fpmem_offset;
2781 /* Functions to save and restore rs6000_fpmem_size.
2782 These will be called, via pointer variables,
2783 from push_function_context and pop_function_context. */
2785 void
2786 rs6000_save_machine_status (p)
2787 struct function *p;
2789 struct machine_function *machine =
2790 (struct machine_function *) xmalloc (sizeof (struct machine_function));
2792 p->machine = machine;
2793 machine->sysv_varargs_p = rs6000_sysv_varargs_p;
2794 machine->fpmem_size = rs6000_fpmem_size;
2795 machine->fpmem_offset = rs6000_fpmem_offset;
2798 void
2799 rs6000_restore_machine_status (p)
2800 struct function *p;
2802 struct machine_function *machine = p->machine;
2804 rs6000_sysv_varargs_p = machine->sysv_varargs_p;
2805 rs6000_fpmem_size = machine->fpmem_size;
2806 rs6000_fpmem_offset = machine->fpmem_offset;
2808 free (machine);
2809 p->machine = (struct machine_function *)0;
2812 /* Do anything needed before RTL is emitted for each function. */
2814 void
2815 rs6000_init_expanders ()
2817 /* Reset varargs and save TOC indicator */
2818 rs6000_sysv_varargs_p = 0;
2819 rs6000_fpmem_size = 0;
2820 rs6000_fpmem_offset = 0;
2822 /* Arrange to save and restore machine status around nested functions. */
2823 save_machine_status = rs6000_save_machine_status;
2824 restore_machine_status = rs6000_restore_machine_status;
2828 /* Print an operand. Recognize special options, documented below. */
2830 #if TARGET_ELF
2831 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
2832 #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
2833 #else
2834 #define SMALL_DATA_RELOC "sda21"
2835 #define SMALL_DATA_REG 0
2836 #endif
2838 void
2839 print_operand (file, x, code)
2840 FILE *file;
2841 rtx x;
2842 char code;
2844 int i;
2845 HOST_WIDE_INT val;
2847 /* These macros test for integers and extract the low-order bits. */
2848 #define INT_P(X) \
2849 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
2850 && GET_MODE (X) == VOIDmode)
2852 #define INT_LOWPART(X) \
2853 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
2855 switch (code)
2857 case '.':
2858 /* Write out an instruction after the call which may be replaced
2859 with glue code by the loader. This depends on the AIX version. */
2860 asm_fprintf (file, RS6000_CALL_GLUE);
2861 return;
2863 case '*':
2864 /* Write the register number of the TOC register. */
2865 fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2 /* PIC_OFFSET_TABLE_REGNUM? */ ], file);
2866 return;
2868 case '$':
2869 /* Write out either a '.' or '$' for the current location, depending
2870 on whether this is Solaris or not. */
2871 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
2872 return;
2874 case 'A':
2875 /* If X is a constant integer whose low-order 5 bits are zero,
2876 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
2877 in the AIX assembler where "sri" with a zero shift count
2878 write a trash instruction. */
2879 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
2880 putc ('l', file);
2881 else
2882 putc ('r', file);
2883 return;
2885 case 'b':
2886 /* Low-order 16 bits of constant, unsigned. */
2887 if (! INT_P (x))
2888 output_operand_lossage ("invalid %%b value");
2890 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
2891 return;
2893 case 'B':
2894 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
2895 for 64-bit mask direction. */
2896 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
2897 return;
2899 case 'C':
2900 /* This is an optional cror needed for LE or GE floating-point
2901 comparisons. Otherwise write nothing. */
2902 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
2903 && GET_MODE (XEXP (x, 0)) == CCFPmode)
2905 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2907 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2908 base_bit + 2, base_bit + (GET_CODE (x) == GE));
2910 return;
2912 case 'D':
2913 /* Similar, except that this is for an scc, so we must be able to
2914 encode the test in a single bit that is one. We do the above
2915 for any LE, GE, GEU, or LEU and invert the bit for NE. */
2916 if (GET_CODE (x) == LE || GET_CODE (x) == GE
2917 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
2919 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2921 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2922 base_bit + 2,
2923 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
2926 else if (GET_CODE (x) == NE)
2928 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2930 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
2931 base_bit + 2, base_bit + 2);
2933 return;
2935 case 'E':
2936 /* X is a CR register. Print the number of the third bit of the CR */
2937 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2938 output_operand_lossage ("invalid %%E value");
2940 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
2941 return;
2943 case 'f':
2944 /* X is a CR register. Print the shift count needed to move it
2945 to the high-order four bits. */
2946 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2947 output_operand_lossage ("invalid %%f value");
2948 else
2949 fprintf (file, "%d", 4 * (REGNO (x) - 68));
2950 return;
2952 case 'F':
2953 /* Similar, but print the count for the rotate in the opposite
2954 direction. */
2955 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2956 output_operand_lossage ("invalid %%F value");
2957 else
2958 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
2959 return;
2961 case 'G':
2962 /* X is a constant integer. If it is negative, print "m",
2963 otherwise print "z". This is to make a aze or ame insn. */
2964 if (GET_CODE (x) != CONST_INT)
2965 output_operand_lossage ("invalid %%G value");
2966 else if (INTVAL (x) >= 0)
2967 putc ('z', file);
2968 else
2969 putc ('m', file);
2970 return;
2972 case 'h':
2973 /* If constant, output low-order five bits. Otherwise,
2974 write normally. */
2975 if (INT_P (x))
2976 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
2977 else
2978 print_operand (file, x, 0);
2979 return;
2981 case 'H':
2982 /* If constant, output low-order six bits. Otherwise,
2983 write normally. */
2984 if (INT_P (x))
2985 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
2986 else
2987 print_operand (file, x, 0);
2988 return;
2990 case 'I':
2991 /* Print `i' if this is a constant, else nothing. */
2992 if (INT_P (x))
2993 putc ('i', file);
2994 return;
2996 case 'j':
2997 /* Write the bit number in CCR for jump. */
2998 i = ccr_bit (x, 0);
2999 if (i == -1)
3000 output_operand_lossage ("invalid %%j code");
3001 else
3002 fprintf (file, "%d", i);
3003 return;
3005 case 'J':
3006 /* Similar, but add one for shift count in rlinm for scc and pass
3007 scc flag to `ccr_bit'. */
3008 i = ccr_bit (x, 1);
3009 if (i == -1)
3010 output_operand_lossage ("invalid %%J code");
3011 else
3012 /* If we want bit 31, write a shift count of zero, not 32. */
3013 fprintf (file, "%d", i == 31 ? 0 : i + 1);
3014 return;
3016 case 'k':
3017 /* X must be a constant. Write the 1's complement of the
3018 constant. */
3019 if (! INT_P (x))
3020 output_operand_lossage ("invalid %%k value");
3022 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
3023 return;
3025 case 'L':
3026 /* Write second word of DImode or DFmode reference. Works on register
3027 or non-indexed memory only. */
3028 if (GET_CODE (x) == REG)
3029 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
3030 else if (GET_CODE (x) == MEM)
3032 /* Handle possible auto-increment. Since it is pre-increment and
3033 we have already done it, we can just use an offset of word. */
3034 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3035 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3036 output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0),
3037 UNITS_PER_WORD));
3038 else
3039 output_address (plus_constant_for_output (XEXP (x, 0),
3040 UNITS_PER_WORD));
3041 if (small_data_operand (x, GET_MODE (x)))
3042 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3043 reg_names[SMALL_DATA_REG]);
3045 return;
3047 case 'm':
3048 /* MB value for a mask operand. */
3049 if (! mask_operand (x, VOIDmode))
3050 output_operand_lossage ("invalid %%m value");
3052 val = INT_LOWPART (x);
3054 /* If the high bit is set and the low bit is not, the value is zero.
3055 If the high bit is zero, the value is the first 1 bit we find from
3056 the left. */
3057 if ((val & 0x80000000) && ((val & 1) == 0))
3059 putc ('0', file);
3060 return;
3062 else if ((val & 0x80000000) == 0)
3064 for (i = 1; i < 32; i++)
3065 if ((val <<= 1) & 0x80000000)
3066 break;
3067 fprintf (file, "%d", i);
3068 return;
3071 /* Otherwise, look for the first 0 bit from the right. The result is its
3072 number plus 1. We know the low-order bit is one. */
3073 for (i = 0; i < 32; i++)
3074 if (((val >>= 1) & 1) == 0)
3075 break;
3077 /* If we ended in ...01, i would be 0. The correct value is 31, so
3078 we want 31 - i. */
3079 fprintf (file, "%d", 31 - i);
3080 return;
3082 case 'M':
3083 /* ME value for a mask operand. */
3084 if (! mask_operand (x, VOIDmode))
3085 output_operand_lossage ("invalid %%M value");
3087 val = INT_LOWPART (x);
3089 /* If the low bit is set and the high bit is not, the value is 31.
3090 If the low bit is zero, the value is the first 1 bit we find from
3091 the right. */
3092 if ((val & 1) && ((val & 0x80000000) == 0))
3094 fputs ("31", file);
3095 return;
3097 else if ((val & 1) == 0)
3099 for (i = 0; i < 32; i++)
3100 if ((val >>= 1) & 1)
3101 break;
3103 /* If we had ....10, i would be 0. The result should be
3104 30, so we need 30 - i. */
3105 fprintf (file, "%d", 30 - i);
3106 return;
3109 /* Otherwise, look for the first 0 bit from the left. The result is its
3110 number minus 1. We know the high-order bit is one. */
3111 for (i = 0; i < 32; i++)
3112 if (((val <<= 1) & 0x80000000) == 0)
3113 break;
3115 fprintf (file, "%d", i);
3116 return;
3118 case 'N':
3119 /* Write the number of elements in the vector times 4. */
3120 if (GET_CODE (x) != PARALLEL)
3121 output_operand_lossage ("invalid %%N value");
3123 fprintf (file, "%d", XVECLEN (x, 0) * 4);
3124 return;
3126 case 'O':
3127 /* Similar, but subtract 1 first. */
3128 if (GET_CODE (x) != PARALLEL)
3129 output_operand_lossage ("invalid %%O value");
3131 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
3132 return;
3134 case 'p':
3135 /* X is a CONST_INT that is a power of two. Output the logarithm. */
3136 if (! INT_P (x)
3137 || (i = exact_log2 (INT_LOWPART (x))) < 0)
3138 output_operand_lossage ("invalid %%p value");
3140 fprintf (file, "%d", i);
3141 return;
3143 case 'P':
3144 /* The operand must be an indirect memory reference. The result
3145 is the register number. */
3146 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
3147 || REGNO (XEXP (x, 0)) >= 32)
3148 output_operand_lossage ("invalid %%P value");
3150 fprintf (file, "%d", REGNO (XEXP (x, 0)));
3151 return;
3153 case 'R':
3154 /* X is a CR register. Print the mask for `mtcrf'. */
3155 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3156 output_operand_lossage ("invalid %%R value");
3157 else
3158 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
3159 return;
3161 case 's':
3162 /* Low 5 bits of 32 - value */
3163 if (! INT_P (x))
3164 output_operand_lossage ("invalid %%s value");
3166 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
3167 return;
3169 case 'S':
3170 /* PowerPC64 mask position. All 0's and all 1's are excluded.
3171 CONST_INT 32-bit mask is considered sign-extended so any
3172 transition must occur within the CONST_INT, not on the boundary. */
3173 if (! mask64_operand (x, VOIDmode))
3174 output_operand_lossage ("invalid %%S value");
3176 val = INT_LOWPART (x);
3178 if (val & 1) /* Clear Left */
3180 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
3181 if (!((val >>= 1) & 1))
3182 break;
3184 #if HOST_BITS_PER_WIDE_INT == 32
3185 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
3187 val = CONST_DOUBLE_HIGH (x);
3189 if (val == 0)
3190 --i;
3191 else
3192 for (i = 32; i < 64; i++)
3193 if (!((val >>= 1) & 1))
3194 break;
3196 #endif
3197 /* i = index of last set bit from right
3198 mask begins at 63 - i from left */
3199 if (i > 63)
3200 output_operand_lossage ("%%S computed all 1's mask");
3201 fprintf (file, "%d", 63 - i);
3202 return;
3204 else /* Clear Right */
3206 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
3207 if ((val >>= 1) & 1)
3208 break;
3210 #if HOST_BITS_PER_WIDE_INT == 32
3211 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
3213 val = CONST_DOUBLE_HIGH (x);
3215 if (val == (HOST_WIDE_INT) -1)
3216 --i;
3217 else
3218 for (i = 32; i < 64; i++)
3219 if ((val >>= 1) & 1)
3220 break;
3222 #endif
3223 /* i = index of last clear bit from right
3224 mask ends at 62 - i from left */
3225 if (i > 62)
3226 output_operand_lossage ("%%S computed all 0's mask");
3227 fprintf (file, "%d", 62 - i);
3228 return;
3231 case 't':
3232 /* Write 12 if this jump operation will branch if true, 4 otherwise.
3233 All floating-point operations except NE branch true and integer
3234 EQ, LT, GT, LTU and GTU also branch true. */
3235 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
3236 output_operand_lossage ("invalid %%t value");
3238 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
3239 && GET_CODE (x) != NE)
3240 || GET_CODE (x) == EQ
3241 || GET_CODE (x) == LT || GET_CODE (x) == GT
3242 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
3243 fputs ("12", file);
3244 else
3245 putc ('4', file);
3246 return;
3248 case 'T':
3249 /* Opposite of 't': write 4 if this jump operation will branch if true,
3250 12 otherwise. */
3251 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
3252 output_operand_lossage ("invalid %%T value");
3254 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
3255 && GET_CODE (x) != NE)
3256 || GET_CODE (x) == EQ
3257 || GET_CODE (x) == LT || GET_CODE (x) == GT
3258 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
3259 putc ('4', file);
3260 else
3261 fputs ("12", file);
3262 return;
3264 case 'u':
3265 /* High-order 16 bits of constant for use in unsigned operand. */
3266 if (! INT_P (x))
3267 output_operand_lossage ("invalid %%u value");
3269 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
3270 (INT_LOWPART (x) >> 16) & 0xffff);
3271 return;
3273 case 'v':
3274 /* High-order 16 bits of constant for use in signed operand. */
3275 if (! INT_P (x))
3276 output_operand_lossage ("invalid %%v value");
3279 int value = (INT_LOWPART (x) >> 16) & 0xffff;
3281 /* Solaris assembler doesn't like lis 0,0x8000 */
3282 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
3283 fprintf (file, "%d", value | (~0 << 16));
3284 else
3285 fprintf (file, "0x%x", value);
3286 return;
3289 case 'U':
3290 /* Print `u' if this has an auto-increment or auto-decrement. */
3291 if (GET_CODE (x) == MEM
3292 && (GET_CODE (XEXP (x, 0)) == PRE_INC
3293 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
3294 putc ('u', file);
3295 return;
3297 case 'V':
3298 /* Print the trap code for this operand. */
3299 switch (GET_CODE (x))
3301 case EQ:
3302 fputs ("eq", file); /* 4 */
3303 break;
3304 case NE:
3305 fputs ("ne", file); /* 24 */
3306 break;
3307 case LT:
3308 fputs ("lt", file); /* 16 */
3309 break;
3310 case LE:
3311 fputs ("le", file); /* 20 */
3312 break;
3313 case GT:
3314 fputs ("gt", file); /* 8 */
3315 break;
3316 case GE:
3317 fputs ("ge", file); /* 12 */
3318 break;
3319 case LTU:
3320 fputs ("llt", file); /* 2 */
3321 break;
3322 case LEU:
3323 fputs ("lle", file); /* 6 */
3324 break;
3325 case GTU:
3326 fputs ("lgt", file); /* 1 */
3327 break;
3328 case GEU:
3329 fputs ("lge", file); /* 5 */
3330 break;
3331 default:
3332 abort ();
3334 break;
3336 case 'w':
3337 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
3338 normally. */
3339 if (INT_P (x))
3340 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
3341 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
3342 else
3343 print_operand (file, x, 0);
3344 return;
3346 case 'W':
3347 /* If constant, low-order 16 bits of constant, unsigned.
3348 Otherwise, write normally. */
3349 if (INT_P (x))
3350 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
3351 else
3352 print_operand (file, x, 0);
3353 return;
3355 case 'X':
3356 if (GET_CODE (x) == MEM
3357 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
3358 putc ('x', file);
3359 return;
3361 case 'Y':
3362 /* Like 'L', for third word of TImode */
3363 if (GET_CODE (x) == REG)
3364 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
3365 else if (GET_CODE (x) == MEM)
3367 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3368 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3369 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
3370 else
3371 output_address (plus_constant (XEXP (x, 0), 8));
3372 if (small_data_operand (x, GET_MODE (x)))
3373 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3374 reg_names[SMALL_DATA_REG]);
3376 return;
3378 case 'z':
3379 /* X is a SYMBOL_REF. Write out the name preceded by a
3380 period and without any trailing data in brackets. Used for function
3381 names. If we are configured for System V (or the embedded ABI) on
3382 the PowerPC, do not emit the period, since those systems do not use
3383 TOCs and the like. */
3384 if (GET_CODE (x) != SYMBOL_REF)
3385 abort ();
3387 if (XSTR (x, 0)[0] != '.')
3389 switch (DEFAULT_ABI)
3391 default:
3392 abort ();
3394 case ABI_AIX:
3395 putc ('.', file);
3396 break;
3398 case ABI_V4:
3399 case ABI_AIX_NODESC:
3400 case ABI_SOLARIS:
3401 break;
3403 case ABI_NT:
3404 fputs ("..", file);
3405 break;
3408 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
3409 return;
3411 case 'Z':
3412 /* Like 'L', for last word of TImode. */
3413 if (GET_CODE (x) == REG)
3414 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
3415 else if (GET_CODE (x) == MEM)
3417 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3418 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3419 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
3420 else
3421 output_address (plus_constant (XEXP (x, 0), 12));
3422 if (small_data_operand (x, GET_MODE (x)))
3423 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3424 reg_names[SMALL_DATA_REG]);
3426 return;
3428 case 0:
3429 if (GET_CODE (x) == REG)
3430 fprintf (file, "%s", reg_names[REGNO (x)]);
3431 else if (GET_CODE (x) == MEM)
3433 /* We need to handle PRE_INC and PRE_DEC here, since we need to
3434 know the width from the mode. */
3435 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
3436 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
3437 REGNO (XEXP (XEXP (x, 0), 0)));
3438 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
3439 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
3440 REGNO (XEXP (XEXP (x, 0), 0)));
3441 else
3442 output_address (XEXP (x, 0));
3444 else
3445 output_addr_const (file, x);
3446 return;
3448 default:
3449 output_operand_lossage ("invalid %%xn code");
3453 /* Print the address of an operand. */
3455 void
3456 print_operand_address (file, x)
3457 FILE *file;
3458 register rtx x;
3460 if (GET_CODE (x) == REG)
3461 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
3462 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST || GET_CODE (x) == LABEL_REF)
3464 output_addr_const (file, x);
3465 if (small_data_operand (x, GET_MODE (x)))
3466 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3467 reg_names[SMALL_DATA_REG]);
3469 #ifdef TARGET_NO_TOC
3470 else if (TARGET_NO_TOC)
3472 #endif
3473 else
3474 fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 /* PIC_OFFSET_TABLE_REGNUM? */ ]);
3476 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
3478 if (REGNO (XEXP (x, 0)) == 0)
3479 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
3480 reg_names[ REGNO (XEXP (x, 0)) ]);
3481 else
3482 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
3483 reg_names[ REGNO (XEXP (x, 1)) ]);
3485 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3487 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
3488 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
3490 #if TARGET_ELF
3491 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
3492 && CONSTANT_P (XEXP (x, 1)))
3494 output_addr_const (file, XEXP (x, 1));
3495 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
3497 #endif
3498 else
3499 abort ();
3502 /* This page contains routines that are used to determine what the function
3503 prologue and epilogue code will do and write them out. */
3505 /* Return the first fixed-point register that is required to be saved. 32 if
3506 none. */
3509 first_reg_to_save ()
3511 int first_reg;
3513 /* Find lowest numbered live register. */
3514 for (first_reg = 13; first_reg <= 31; first_reg++)
3515 if (regs_ever_live[first_reg]
3516 && (! call_used_regs[first_reg]
3517 || (first_reg == PIC_OFFSET_TABLE_REGNUM
3518 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
3519 && flag_pic == 1)))
3520 break;
3522 if (profile_flag)
3524 /* AIX must save/restore every register that contains a parameter
3525 before/after the .__mcount call plus an additional register
3526 for the static chain, if needed; use registers from 30 down to 22
3527 to do this. */
3528 if (DEFAULT_ABI == ABI_AIX)
3530 int last_parm_reg, profile_first_reg;
3532 /* Figure out last used parameter register. The proper thing
3533 to do is to walk incoming args of the function. A function
3534 might have live parameter registers even if it has no
3535 incoming args. */
3536 for (last_parm_reg = 10;
3537 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
3538 last_parm_reg--)
3541 /* Calculate first reg for saving parameter registers
3542 and static chain.
3543 Skip reg 31 which may contain the frame pointer. */
3544 profile_first_reg = (33 - last_parm_reg
3545 - (current_function_needs_context ? 1 : 0));
3546 /* Do not save frame pointer if no parameters needs to be saved. */
3547 if (profile_first_reg == 31)
3548 profile_first_reg = 32;
3550 if (first_reg > profile_first_reg)
3551 first_reg = profile_first_reg;
3554 /* SVR4 may need one register to preserve the static chain. */
3555 else if (current_function_needs_context)
3557 /* Skip reg 31 which may contain the frame pointer. */
3558 if (first_reg > 30)
3559 first_reg = 30;
3563 return first_reg;
3566 /* Similar, for FP regs. */
3569 first_fp_reg_to_save ()
3571 int first_reg;
3573 /* Find lowest numbered live register. */
3574 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
3575 if (regs_ever_live[first_reg])
3576 break;
3578 return first_reg;
3581 /* Return non-zero if this function makes calls. */
3584 rs6000_makes_calls ()
3586 rtx insn;
3588 /* If we are profiling, we will be making a call to __mcount.
3589 Under the System V ABI's, we store the LR directly, so
3590 we don't need to do it here. */
3591 if (DEFAULT_ABI == ABI_AIX && profile_flag)
3592 return 1;
3594 for (insn = get_insns (); insn; insn = next_insn (insn))
3595 if (GET_CODE (insn) == CALL_INSN)
3596 return 1;
3598 return 0;
3602 /* Calculate the stack information for the current function. This is
3603 complicated by having two separate calling sequences, the AIX calling
3604 sequence and the V.4 calling sequence.
3606 AIX stack frames look like:
3607 32-bit 64-bit
3608 SP----> +---------------------------------------+
3609 | back chain to caller | 0 0
3610 +---------------------------------------+
3611 | saved CR | 4 8 (8-11)
3612 +---------------------------------------+
3613 | saved LR | 8 16
3614 +---------------------------------------+
3615 | reserved for compilers | 12 24
3616 +---------------------------------------+
3617 | reserved for binders | 16 32
3618 +---------------------------------------+
3619 | saved TOC pointer | 20 40
3620 +---------------------------------------+
3621 | Parameter save area (P) | 24 48
3622 +---------------------------------------+
3623 | Alloca space (A) | 24+P etc.
3624 +---------------------------------------+
3625 | Local variable space (L) | 24+P+A
3626 +---------------------------------------+
3627 | Float/int conversion temporary (X) | 24+P+A+L
3628 +---------------------------------------+
3629 | Save area for GP registers (G) | 24+P+A+X+L
3630 +---------------------------------------+
3631 | Save area for FP registers (F) | 24+P+A+X+L+G
3632 +---------------------------------------+
3633 old SP->| back chain to caller's caller |
3634 +---------------------------------------+
3636 The required alignment for AIX configurations is two words (i.e., 8
3637 or 16 bytes).
3640 V.4 stack frames look like:
3642 SP----> +---------------------------------------+
3643 | back chain to caller | 0
3644 +---------------------------------------+
3645 | caller's saved LR | 4
3646 +---------------------------------------+
3647 | Parameter save area (P) | 8
3648 +---------------------------------------+
3649 | Alloca space (A) | 8+P
3650 +---------------------------------------+
3651 | Varargs save area (V) | 8+P+A
3652 +---------------------------------------+
3653 | Local variable space (L) | 8+P+A+V
3654 +---------------------------------------+
3655 | Float/int conversion temporary (X) | 8+P+A+V+L
3656 +---------------------------------------+
3657 | saved CR (C) | 8+P+A+V+L+X
3658 +---------------------------------------+
3659 | Save area for GP registers (G) | 8+P+A+V+L+X+C
3660 +---------------------------------------+
3661 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
3662 +---------------------------------------+
3663 old SP->| back chain to caller's caller |
3664 +---------------------------------------+
3666 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
3667 given. (But note below and in sysv4.h that we require only 8 and
3668 may round up the size of our stack frame anyways. The historical
3669 reason is early versions of powerpc-linux which didn't properly
3670 align the stack at program startup. A happy side-effect is that
3671 -mno-eabi libraries can be used with -meabi programs.)
3674 A PowerPC Windows/NT frame looks like:
3676 SP----> +---------------------------------------+
3677 | back chain to caller | 0
3678 +---------------------------------------+
3679 | reserved | 4
3680 +---------------------------------------+
3681 | reserved | 8
3682 +---------------------------------------+
3683 | reserved | 12
3684 +---------------------------------------+
3685 | reserved | 16
3686 +---------------------------------------+
3687 | reserved | 20
3688 +---------------------------------------+
3689 | Parameter save area (P) | 24
3690 +---------------------------------------+
3691 | Alloca space (A) | 24+P
3692 +---------------------------------------+
3693 | Local variable space (L) | 24+P+A
3694 +---------------------------------------+
3695 | Float/int conversion temporary (X) | 24+P+A+L
3696 +---------------------------------------+
3697 | Save area for FP registers (F) | 24+P+A+L+X
3698 +---------------------------------------+
3699 | Possible alignment area (Y) | 24+P+A+L+X+F
3700 +---------------------------------------+
3701 | Save area for GP registers (G) | 24+P+A+L+X+F+Y
3702 +---------------------------------------+
3703 | Save area for CR (C) | 24+P+A+L+X+F+Y+G
3704 +---------------------------------------+
3705 | Save area for TOC (T) | 24+P+A+L+X+F+Y+G+C
3706 +---------------------------------------+
3707 | Save area for LR (R) | 24+P+A+L+X+F+Y+G+C+T
3708 +---------------------------------------+
3709 old SP->| back chain to caller's caller |
3710 +---------------------------------------+
3712 For NT, there is no specific order to save the registers, but in
3713 order to support __builtin_return_address, the save area for the
3714 link register needs to be in a known place, so we use -4 off of the
3715 old SP. To support calls through pointers, we also allocate a
3716 fixed slot to store the TOC, -8 off the old SP.
3718 The required alignment for NT is 16 bytes.
3721 The EABI configuration defaults to the V.4 layout, unless
3722 -mcall-aix is used, in which case the AIX layout is used. However,
3723 the stack alignment requirements may differ. If -mno-eabi is not
3724 given, the required stack alignment is 8 bytes; if -mno-eabi is
3725 given, the required alignment is 16 bytes. (But see V.4 comment
3726 above.) */
3728 #ifndef ABI_STACK_BOUNDARY
3729 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
3730 #endif
3732 rs6000_stack_t *
3733 rs6000_stack_info ()
3735 static rs6000_stack_t info, zero_info;
3736 rs6000_stack_t *info_ptr = &info;
3737 int reg_size = TARGET_32BIT ? 4 : 8;
3738 enum rs6000_abi abi;
3739 int total_raw_size;
3741 /* Zero all fields portably */
3742 info = zero_info;
3744 /* Select which calling sequence */
3745 info_ptr->abi = abi = DEFAULT_ABI;
3747 /* Calculate which registers need to be saved & save area size */
3748 info_ptr->first_gp_reg_save = first_reg_to_save ();
3749 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
3750 even if it currently looks like we won't. */
3751 if (flag_pic == 1
3752 && (abi == ABI_V4 || abi == ABI_SOLARIS)
3753 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
3754 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
3755 else
3756 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
3758 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
3759 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
3761 /* Does this function call anything? */
3762 info_ptr->calls_p = rs6000_makes_calls ();
3764 /* Allocate space to save the toc. */
3765 if (abi == ABI_NT && info_ptr->calls_p)
3767 info_ptr->toc_save_p = 1;
3768 info_ptr->toc_size = reg_size;
3771 /* Does this machine need the float/int conversion area? */
3772 info_ptr->fpmem_p = regs_ever_live[FPMEM_REGNUM];
3774 /* If this is main and we need to call a function to set things up,
3775 save main's arguments around the call. */
3776 #ifdef TARGET_EABI
3777 if (TARGET_EABI)
3778 #endif
3780 if (0 == strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
3781 "main")
3782 && DECL_CONTEXT (current_function_decl) == NULL_TREE)
3784 info_ptr->main_p = 1;
3786 #ifdef NAME__MAIN
3787 info_ptr->calls_p = 1;
3789 if (DECL_ARGUMENTS (current_function_decl))
3791 int i;
3792 tree arg;
3794 info_ptr->main_save_p = 1;
3795 info_ptr->main_size = 0;
3797 for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl));
3798 arg != NULL_TREE && i < 8;
3799 (arg = TREE_CHAIN (arg)), i++)
3801 info_ptr->main_size += reg_size;
3804 #endif
3808 /* Determine if we need to save the link register */
3809 if (regs_ever_live[65]
3810 || (DEFAULT_ABI == ABI_AIX && profile_flag)
3811 #ifdef TARGET_RELOCATABLE
3812 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
3813 #endif
3814 || (info_ptr->first_fp_reg_save != 64
3815 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
3816 || (abi == ABI_V4 && current_function_calls_alloca)
3817 || (abi == ABI_SOLARIS && current_function_calls_alloca)
3818 || info_ptr->calls_p)
3820 info_ptr->lr_save_p = 1;
3821 regs_ever_live[65] = 1;
3822 if (abi == ABI_NT)
3823 info_ptr->lr_size = reg_size;
3826 /* Determine if we need to save the condition code registers */
3827 if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
3829 info_ptr->cr_save_p = 1;
3830 if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
3831 info_ptr->cr_size = reg_size;
3834 /* Determine various sizes */
3835 info_ptr->reg_size = reg_size;
3836 info_ptr->fixed_size = RS6000_SAVE_AREA;
3837 info_ptr->varargs_size = RS6000_VARARGS_AREA;
3838 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
3839 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
3840 info_ptr->fpmem_size = (info_ptr->fpmem_p) ? 8 : 0;
3841 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
3842 + info_ptr->gp_size
3843 + info_ptr->cr_size
3844 + info_ptr->lr_size
3845 + info_ptr->toc_size
3846 + info_ptr->main_size, 8);
3848 /* Calculate the offsets */
3849 switch (abi)
3851 case ABI_NONE:
3852 default:
3853 abort ();
3855 case ABI_AIX:
3856 case ABI_AIX_NODESC:
3857 info_ptr->fp_save_offset = - info_ptr->fp_size;
3858 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
3859 info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size;
3860 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
3861 info_ptr->lr_save_offset = 2*reg_size;
3862 break;
3864 case ABI_V4:
3865 case ABI_SOLARIS:
3866 info_ptr->fp_save_offset = - info_ptr->fp_size;
3867 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
3868 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
3869 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
3870 info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->main_size;
3871 info_ptr->lr_save_offset = reg_size;
3872 break;
3874 case ABI_NT:
3875 info_ptr->lr_save_offset = -reg_size;
3876 info_ptr->toc_save_offset = info_ptr->lr_save_offset - info_ptr->lr_size;
3877 info_ptr->cr_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
3878 info_ptr->gp_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size;
3879 info_ptr->fp_save_offset = info_ptr->gp_save_offset - info_ptr->fp_size;
3880 if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0)
3881 info_ptr->fp_save_offset -= reg_size;
3883 info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size;
3884 break;
3887 /* Ensure that fpmem_offset will be aligned to an 8-byte boundary. */
3888 if (info_ptr->fpmem_p
3889 && (info_ptr->main_save_offset - info_ptr->fpmem_size) % 8)
3890 info_ptr->fpmem_size += reg_size;
3892 total_raw_size = (info_ptr->vars_size
3893 + info_ptr->parm_size
3894 + info_ptr->fpmem_size
3895 + info_ptr->save_size
3896 + info_ptr->varargs_size
3897 + info_ptr->fixed_size);
3899 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
3901 /* Determine if we need to allocate any stack frame:
3903 For AIX we need to push the stack if a frame pointer is needed (because
3904 the stack might be dynamically adjusted), if we are debugging, if we
3905 make calls, or if the sum of fp_save, gp_save, fpmem, and local variables
3906 are more than the space needed to save all non-volatile registers:
3907 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved).
3909 For V.4 we don't have the stack cushion that AIX uses, but assume that
3910 the debugger can handle stackless frames. */
3912 if (info_ptr->calls_p)
3913 info_ptr->push_p = 1;
3915 else if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
3916 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
3917 || (abi == ABI_NT ? info_ptr->lr_save_p
3918 : info_ptr->calls_p));
3920 else
3921 info_ptr->push_p = (frame_pointer_needed
3922 || write_symbols != NO_DEBUG
3923 || ((total_raw_size - info_ptr->fixed_size)
3924 > (TARGET_32BIT ? 220 : 288)));
3926 if (info_ptr->fpmem_p)
3928 info_ptr->fpmem_offset = info_ptr->main_save_offset - info_ptr->fpmem_size;
3929 rs6000_fpmem_size = info_ptr->fpmem_size;
3930 rs6000_fpmem_offset = (info_ptr->push_p
3931 ? info_ptr->total_size + info_ptr->fpmem_offset
3932 : info_ptr->fpmem_offset);
3934 else
3935 info_ptr->fpmem_offset = 0;
3937 /* Zero offsets if we're not saving those registers */
3938 if (info_ptr->fp_size == 0)
3939 info_ptr->fp_save_offset = 0;
3941 if (info_ptr->gp_size == 0)
3942 info_ptr->gp_save_offset = 0;
3944 if (! info_ptr->lr_save_p)
3945 info_ptr->lr_save_offset = 0;
3947 if (! info_ptr->cr_save_p)
3948 info_ptr->cr_save_offset = 0;
3950 if (! info_ptr->toc_save_p)
3951 info_ptr->toc_save_offset = 0;
3953 if (! info_ptr->main_save_p)
3954 info_ptr->main_save_offset = 0;
3956 return info_ptr;
3959 void
3960 debug_stack_info (info)
3961 rs6000_stack_t *info;
3963 const char *abi_string;
3965 if (! info)
3966 info = rs6000_stack_info ();
3968 fprintf (stderr, "\nStack information for function %s:\n",
3969 ((current_function_decl && DECL_NAME (current_function_decl))
3970 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
3971 : "<unknown>"));
3973 switch (info->abi)
3975 default: abi_string = "Unknown"; break;
3976 case ABI_NONE: abi_string = "NONE"; break;
3977 case ABI_AIX: abi_string = "AIX"; break;
3978 case ABI_AIX_NODESC: abi_string = "AIX"; break;
3979 case ABI_V4: abi_string = "V.4"; break;
3980 case ABI_SOLARIS: abi_string = "Solaris"; break;
3981 case ABI_NT: abi_string = "NT"; break;
3984 fprintf (stderr, "\tABI = %5s\n", abi_string);
3986 if (info->first_gp_reg_save != 32)
3987 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
3989 if (info->first_fp_reg_save != 64)
3990 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
3992 if (info->lr_save_p)
3993 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
3995 if (info->cr_save_p)
3996 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
3998 if (info->toc_save_p)
3999 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
4001 if (info->push_p)
4002 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
4004 if (info->calls_p)
4005 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
4007 if (info->main_p)
4008 fprintf (stderr, "\tmain_p = %5d\n", info->main_p);
4010 if (info->main_save_p)
4011 fprintf (stderr, "\tmain_save_p = %5d\n", info->main_save_p);
4013 if (info->fpmem_p)
4014 fprintf (stderr, "\tfpmem_p = %5d\n", info->fpmem_p);
4016 if (info->gp_save_offset)
4017 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
4019 if (info->fp_save_offset)
4020 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
4022 if (info->lr_save_offset)
4023 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
4025 if (info->cr_save_offset)
4026 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
4028 if (info->toc_save_offset)
4029 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
4031 if (info->varargs_save_offset)
4032 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
4034 if (info->main_save_offset)
4035 fprintf (stderr, "\tmain_save_offset = %5d\n", info->main_save_offset);
4037 if (info->fpmem_offset)
4038 fprintf (stderr, "\tfpmem_offset = %5d\n", info->fpmem_offset);
4040 if (info->total_size)
4041 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
4043 if (info->varargs_size)
4044 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
4046 if (info->vars_size)
4047 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
4049 if (info->parm_size)
4050 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
4052 if (info->fpmem_size)
4053 fprintf (stderr, "\tfpmem_size = %5d\n", info->fpmem_size);
4055 if (info->fixed_size)
4056 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
4058 if (info->gp_size)
4059 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
4061 if (info->fp_size)
4062 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
4064 if (info->lr_size)
4065 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
4067 if (info->cr_size)
4068 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
4070 if (info->toc_size)
4071 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
4073 if (info->main_size)
4074 fprintf (stderr, "\tmain_size = %5d\n", info->main_size);
4076 if (info->save_size)
4077 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
4079 if (info->reg_size != 4)
4080 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
4082 fprintf (stderr, "\n");
4085 /* Write out an instruction to load the TOC_TABLE address into register 30.
4086 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
4087 a constant pool. */
4089 void
4090 rs6000_output_load_toc_table (file, reg)
4091 FILE *file;
4092 int reg;
4094 char buf[256];
4096 #ifdef USING_SVR4_H
4097 if (TARGET_RELOCATABLE)
4099 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
4100 fprintf (file, "\tbl ");
4101 assemble_name (file, buf);
4102 fprintf (file, "\n");
4104 /* possibly create the toc section */
4105 if (! toc_initialized)
4107 toc_section ();
4108 function_section (current_function_decl);
4111 /* If not first call in this function, we need to put the
4112 different between .LCTOC1 and the address we get to right
4113 after the bl. It will mess up disassembling the instructions
4114 but that can't be helped. We will later need to bias the
4115 address before loading. */
4116 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
4118 const char *init_ptr = TARGET_32BIT ? ".long" : ".quad";
4119 const char *buf_ptr;
4121 ASM_OUTPUT_INTERNAL_LABEL (file, "LCL", rs6000_pic_labelno);
4123 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
4124 STRIP_NAME_ENCODING (buf_ptr, buf);
4125 fprintf (file, "\t%s %s-", init_ptr, buf_ptr);
4127 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
4128 fprintf (file, "%s\n", buf_ptr);
4131 ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
4132 fprintf (file, "\tmflr %s\n", reg_names[reg]);
4134 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
4135 asm_fprintf(file, "\t{cal|la} %s,%d(%s)\n", reg_names[reg],
4136 (TARGET_32BIT ? 4 : 8), reg_names[reg]);
4138 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s,(" : "\tld %s,(",
4139 reg_names[0]);
4140 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
4141 assemble_name (file, buf);
4142 putc ('-', file);
4143 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
4144 assemble_name (file, buf);
4145 fprintf (file, ")(%s)\n", reg_names[reg]);
4146 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
4147 reg_names[reg], reg_names[0], reg_names[reg]);
4148 rs6000_pic_labelno++;
4150 else if (! TARGET_64BIT)
4152 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
4153 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[reg]);
4154 assemble_name (file, buf);
4155 fputs ("@ha\n", file);
4156 asm_fprintf (file, "\t{cal|la} %s,", reg_names[reg]);
4157 assemble_name (file, buf);
4158 asm_fprintf (file, "@l(%s)\n", reg_names[reg]);
4160 else
4161 abort ();
4163 #else /* !USING_SVR4_H */
4164 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
4165 asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,",
4166 reg_names[reg]);
4167 assemble_name (file, buf);
4168 asm_fprintf (file, "(%s)\n", reg_names[2]);
4169 #endif /* USING_SVR4_H */
4173 /* Emit the correct code for allocating stack space. If COPY_R12, make sure a copy
4174 of the old frame is left in r12. */
4176 void
4177 rs6000_allocate_stack_space (file, size, copy_r12)
4178 FILE *file;
4179 int size;
4180 int copy_r12;
4182 int neg_size = -size;
4184 if (current_function_limit_stack)
4186 if (REG_P (stack_limit_rtx)
4187 && REGNO (stack_limit_rtx) > 1
4188 && REGNO (stack_limit_rtx) <= 31)
4190 if (size <= 32767)
4191 asm_fprintf (file, "\t{cal %s,%d(%s)|addi %s,%s,%d}\n",
4192 reg_names[0], reg_names[REGNO (stack_limit_rtx)],
4193 size);
4194 else
4196 asm_fprintf (file, "\t{cau|addis} %s,%s,0x%x\n",
4197 reg_names[0], reg_names[REGNO (stack_limit_rtx)],
4198 ((size + 0x8000) >> 16) & 0xffff);
4199 asm_fprintf (file, "\t{ai|addic} %s,%s,%d\n",
4200 reg_names[0], reg_names[0],
4201 (size & 0x7fff) | -(size & 0x8000));
4203 if (TARGET_32BIT)
4204 asm_fprintf (file, "\t{t|tw}llt %s,%s\n",
4205 reg_names[1], reg_names[0]);
4206 else
4207 asm_fprintf (file, "\ttdllt %s,%s\n", reg_names[1], reg_names[0]);
4209 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
4210 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
4212 const char * l_name = XSTR (stack_limit_rtx, 0);
4213 const char * stripped_name;
4215 STRIP_NAME_ENCODING (stripped_name, l_name);
4216 asm_fprintf (file, "\t{liu|lis} %s,%s@ha+%d\n",
4217 reg_names[0], stripped_name, size);
4218 asm_fprintf (file, "\t{ai|addic} %s,%s,%s@l+%d\n",
4219 reg_names[0], reg_names[0], stripped_name, size);
4220 if (TARGET_32BIT)
4221 asm_fprintf (file, "\t{t|tw}llt %s,%s\n",
4222 reg_names[1], reg_names[0]);
4223 else
4224 asm_fprintf (file, "\ttdllt %s,%s\n", reg_names[1], reg_names[0]);
4226 else
4227 warning ("stack limit expression is not supported");
4230 if (TARGET_UPDATE)
4232 if (size < 32767)
4233 asm_fprintf (file,
4234 (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n",
4235 reg_names[1], neg_size, reg_names[1]);
4236 else
4238 if (copy_r12)
4239 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
4241 asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n",
4242 reg_names[0], (neg_size >> 16) & 0xffff,
4243 reg_names[0], reg_names[0], neg_size & 0xffff);
4244 asm_fprintf (file,
4245 (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n",
4246 reg_names[1], reg_names[1], reg_names[0]);
4249 else
4251 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
4252 if (size < 32767)
4253 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
4254 reg_names[1], neg_size, reg_names[1]);
4255 else
4257 asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n",
4258 reg_names[0], (neg_size >> 16) & 0xffff,
4259 reg_names[0], reg_names[0], neg_size & 0xffff);
4260 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", reg_names[1],
4261 reg_names[0], reg_names[1]);
4264 asm_fprintf (file,
4265 (TARGET_32BIT) ? "\t{st|stw} %s,0(%s)\n" : "\tstd %s,0(%s)\n",
4266 reg_names[12], reg_names[1]);
4271 /* Write function prologue. */
4272 void
4273 output_prolog (file, size)
4274 FILE *file;
4275 int size ATTRIBUTE_UNUSED;
4277 rs6000_stack_t *info = rs6000_stack_info ();
4278 int reg_size = info->reg_size;
4279 const char *store_reg;
4280 const char *load_reg;
4281 int sp_reg = 1;
4282 int sp_offset = 0;
4284 if (TARGET_32BIT)
4286 store_reg = "\t{st|stw} %s,%d(%s)\n";
4287 load_reg = "\t{l|lwz} %s,%d(%s)\n";
4289 else
4291 store_reg = "\tstd %s,%d(%s)\n";
4292 load_reg = "\tlld %s,%d(%s)\n";
4295 if (TARGET_DEBUG_STACK)
4296 debug_stack_info (info);
4298 /* Write .extern for any function we will call to save and restore fp
4299 values. */
4300 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4301 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4302 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
4303 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
4305 /* Write .extern for truncation routines, if needed. */
4306 if (rs6000_trunc_used && ! trunc_defined)
4308 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
4309 RS6000_ITRUNC, RS6000_UITRUNC);
4310 trunc_defined = 1;
4313 /* Write .extern for AIX common mode routines, if needed. */
4314 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
4316 fputs ("\t.extern __mulh\n", file);
4317 fputs ("\t.extern __mull\n", file);
4318 fputs ("\t.extern __divss\n", file);
4319 fputs ("\t.extern __divus\n", file);
4320 fputs ("\t.extern __quoss\n", file);
4321 fputs ("\t.extern __quous\n", file);
4322 common_mode_defined = 1;
4325 /* For V.4, update stack before we do any saving and set back pointer. */
4326 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
4328 if (info->total_size < 32767)
4329 sp_offset = info->total_size;
4330 else
4331 sp_reg = 12;
4332 rs6000_allocate_stack_space (file, info->total_size, sp_reg == 12);
4335 /* If we use the link register, get it into r0. */
4336 if (info->lr_save_p)
4337 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
4339 /* If we need to save CR, put it into r12. */
4340 if (info->cr_save_p && sp_reg != 12)
4341 asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
4343 /* Do any required saving of fpr's. If only one or two to save, do it
4344 ourself. Otherwise, call function. Note that since they are statically
4345 linked, we do not need a nop following them. */
4346 if (FP_SAVE_INLINE (info->first_fp_reg_save))
4348 int regno = info->first_fp_reg_save;
4349 int loc = info->fp_save_offset + sp_offset;
4351 for ( ; regno < 64; regno++, loc += 8)
4352 asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
4354 else if (info->first_fp_reg_save != 64)
4355 asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX,
4356 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
4358 /* Now save gpr's. */
4359 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
4361 int regno = info->first_gp_reg_save;
4362 int loc = info->gp_save_offset + sp_offset;
4364 for ( ; regno < 32; regno++, loc += reg_size)
4365 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
4368 else if (info->first_gp_reg_save != 32)
4369 asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n",
4370 reg_names[info->first_gp_reg_save],
4371 info->gp_save_offset + sp_offset,
4372 reg_names[sp_reg]);
4374 /* Save main's arguments if we need to call a function */
4375 #ifdef NAME__MAIN
4376 if (info->main_save_p)
4378 int regno;
4379 int loc = info->main_save_offset + sp_offset;
4380 int size = info->main_size;
4382 for (regno = 3; size > 0; regno++, loc += reg_size, size -= reg_size)
4383 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
4385 #endif
4387 /* Save lr if we used it. */
4388 if (info->lr_save_p)
4389 asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset + sp_offset,
4390 reg_names[sp_reg]);
4392 /* Save CR if we use any that must be preserved. */
4393 if (info->cr_save_p)
4395 if (sp_reg == 12) /* If r12 is used to hold the original sp, copy cr now */
4397 asm_fprintf (file, "\tmfcr %s\n", reg_names[0]);
4398 asm_fprintf (file, store_reg, reg_names[0],
4399 info->cr_save_offset + sp_offset,
4400 reg_names[sp_reg]);
4402 else
4403 asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset + sp_offset,
4404 reg_names[sp_reg]);
4407 /* If we need PIC_OFFSET_TABLE_REGNUM, initialize it now */
4408 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4409 && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
4411 if (! info->lr_save_p)
4412 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
4414 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
4415 asm_fprintf (file, "\tmflr %s\n", reg_names[PIC_OFFSET_TABLE_REGNUM]);
4417 if (! info->lr_save_p)
4418 asm_fprintf (file, "\tmtlr %s\n", reg_names[0]);
4421 /* NT needs us to probe the stack frame every 4k pages for large frames, so
4422 do it here. */
4423 if (DEFAULT_ABI == ABI_NT && info->total_size > 4096)
4425 if (info->total_size < 32768)
4427 int probe_offset = 4096;
4428 while (probe_offset < info->total_size)
4430 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", reg_names[0], -probe_offset, reg_names[1]);
4431 probe_offset += 4096;
4434 else
4436 int probe_iterations = info->total_size / 4096;
4437 static int probe_labelno = 0;
4438 char buf[256];
4440 if (probe_iterations < 32768)
4441 asm_fprintf (file, "\tli %s,%d\n", reg_names[12], probe_iterations);
4442 else
4444 asm_fprintf (file, "\tlis %s,%d\n", reg_names[12], probe_iterations >> 16);
4445 if (probe_iterations & 0xffff)
4446 asm_fprintf (file, "\tori %s,%s,%d\n", reg_names[12], reg_names[12],
4447 probe_iterations & 0xffff);
4449 asm_fprintf (file, "\tmtctr %s\n", reg_names[12]);
4450 asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
4451 ASM_OUTPUT_INTERNAL_LABEL (file, "LCprobe", probe_labelno);
4452 asm_fprintf (file, "\t{lu|lwzu} %s,-4096(%s)\n", reg_names[0], reg_names[12]);
4453 ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno++);
4454 fputs ("\tbdnz ", file);
4455 assemble_name (file, buf);
4456 putc ('\n', file);
4460 /* Update stack and set back pointer unless this is V.4, which was done previously */
4461 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
4462 rs6000_allocate_stack_space (file, info->total_size, FALSE);
4464 /* Set frame pointer, if needed. */
4465 if (frame_pointer_needed)
4466 asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]);
4468 #ifdef NAME__MAIN
4469 /* If we need to call a function to set things up for main, do so now
4470 before dealing with the TOC. */
4471 if (info->main_p)
4473 const char *prefix = "";
4475 switch (DEFAULT_ABI)
4477 case ABI_AIX: prefix = "."; break;
4478 case ABI_NT: prefix = ".."; break;
4481 fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN);
4482 #ifdef RS6000_CALL_GLUE2
4483 fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN);
4484 #else
4485 #ifdef RS6000_CALL_GLUE
4486 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
4488 putc('\t', file);
4489 asm_fprintf (file, RS6000_CALL_GLUE);
4490 putc('\n', file);
4492 #endif
4493 #endif
4495 if (info->main_save_p)
4497 int regno;
4498 int loc;
4499 int size = info->main_size;
4501 if (info->total_size < 32767)
4503 loc = info->total_size + info->main_save_offset;
4504 for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size)
4505 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
4507 else
4509 int neg_size = info->main_save_offset - info->total_size;
4510 loc = 0;
4511 asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n",
4512 reg_names[0], (neg_size >> 16) & 0xffff,
4513 reg_names[0], reg_names[0], neg_size & 0xffff);
4515 asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0],
4516 reg_names[1]);
4518 for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size)
4519 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]);
4523 #endif
4526 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
4527 TOC_TABLE address into register 30. */
4528 if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
4530 #ifdef USING_SVR4_H
4531 if (! profile_flag)
4532 rs6000_pic_func_labelno = rs6000_pic_labelno;
4533 #endif
4534 rs6000_output_load_toc_table (file, 30);
4537 if (DEFAULT_ABI == ABI_NT)
4539 assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4540 fputs (".b:\n", file);
4544 /* Write function epilogue. */
4546 void
4547 output_epilog (file, size)
4548 FILE *file;
4549 int size ATTRIBUTE_UNUSED;
4551 rs6000_stack_t *info = rs6000_stack_info ();
4552 const char *load_reg = (TARGET_32BIT) ? "\t{l|lwz} %s,%d(%s)\n" : "\tld %s,%d(%s)\n";
4553 rtx insn = get_last_insn ();
4554 int sp_reg = 1;
4555 int sp_offset = 0;
4557 /* If the last insn was a BARRIER, we don't have to write anything except
4558 the trace table. */
4559 if (GET_CODE (insn) == NOTE)
4560 insn = prev_nonnote_insn (insn);
4561 if (insn == 0 || GET_CODE (insn) != BARRIER)
4563 /* If we have a frame pointer, a call to alloca, or a large stack
4564 frame, restore the old stack pointer using the backchain. Otherwise,
4565 we know what size to update it with. */
4566 if (frame_pointer_needed || current_function_calls_alloca
4567 || info->total_size > 32767)
4569 /* Under V.4, don't reset the stack pointer until after we're done
4570 loading the saved registers. */
4571 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4572 sp_reg = 11;
4574 asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]);
4576 else if (info->push_p)
4578 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4579 sp_offset = info->total_size;
4580 else
4581 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
4582 reg_names[1], info->total_size, reg_names[1]);
4585 /* Get the old lr if we saved it. */
4586 if (info->lr_save_p)
4587 asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset + sp_offset, reg_names[sp_reg]);
4589 /* Get the old cr if we saved it. */
4590 if (info->cr_save_p)
4591 asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset + sp_offset, reg_names[sp_reg]);
4593 /* Set LR here to try to overlap restores below. */
4594 if (info->lr_save_p)
4595 asm_fprintf (file, "\tmtlr %s\n", reg_names[0]);
4597 /* Restore gpr's. */
4598 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
4600 int regno = info->first_gp_reg_save;
4601 int loc = info->gp_save_offset + sp_offset;
4602 int reg_size = (TARGET_32BIT) ? 4 : 8;
4604 for ( ; regno < 32; regno++, loc += reg_size)
4605 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[sp_reg]);
4608 else if (info->first_gp_reg_save != 32)
4609 asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n",
4610 reg_names[info->first_gp_reg_save],
4611 info->gp_save_offset + sp_offset,
4612 reg_names[sp_reg]);
4614 /* Restore fpr's if we can do it without calling a function. */
4615 if (FP_SAVE_INLINE (info->first_fp_reg_save))
4617 int regno = info->first_fp_reg_save;
4618 int loc = info->fp_save_offset + sp_offset;
4620 for ( ; regno < 64; regno++, loc += 8)
4621 asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
4624 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
4625 that were used. */
4626 if (info->cr_save_p)
4627 asm_fprintf (file, "\tmtcrf %d,%s\n",
4628 (regs_ever_live[70] != 0) * 0x20
4629 + (regs_ever_live[71] != 0) * 0x10
4630 + (regs_ever_live[72] != 0) * 0x8, reg_names[12]);
4632 /* If this is V.4, unwind the stack pointer after all of the loads
4633 have been done */
4634 if (sp_offset != 0)
4635 asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n",
4636 reg_names[1], sp_offset, reg_names[1]);
4637 else if (sp_reg != 1)
4638 asm_fprintf (file, "\tmr %s,%s\n", reg_names[1], reg_names[sp_reg]);
4640 /* If we have to restore more than two FP registers, branch to the
4641 restore function. It will return to our caller. */
4642 if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4643 asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX,
4644 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
4645 else
4646 asm_fprintf (file, "\t{br|blr}\n");
4649 /* Output a traceback table here. See /usr/include/sys/debug.h for info
4650 on its format.
4652 We don't output a traceback table if -finhibit-size-directive was
4653 used. The documentation for -finhibit-size-directive reads
4654 ``don't output a @code{.size} assembler directive, or anything
4655 else that would cause trouble if the function is split in the
4656 middle, and the two halves are placed at locations far apart in
4657 memory.'' The traceback table has this property, since it
4658 includes the offset from the start of the function to the
4659 traceback table itself.
4661 System V.4 Powerpc's (and the embedded ABI derived from it) use a
4662 different traceback table. */
4663 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
4665 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
4666 int fixed_parms, float_parms, parm_info;
4667 int i;
4669 while (*fname == '.') /* V.4 encodes . in the name */
4670 fname++;
4672 /* Need label immediately before tbtab, so we can compute its offset
4673 from the function start. */
4674 if (*fname == '*')
4675 ++fname;
4676 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
4677 ASM_OUTPUT_LABEL (file, fname);
4679 /* The .tbtab pseudo-op can only be used for the first eight
4680 expressions, since it can't handle the possibly variable
4681 length fields that follow. However, if you omit the optional
4682 fields, the assembler outputs zeros for all optional fields
4683 anyways, giving each variable length field is minimum length
4684 (as defined in sys/debug.h). Thus we can not use the .tbtab
4685 pseudo-op at all. */
4687 /* An all-zero word flags the start of the tbtab, for debuggers
4688 that have to find it by searching forward from the entry
4689 point or from the current pc. */
4690 fputs ("\t.long 0\n", file);
4692 /* Tbtab format type. Use format type 0. */
4693 fputs ("\t.byte 0,", file);
4695 /* Language type. Unfortunately, there doesn't seem to be any
4696 official way to get this info, so we use language_string. C
4697 is 0. C++ is 9. No number defined for Obj-C, so use the
4698 value for C for now. There is no official value for Java,
4699 although IBM appears to be using 13. There is no official value
4700 for Chill, so we've choosen 44 pseudo-randomly. */
4701 if (! strcmp (language_string, "GNU C")
4702 || ! strcmp (language_string, "GNU Obj-C"))
4703 i = 0;
4704 else if (! strcmp (language_string, "GNU F77"))
4705 i = 1;
4706 else if (! strcmp (language_string, "GNU Ada"))
4707 i = 3;
4708 else if (! strcmp (language_string, "GNU Pascal"))
4709 i = 2;
4710 else if (! strcmp (language_string, "GNU C++"))
4711 i = 9;
4712 else if (! strcmp (language_string, "GNU Java"))
4713 i = 13;
4714 else if (! strcmp (language_string, "GNU CHILL"))
4715 i = 44;
4716 else
4717 abort ();
4718 fprintf (file, "%d,", i);
4720 /* 8 single bit fields: global linkage (not set for C extern linkage,
4721 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
4722 from start of procedure stored in tbtab, internal function, function
4723 has controlled storage, function has no toc, function uses fp,
4724 function logs/aborts fp operations. */
4725 /* Assume that fp operations are used if any fp reg must be saved. */
4726 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
4728 /* 6 bitfields: function is interrupt handler, name present in
4729 proc table, function calls alloca, on condition directives
4730 (controls stack walks, 3 bits), saves condition reg, saves
4731 link reg. */
4732 /* The `function calls alloca' bit seems to be set whenever reg 31 is
4733 set up as a frame pointer, even when there is no alloca call. */
4734 fprintf (file, "%d,",
4735 ((1 << 6) | (frame_pointer_needed << 5)
4736 | (info->cr_save_p << 1) | (info->lr_save_p)));
4738 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
4739 (6 bits). */
4740 fprintf (file, "%d,",
4741 (info->push_p << 7) | (64 - info->first_fp_reg_save));
4743 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
4744 fprintf (file, "%d,", (32 - first_reg_to_save ()));
4747 /* Compute the parameter info from the function decl argument
4748 list. */
4749 tree decl;
4750 int next_parm_info_bit;
4752 next_parm_info_bit = 31;
4753 parm_info = 0;
4754 fixed_parms = 0;
4755 float_parms = 0;
4757 for (decl = DECL_ARGUMENTS (current_function_decl);
4758 decl; decl = TREE_CHAIN (decl))
4760 rtx parameter = DECL_INCOMING_RTL (decl);
4761 enum machine_mode mode = GET_MODE (parameter);
4763 if (GET_CODE (parameter) == REG)
4765 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
4767 int bits;
4769 float_parms++;
4771 if (mode == SFmode)
4772 bits = 0x2;
4773 else if (mode == DFmode)
4774 bits = 0x3;
4775 else
4776 abort ();
4778 /* If only one bit will fit, don't or in this entry. */
4779 if (next_parm_info_bit > 0)
4780 parm_info |= (bits << (next_parm_info_bit - 1));
4781 next_parm_info_bit -= 2;
4783 else
4785 fixed_parms += ((GET_MODE_SIZE (mode)
4786 + (UNITS_PER_WORD - 1))
4787 / UNITS_PER_WORD);
4788 next_parm_info_bit -= 1;
4794 /* Number of fixed point parameters. */
4795 /* This is actually the number of words of fixed point parameters; thus
4796 an 8 byte struct counts as 2; and thus the maximum value is 8. */
4797 fprintf (file, "%d,", fixed_parms);
4799 /* 2 bitfields: number of floating point parameters (7 bits), parameters
4800 all on stack. */
4801 /* This is actually the number of fp registers that hold parameters;
4802 and thus the maximum value is 13. */
4803 /* Set parameters on stack bit if parameters are not in their original
4804 registers, regardless of whether they are on the stack? Xlc
4805 seems to set the bit when not optimizing. */
4806 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
4808 /* Optional fields follow. Some are variable length. */
4810 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
4811 11 double float. */
4812 /* There is an entry for each parameter in a register, in the order that
4813 they occur in the parameter list. Any intervening arguments on the
4814 stack are ignored. If the list overflows a long (max possible length
4815 34 bits) then completely leave off all elements that don't fit. */
4816 /* Only emit this long if there was at least one parameter. */
4817 if (fixed_parms || float_parms)
4818 fprintf (file, "\t.long %d\n", parm_info);
4820 /* Offset from start of code to tb table. */
4821 fputs ("\t.long ", file);
4822 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
4823 RS6000_OUTPUT_BASENAME (file, fname);
4824 fputs ("-.", file);
4825 RS6000_OUTPUT_BASENAME (file, fname);
4826 putc ('\n', file);
4828 /* Interrupt handler mask. */
4829 /* Omit this long, since we never set the interrupt handler bit
4830 above. */
4832 /* Number of CTL (controlled storage) anchors. */
4833 /* Omit this long, since the has_ctl bit is never set above. */
4835 /* Displacement into stack of each CTL anchor. */
4836 /* Omit this list of longs, because there are no CTL anchors. */
4838 /* Length of function name. */
4839 fprintf (file, "\t.short %d\n", (int) strlen (fname));
4841 /* Function name. */
4842 assemble_string (fname, strlen (fname));
4844 /* Register for alloca automatic storage; this is always reg 31.
4845 Only emit this if the alloca bit was set above. */
4846 if (frame_pointer_needed)
4847 fputs ("\t.byte 31\n", file);
4850 if (DEFAULT_ABI == ABI_NT)
4852 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4853 fputs (".e:\nFE_MOT_RESVD..", file);
4854 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4855 fputs (":\n", file);
4859 /* A C compound statement that outputs the assembler code for a thunk function,
4860 used to implement C++ virtual function calls with multiple inheritance. The
4861 thunk acts as a wrapper around a virtual function, adjusting the implicit
4862 object parameter before handing control off to the real function.
4864 First, emit code to add the integer DELTA to the location that contains the
4865 incoming first argument. Assume that this argument contains a pointer, and
4866 is the one used to pass the `this' pointer in C++. This is the incoming
4867 argument *before* the function prologue, e.g. `%o0' on a sparc. The
4868 addition must preserve the values of all other incoming arguments.
4870 After the addition, emit code to jump to FUNCTION, which is a
4871 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
4872 the return address. Hence returning from FUNCTION will return to whoever
4873 called the current `thunk'.
4875 The effect must be as if FUNCTION had been called directly with the adjusted
4876 first argument. This macro is responsible for emitting all of the code for
4877 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
4878 invoked.
4880 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
4881 extracted from it.) It might possibly be useful on some targets, but
4882 probably not.
4884 If you do not define this macro, the target-independent code in the C++
4885 frontend will generate a less efficient heavyweight thunk that calls
4886 FUNCTION instead of jumping to it. The generic approach does not support
4887 varargs. */
4889 void
4890 output_mi_thunk (file, thunk_fndecl, delta, function)
4891 FILE *file;
4892 tree thunk_fndecl ATTRIBUTE_UNUSED;
4893 int delta;
4894 tree function;
4896 const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
4897 const char *prefix;
4898 const char *fname;
4899 const char *r0 = reg_names[0];
4900 const char *sp = reg_names[1];
4901 const char *toc = reg_names[2];
4902 const char *schain = reg_names[11];
4903 const char *r12 = reg_names[12];
4904 char buf[512];
4905 static int labelno = 0;
4907 /* Small constants that can be done by one add instruction */
4908 if (delta >= -32768 && delta <= 32767)
4910 if (! TARGET_NEW_MNEMONICS)
4911 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
4912 else
4913 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
4916 /* Large constants that can be done by one addis instruction */
4917 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
4918 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
4919 delta >> 16);
4921 /* 32-bit constants that can be done by an add and addis instruction. */
4922 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
4924 /* Break into two pieces, propagating the sign bit from the low word to
4925 the upper word. */
4926 int delta_high = delta >> 16;
4927 int delta_low = delta & 0xffff;
4928 if ((delta_low & 0x8000) != 0)
4930 delta_high++;
4931 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
4934 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
4935 delta_high);
4937 if (! TARGET_NEW_MNEMONICS)
4938 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
4939 else
4940 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
4943 /* 64-bit constants, fixme */
4944 else
4945 abort ();
4947 /* Get the prefix in front of the names. */
4948 switch (DEFAULT_ABI)
4950 default:
4951 abort ();
4953 case ABI_AIX:
4954 prefix = ".";
4955 break;
4957 case ABI_V4:
4958 case ABI_AIX_NODESC:
4959 case ABI_SOLARIS:
4960 prefix = "";
4961 break;
4963 case ABI_NT:
4964 prefix = "..";
4965 break;
4968 /* If the function is compiled in this module, jump to it directly.
4969 Otherwise, load up its address and jump to it. */
4971 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
4973 if (current_file_function_operand (XEXP (DECL_RTL (function), 0))
4974 && ! lookup_attribute ("longcall",
4975 TYPE_ATTRIBUTES (TREE_TYPE (function))))
4977 fprintf (file, "\tb %s", prefix);
4978 assemble_name (file, fname);
4979 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
4980 putc ('\n', file);
4983 else
4985 switch (DEFAULT_ABI)
4987 default:
4988 case ABI_NT:
4989 abort ();
4991 case ABI_AIX:
4992 /* Set up a TOC entry for the function. */
4993 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
4994 toc_section ();
4995 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
4996 labelno++;
4998 /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since
4999 there will be only one TOC entry for this function. */
5000 fputs ("\t.tc\t", file);
5001 assemble_name (file, buf);
5002 fputs ("[TC],", file);
5003 assemble_name (file, buf);
5004 putc ('\n', file);
5005 text_section ();
5006 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12);
5007 assemble_name (file, buf);
5008 asm_fprintf (file, "(%s)\n", reg_names[2]);
5009 asm_fprintf (file,
5010 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
5011 r0, r12);
5013 asm_fprintf (file,
5014 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
5015 toc, r12);
5017 asm_fprintf (file, "\tmtctr %s\n", r0);
5018 asm_fprintf (file,
5019 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
5020 schain, r12);
5022 asm_fprintf (file, "\tbctr\n");
5023 break;
5025 case ABI_V4:
5026 fprintf (file, "\tb %s", prefix);
5027 assemble_name (file, fname);
5028 if (flag_pic) fputs ("@plt", file);
5029 putc ('\n', file);
5030 break;
5032 /* Don't use r11, that contains the static chain, just use r0/r12. */
5033 case ABI_AIX_NODESC:
5034 case ABI_SOLARIS:
5035 if (flag_pic == 1)
5037 fprintf (file, "\tmflr %s\n", r0);
5038 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
5039 asm_fprintf (file, "\tmflr %s\n", r12);
5040 asm_fprintf (file, "\tmtlr %s\n", r0);
5041 asm_fprintf (file, "\t{l|lwz} %s,", r0);
5042 assemble_name (file, fname);
5043 asm_fprintf (file, "@got(%s)\n", r12);
5044 asm_fprintf (file, "\tmtctr %s\n", r0);
5045 asm_fprintf (file, "\tbctr\n");
5047 #if TARGET_ELF
5048 else if (flag_pic > 1 || TARGET_RELOCATABLE)
5050 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
5051 labelno++;
5052 fprintf (file, "\tmflr %s\n", r0);
5053 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", r0, sp);
5054 rs6000_pic_func_labelno = rs6000_pic_labelno;
5055 rs6000_output_load_toc_table (file, 12);
5056 asm_fprintf (file, "\t{l|lwz} %s,", r0);
5057 assemble_name (file, buf);
5058 asm_fprintf (file, "(%s)\n", r12);
5059 asm_fprintf (file, "\t{l|lwz} %s,4(%s)\n", r12, sp);
5060 asm_fprintf (file, "\tmtlr %s\n", r12);
5061 asm_fprintf (file, "\tmtctr %s\n", r0);
5062 asm_fprintf (file, "\tbctr\n");
5063 asm_fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
5064 assemble_name (file, buf);
5065 fputs (" = .-.LCTOC1\n", file);
5066 fputs ("\t.long ", file);
5067 assemble_name (file, fname);
5068 fputs ("\n\t.previous\n", file);
5070 #endif /* TARGET_ELF */
5072 else
5074 asm_fprintf (file, "\t{liu|lis} %s,", r12);
5075 assemble_name (file, fname);
5076 asm_fprintf (file, "@ha\n");
5077 asm_fprintf (file, "\t{cal|la} %s,", r12);
5078 assemble_name (file, fname);
5079 asm_fprintf (file, "@l(%s)\n", r12);
5080 asm_fprintf (file, "\tmtctr %s\n", r12);
5081 asm_fprintf (file, "\tbctr\n");
5084 break;
5090 /* Output a TOC entry. We derive the entry name from what is
5091 being written. */
5093 void
5094 output_toc (file, x, labelno)
5095 FILE *file;
5096 rtx x;
5097 int labelno;
5099 char buf[256];
5100 const char *name = buf;
5101 const char *real_name;
5102 rtx base = x;
5103 int offset = 0;
5105 if (TARGET_NO_TOC)
5106 abort ();
5108 /* if we're going to put a double constant in the TOC, make sure it's
5109 aligned properly when strict alignment is on. */
5110 if (GET_CODE (x) == CONST_DOUBLE
5111 && STRICT_ALIGNMENT
5112 && GET_MODE (x) == DFmode
5113 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
5114 ASM_OUTPUT_ALIGN (file, 3);
5118 if (TARGET_ELF && TARGET_MINIMAL_TOC)
5120 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
5121 fprintf (file, "%d = .-", labelno);
5122 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
5123 fputs ("1\n", file);
5125 else
5126 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
5128 /* Handle FP constants specially. Note that if we have a minimal
5129 TOC, things we put here aren't actually in the TOC, so we can allow
5130 FP constants. */
5131 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode
5132 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
5134 REAL_VALUE_TYPE rv;
5135 long k[2];
5137 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
5138 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
5140 if (TARGET_64BIT)
5142 if (TARGET_MINIMAL_TOC)
5143 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
5144 else
5145 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
5146 k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff);
5147 return;
5149 else
5151 if (TARGET_MINIMAL_TOC)
5152 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]);
5153 else
5154 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n",
5155 k[0], k[1], k[0], k[1]);
5156 return;
5159 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
5160 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
5162 REAL_VALUE_TYPE rv;
5163 long l;
5165 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
5166 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5168 if (TARGET_64BIT)
5170 if (TARGET_MINIMAL_TOC)
5171 fprintf (file, "\t.llong 0x%lx00000000\n", l);
5172 else
5173 fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l);
5174 return;
5176 else
5178 if (TARGET_MINIMAL_TOC)
5179 fprintf (file, "\t.long 0x%lx\n", l);
5180 else
5181 fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l);
5182 return;
5185 else if (GET_MODE (x) == DImode
5186 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
5187 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
5189 HOST_WIDE_INT low;
5190 HOST_WIDE_INT high;
5192 if (GET_CODE (x) == CONST_DOUBLE)
5194 low = CONST_DOUBLE_LOW (x);
5195 high = CONST_DOUBLE_HIGH (x);
5197 else
5198 #if HOST_BITS_PER_WIDE_INT == 32
5200 low = INTVAL (x);
5201 high = (low < 0) ? ~0 : 0;
5203 #else
5205 low = INTVAL (x) & 0xffffffff;
5206 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
5208 #endif
5210 if (TARGET_64BIT)
5212 if (TARGET_MINIMAL_TOC)
5213 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
5214 else
5215 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
5216 (long)high, (long)low, (long)high, (long)low);
5217 return;
5219 else
5221 if (TARGET_MINIMAL_TOC)
5222 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n",
5223 (long)high, (long)low);
5224 else
5225 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n",
5226 (long)high, (long)low, (long)high, (long)low);
5227 return;
5231 if (GET_CODE (x) == CONST)
5233 base = XEXP (XEXP (x, 0), 0);
5234 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5237 if (GET_CODE (base) == SYMBOL_REF)
5238 name = XSTR (base, 0);
5239 else if (GET_CODE (base) == LABEL_REF)
5240 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
5241 else if (GET_CODE (base) == CODE_LABEL)
5242 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
5243 else
5244 abort ();
5246 STRIP_NAME_ENCODING (real_name, name);
5247 if (TARGET_MINIMAL_TOC)
5248 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
5249 else
5251 fprintf (file, "\t.tc %s", real_name);
5253 if (offset < 0)
5254 fprintf (file, ".N%d", - offset);
5255 else if (offset)
5256 fprintf (file, ".P%d", offset);
5258 fputs ("[TC],", file);
5261 /* Currently C++ toc references to vtables can be emitted before it
5262 is decided whether the vtable is public or private. If this is
5263 the case, then the linker will eventually complain that there is
5264 a TOC reference to an unknown section. Thus, for vtables only,
5265 we emit the TOC reference to reference the symbol and not the
5266 section. */
5267 if (! strncmp ("_vt.", name, 4))
5269 RS6000_OUTPUT_BASENAME (file, name);
5270 if (offset < 0)
5271 fprintf (file, "%d", offset);
5272 else if (offset > 0)
5273 fprintf (file, "+%d", offset);
5275 else
5276 output_addr_const (file, x);
5277 putc ('\n', file);
5280 /* Output an assembler pseudo-op to write an ASCII string of N characters
5281 starting at P to FILE.
5283 On the RS/6000, we have to do this using the .byte operation and
5284 write out special characters outside the quoted string.
5285 Also, the assembler is broken; very long strings are truncated,
5286 so we must artificially break them up early. */
5288 void
5289 output_ascii (file, p, n)
5290 FILE *file;
5291 const char *p;
5292 int n;
5294 char c;
5295 int i, count_string;
5296 const char *for_string = "\t.byte \"";
5297 const char *for_decimal = "\t.byte ";
5298 const char *to_close = NULL;
5300 count_string = 0;
5301 for (i = 0; i < n; i++)
5303 c = *p++;
5304 if (c >= ' ' && c < 0177)
5306 if (for_string)
5307 fputs (for_string, file);
5308 putc (c, file);
5310 /* Write two quotes to get one. */
5311 if (c == '"')
5313 putc (c, file);
5314 ++count_string;
5317 for_string = NULL;
5318 for_decimal = "\"\n\t.byte ";
5319 to_close = "\"\n";
5320 ++count_string;
5322 if (count_string >= 512)
5324 fputs (to_close, file);
5326 for_string = "\t.byte \"";
5327 for_decimal = "\t.byte ";
5328 to_close = NULL;
5329 count_string = 0;
5332 else
5334 if (for_decimal)
5335 fputs (for_decimal, file);
5336 fprintf (file, "%d", c);
5338 for_string = "\n\t.byte \"";
5339 for_decimal = ", ";
5340 to_close = "\n";
5341 count_string = 0;
5345 /* Now close the string if we have written one. Then end the line. */
5346 if (to_close)
5347 fprintf (file, to_close);
5350 /* Generate a unique section name for FILENAME for a section type
5351 represented by SECTION_DESC. Output goes into BUF.
5353 SECTION_DESC can be any string, as long as it is different for each
5354 possible section type.
5356 We name the section in the same manner as xlc. The name begins with an
5357 underscore followed by the filename (after stripping any leading directory
5358 names) with the last period replaced by the string SECTION_DESC. If
5359 FILENAME does not contain a period, SECTION_DESC is appended to the end of
5360 the name. */
5362 void
5363 rs6000_gen_section_name (buf, filename, section_desc)
5364 char **buf;
5365 char *filename;
5366 char *section_desc;
5368 char *q, *after_last_slash, *last_period = 0;
5369 char *p;
5370 int len;
5372 after_last_slash = filename;
5373 for (q = filename; *q; q++)
5375 if (*q == '/')
5376 after_last_slash = q + 1;
5377 else if (*q == '.')
5378 last_period = q;
5381 len = strlen (after_last_slash) + strlen (section_desc) + 2;
5382 *buf = (char *) permalloc (len);
5384 p = *buf;
5385 *p++ = '_';
5387 for (q = after_last_slash; *q; q++)
5389 if (q == last_period)
5391 strcpy (p, section_desc);
5392 p += strlen (section_desc);
5395 else if (ISALNUM (*q))
5396 *p++ = *q;
5399 if (last_period == 0)
5400 strcpy (p, section_desc);
5401 else
5402 *p = '\0';
5405 /* Write function profiler code. */
5407 void
5408 output_function_profiler (file, labelno)
5409 FILE *file;
5410 int labelno;
5412 /* The last used parameter register. */
5413 int last_parm_reg;
5414 int i, j;
5415 char buf[100];
5417 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
5418 switch (DEFAULT_ABI)
5420 default:
5421 abort ();
5423 case ABI_V4:
5424 case ABI_SOLARIS:
5425 case ABI_AIX_NODESC:
5426 fprintf (file, "\tmflr %s\n", reg_names[0]);
5427 if (flag_pic == 1)
5429 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
5430 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
5431 reg_names[0], reg_names[1]);
5432 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
5433 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
5434 assemble_name (file, buf);
5435 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
5437 #if TARGET_ELF
5438 else if (flag_pic > 1 || TARGET_RELOCATABLE)
5440 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
5441 reg_names[0], reg_names[1]);
5442 rs6000_pic_func_labelno = rs6000_pic_labelno;
5443 rs6000_output_load_toc_table (file, 12);
5444 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[12]);
5445 assemble_name (file, buf);
5446 asm_fprintf (file, "X(%s)\n", reg_names[12]);
5447 asm_fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
5448 assemble_name (file, buf);
5449 fputs ("X = .-.LCTOC1\n", file);
5450 fputs ("\t.long ", file);
5451 assemble_name (file, buf);
5452 fputs ("\n\t.previous\n", file);
5454 #endif
5455 else
5457 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
5458 assemble_name (file, buf);
5459 fputs ("@ha\n", file);
5460 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
5461 reg_names[0], reg_names[1]);
5462 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
5463 assemble_name (file, buf);
5464 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
5467 if (current_function_needs_context)
5468 asm_fprintf (file, "\tmr %s,%s\n",
5469 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
5470 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
5471 if (current_function_needs_context)
5472 asm_fprintf (file, "\tmr %s,%s\n",
5473 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
5474 break;
5476 case ABI_AIX:
5477 /* Set up a TOC entry for the profiler label. */
5478 toc_section ();
5479 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
5480 if (TARGET_MINIMAL_TOC)
5482 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
5483 assemble_name (file, buf);
5484 putc ('\n', file);
5486 else
5488 fputs ("\t.tc\t", file);
5489 assemble_name (file, buf);
5490 fputs ("[TC],", file);
5491 assemble_name (file, buf);
5492 putc ('\n', file);
5494 text_section ();
5496 /* Figure out last used parameter register. The proper thing to do is
5497 to walk incoming args of the function. A function might have live
5498 parameter registers even if it has no incoming args. */
5500 for (last_parm_reg = 10;
5501 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
5502 last_parm_reg--)
5505 /* Save parameter registers in regs 23-30 and static chain in r22.
5506 Don't overwrite reg 31, since it might be set up as the frame pointer. */
5508 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
5509 asm_fprintf (file, "\tmr %d,%d\n", j, i);
5510 if (current_function_needs_context)
5511 asm_fprintf (file, "\tmr %d,%d\n", j, STATIC_CHAIN_REGNUM);
5513 /* Load location address into r3, and call mcount. */
5515 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
5516 asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,",
5517 reg_names[3]);
5518 assemble_name (file, buf);
5519 asm_fprintf (file, "(%s)\n\tbl %s\n\t", reg_names[2], RS6000_MCOUNT);
5520 asm_fprintf (file, RS6000_CALL_GLUE);
5521 putc('\n', file);
5523 /* Restore parameter registers and static chain. */
5525 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
5526 asm_fprintf (file, "\tmr %d,%d\n", i, j);
5527 if (current_function_needs_context)
5528 asm_fprintf (file, "\tmr %d,%d\n", STATIC_CHAIN_REGNUM, j);
5530 break;
5534 /* Adjust the cost of a scheduling dependency. Return the new cost of
5535 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
5538 rs6000_adjust_cost (insn, link, dep_insn, cost)
5539 rtx insn;
5540 rtx link;
5541 rtx dep_insn ATTRIBUTE_UNUSED;
5542 int cost;
5544 if (! recog_memoized (insn))
5545 return 0;
5547 if (REG_NOTE_KIND (link) != 0)
5548 return 0;
5550 if (REG_NOTE_KIND (link) == 0)
5552 /* Data dependency; DEP_INSN writes a register that INSN reads some
5553 cycles later. */
5555 /* Tell the first scheduling pass about the latency between a mtctr
5556 and bctr (and mtlr and br/blr). The first scheduling pass will not
5557 know about this latency since the mtctr instruction, which has the
5558 latency associated to it, will be generated by reload. */
5559 if (get_attr_type (insn) == TYPE_JMPREG)
5560 return TARGET_POWER ? 5 : 4;
5562 /* Fall out to return default cost. */
5565 return cost;
5568 /* A C statement (sans semicolon) to update the integer scheduling priority
5569 INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier,
5570 increase the priority to execute INSN later. Do not define this macro if
5571 you do not need to adjust the scheduling priorities of insns. */
5574 rs6000_adjust_priority (insn, priority)
5575 rtx insn ATTRIBUTE_UNUSED;
5576 int priority;
5578 /* On machines (like the 750) which have asymetric integer units, where one
5579 integer unit can do multiply and divides and the other can't, reduce the
5580 priority of multiply/divide so it is scheduled before other integer
5581 operationss. */
5583 #if 0
5584 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
5585 return priority;
5587 if (GET_CODE (PATTERN (insn)) == USE)
5588 return priority;
5590 switch (rs6000_cpu_attr) {
5591 case CPU_PPC750:
5592 switch (get_attr_type (insn))
5594 default:
5595 break;
5597 case TYPE_IMUL:
5598 case TYPE_IDIV:
5599 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
5600 priority, priority);
5601 if (priority >= 0 && priority < 0x01000000)
5602 priority >>= 3;
5603 break;
5606 #endif
5608 return priority;
5611 /* Return how many instructions the machine can issue per cycle */
5612 int get_issue_rate()
5614 switch (rs6000_cpu_attr) {
5615 case CPU_RIOS1: /* ? */
5616 case CPU_RS64A:
5617 case CPU_PPC601: /* ? */
5618 return 3;
5619 case CPU_PPC603:
5620 case CPU_PPC750:
5621 return 2;
5622 case CPU_RIOS2:
5623 case CPU_PPC604:
5624 case CPU_PPC604E:
5625 case CPU_PPC620:
5626 case CPU_PPC630:
5627 return 4;
5628 default:
5629 return 1;
5634 /* Output assembler code for a block containing the constant parts
5635 of a trampoline, leaving space for the variable parts.
5637 The trampoline should set the static chain pointer to value placed
5638 into the trampoline and should branch to the specified routine. */
5640 void
5641 rs6000_trampoline_template (file)
5642 FILE *file;
5644 const char *sc = reg_names[STATIC_CHAIN_REGNUM];
5645 const char *r0 = reg_names[0];
5646 const char *r2 = reg_names[2];
5648 switch (DEFAULT_ABI)
5650 default:
5651 abort ();
5653 /* Under AIX, this is not code at all, but merely a data area,
5654 since that is the way all functions are called. The first word is
5655 the address of the function, the second word is the TOC pointer (r2),
5656 and the third word is the static chain value. */
5657 case ABI_AIX:
5658 break;
5661 /* V.4/eabi function pointers are just a single pointer, so we need to
5662 do the full gory code to load up the static chain. */
5663 case ABI_V4:
5664 case ABI_SOLARIS:
5665 case ABI_AIX_NODESC:
5666 break;
5668 /* NT function pointers point to a two word area (real address, TOC)
5669 which unfortunately does not include a static chain field. So we
5670 use the function field to point to ..LTRAMP1 and the toc field
5671 to point to the whole table. */
5672 case ABI_NT:
5673 if (STATIC_CHAIN_REGNUM == 0
5674 || STATIC_CHAIN_REGNUM == 2
5675 || TARGET_64BIT
5676 || !TARGET_NEW_MNEMONICS)
5677 abort ();
5679 fprintf (file, "\t.ualong 0\n"); /* offset 0 */
5680 fprintf (file, "\t.ualong 0\n"); /* offset 4 */
5681 fprintf (file, "\t.ualong 0\n"); /* offset 8 */
5682 fprintf (file, "\t.ualong 0\n"); /* offset 12 */
5683 fprintf (file, "\t.ualong 0\n"); /* offset 16 */
5684 fprintf (file, "..LTRAMP1..0:\n"); /* offset 20 */
5685 fprintf (file, "\tlwz %s,8(%s)\n", r0, r2); /* offset 24 */
5686 fprintf (file, "\tlwz %s,12(%s)\n", sc, r2); /* offset 28 */
5687 fprintf (file, "\tmtctr %s\n", r0); /* offset 32 */
5688 fprintf (file, "\tlwz %s,16(%s)\n", r2, r2); /* offset 36 */
5689 fprintf (file, "\tbctr\n"); /* offset 40 */
5690 break;
5693 return;
5696 /* Length in units of the trampoline for entering a nested function. */
5699 rs6000_trampoline_size ()
5701 int ret = 0;
5703 switch (DEFAULT_ABI)
5705 default:
5706 abort ();
5708 case ABI_AIX:
5709 ret = (TARGET_32BIT) ? 12 : 24;
5710 break;
5712 case ABI_V4:
5713 case ABI_SOLARIS:
5714 case ABI_AIX_NODESC:
5715 ret = (TARGET_32BIT) ? 40 : 48;
5716 break;
5718 case ABI_NT:
5719 ret = 20;
5720 break;
5723 return ret;
5726 /* Emit RTL insns to initialize the variable parts of a trampoline.
5727 FNADDR is an RTX for the address of the function's pure code.
5728 CXT is an RTX for the static chain value for the function. */
5730 void
5731 rs6000_initialize_trampoline (addr, fnaddr, cxt)
5732 rtx addr;
5733 rtx fnaddr;
5734 rtx cxt;
5736 enum machine_mode pmode = Pmode;
5737 int regsize = (TARGET_32BIT) ? 4 : 8;
5738 rtx ctx_reg = force_reg (pmode, cxt);
5740 switch (DEFAULT_ABI)
5742 default:
5743 abort ();
5745 /* Macros to shorten the code expansions below. */
5746 #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
5747 #define MEM_PLUS(addr,offset) \
5748 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
5750 /* Under AIX, just build the 3 word function descriptor */
5751 case ABI_AIX:
5753 rtx fn_reg = gen_reg_rtx (pmode);
5754 rtx toc_reg = gen_reg_rtx (pmode);
5755 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
5756 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
5757 emit_move_insn (MEM_DEREF (addr), fn_reg);
5758 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
5759 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
5761 break;
5763 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
5764 case ABI_V4:
5765 case ABI_SOLARIS:
5766 case ABI_AIX_NODESC:
5767 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
5768 FALSE, VOIDmode, 4,
5769 addr, pmode,
5770 GEN_INT (rs6000_trampoline_size ()), SImode,
5771 fnaddr, pmode,
5772 ctx_reg, pmode);
5773 break;
5775 /* Under NT, update the first word to point to the ..LTRAMP1..0 header,
5776 the second word will point to the whole trampoline, third-fifth words
5777 will then have the real address, static chain, and toc value. */
5778 case ABI_NT:
5780 rtx tramp_reg = gen_reg_rtx (pmode);
5781 rtx fn_reg = gen_reg_rtx (pmode);
5782 rtx toc_reg = gen_reg_rtx (pmode);
5784 emit_move_insn (tramp_reg, gen_rtx_SYMBOL_REF (pmode, "..LTRAMP1..0"));
5785 addr = force_reg (pmode, addr);
5786 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
5787 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
5788 emit_move_insn (MEM_DEREF (addr), tramp_reg);
5789 emit_move_insn (MEM_PLUS (addr, regsize), addr);
5790 emit_move_insn (MEM_PLUS (addr, 2*regsize), fn_reg);
5791 emit_move_insn (MEM_PLUS (addr, 3*regsize), ctx_reg);
5792 emit_move_insn (MEM_PLUS (addr, 4*regsize), gen_rtx_REG (pmode, 2));
5794 break;
5797 return;
5801 /* If defined, a C expression whose value is nonzero if IDENTIFIER
5802 with arguments ARGS is a valid machine specific attribute for DECL.
5803 The attributes in ATTRIBUTES have previously been assigned to DECL. */
5806 rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
5807 tree decl ATTRIBUTE_UNUSED;
5808 tree attributes ATTRIBUTE_UNUSED;
5809 tree identifier ATTRIBUTE_UNUSED;
5810 tree args ATTRIBUTE_UNUSED;
5812 return 0;
5815 /* If defined, a C expression whose value is nonzero if IDENTIFIER
5816 with arguments ARGS is a valid machine specific attribute for TYPE.
5817 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
5820 rs6000_valid_type_attribute_p (type, attributes, identifier, args)
5821 tree type;
5822 tree attributes ATTRIBUTE_UNUSED;
5823 tree identifier;
5824 tree args;
5826 if (TREE_CODE (type) != FUNCTION_TYPE
5827 && TREE_CODE (type) != FIELD_DECL
5828 && TREE_CODE (type) != TYPE_DECL)
5829 return 0;
5831 /* Longcall attribute says that the function is not within 2**26 bytes
5832 of the current function, and to do an indirect call. */
5833 if (is_attribute_p ("longcall", identifier))
5834 return (args == NULL_TREE);
5836 if (DEFAULT_ABI == ABI_NT)
5838 /* Stdcall attribute says callee is responsible for popping arguments
5839 if they are not variable. */
5840 if (is_attribute_p ("stdcall", identifier))
5841 return (args == NULL_TREE);
5843 /* Cdecl attribute says the callee is a normal C declaration */
5844 if (is_attribute_p ("cdecl", identifier))
5845 return (args == NULL_TREE);
5847 /* Dllimport attribute says the caller is to call the function
5848 indirectly through a __imp_<name> pointer. */
5849 if (is_attribute_p ("dllimport", identifier))
5850 return (args == NULL_TREE);
5852 /* Dllexport attribute says the callee is to create a __imp_<name>
5853 pointer. */
5854 if (is_attribute_p ("dllexport", identifier))
5855 return (args == NULL_TREE);
5857 /* Exception attribute allows the user to specify 1-2 strings
5858 or identifiers that will fill in the 3rd and 4th fields
5859 of the structured exception table. */
5860 if (is_attribute_p ("exception", identifier))
5862 int i;
5864 if (args == NULL_TREE)
5865 return 0;
5867 for (i = 0; i < 2 && args != NULL_TREE; i++)
5869 tree this_arg = TREE_VALUE (args);
5870 args = TREE_PURPOSE (args);
5872 if (TREE_CODE (this_arg) != STRING_CST
5873 && TREE_CODE (this_arg) != IDENTIFIER_NODE)
5874 return 0;
5877 return (args == NULL_TREE);
5881 return 0;
5884 /* If defined, a C expression whose value is zero if the attributes on
5885 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
5886 two if they are nearly compatible (which causes a warning to be
5887 generated). */
5890 rs6000_comp_type_attributes (type1, type2)
5891 tree type1 ATTRIBUTE_UNUSED;
5892 tree type2 ATTRIBUTE_UNUSED;
5894 return 1;
5897 /* If defined, a C statement that assigns default attributes to newly
5898 defined TYPE. */
5900 void
5901 rs6000_set_default_type_attributes (type)
5902 tree type ATTRIBUTE_UNUSED;
5904 return;
5907 /* Return a dll import reference corresponding to a call's SYMBOL_REF */
5908 struct rtx_def *
5909 rs6000_dll_import_ref (call_ref)
5910 rtx call_ref;
5912 const char *call_name;
5913 int len;
5914 char *p;
5915 rtx reg1, reg2;
5916 tree node;
5918 if (GET_CODE (call_ref) != SYMBOL_REF)
5919 abort ();
5921 call_name = XSTR (call_ref, 0);
5922 len = sizeof ("__imp_") + strlen (call_name);
5923 p = alloca (len);
5924 reg2 = gen_reg_rtx (Pmode);
5926 strcpy (p, "__imp_");
5927 strcat (p, call_name);
5928 node = get_identifier (p);
5930 reg1 = force_reg (Pmode, gen_rtx_SYMBOL_REF (VOIDmode,
5931 IDENTIFIER_POINTER (node)));
5932 emit_move_insn (reg2, gen_rtx_MEM (Pmode, reg1));
5934 return reg2;
5937 /* Return a reference suitable for calling a function with the
5938 longcall attribute. */
5939 struct rtx_def *
5940 rs6000_longcall_ref (call_ref)
5941 rtx call_ref;
5943 const char *call_name;
5944 tree node;
5946 if (GET_CODE (call_ref) != SYMBOL_REF)
5947 return call_ref;
5949 /* System V adds '.' to the internal name, so skip them. */
5950 call_name = XSTR (call_ref, 0);
5951 if (*call_name == '.')
5953 while (*call_name == '.')
5954 call_name++;
5956 node = get_identifier (call_name);
5957 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
5960 return force_reg (Pmode, call_ref);
5964 /* A C statement or statements to switch to the appropriate section
5965 for output of RTX in mode MODE. You can assume that RTX is some
5966 kind of constant in RTL. The argument MODE is redundant except in
5967 the case of a `const_int' rtx. Select the section by calling
5968 `text_section' or one of the alternatives for other sections.
5970 Do not define this macro if you put all constants in the read-only
5971 data section. */
5973 #ifdef USING_SVR4_H
5975 void
5976 rs6000_select_rtx_section (mode, x)
5977 enum machine_mode mode ATTRIBUTE_UNUSED;
5978 rtx x;
5980 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x))
5981 toc_section ();
5982 else
5983 const_section ();
5986 /* A C statement or statements to switch to the appropriate
5987 section for output of DECL. DECL is either a `VAR_DECL' node
5988 or a constant of some sort. RELOC indicates whether forming
5989 the initial value of DECL requires link-time relocations. */
5991 void
5992 rs6000_select_section (decl, reloc)
5993 tree decl;
5994 int reloc;
5996 int size = int_size_in_bytes (TREE_TYPE (decl));
5998 if (TREE_CODE (decl) == STRING_CST)
6000 if (! flag_writable_strings)
6001 const_section ();
6002 else
6003 data_section ();
6005 else if (TREE_CODE (decl) == VAR_DECL)
6007 if ((flag_pic && reloc)
6008 || ! TREE_READONLY (decl)
6009 || TREE_SIDE_EFFECTS (decl)
6010 || ! DECL_INITIAL (decl)
6011 || (DECL_INITIAL (decl) != error_mark_node
6012 && ! TREE_CONSTANT (DECL_INITIAL (decl))))
6014 if (rs6000_sdata != SDATA_NONE && (size > 0)
6015 && (size <= g_switch_value))
6016 sdata_section ();
6017 else
6018 data_section ();
6020 else
6022 if (rs6000_sdata != SDATA_NONE && (size > 0)
6023 && (size <= g_switch_value))
6025 if (rs6000_sdata == SDATA_EABI)
6026 sdata2_section ();
6027 else
6028 sdata_section (); /* System V doesn't have .sdata2/.sbss2 */
6030 else
6031 const_section ();
6034 else
6035 const_section ();
6039 /* If we are referencing a function that is static or is known to be
6040 in this file, make the SYMBOL_REF special. We can use this to indicate
6041 that we can branch to this function without emitting a no-op after the
6042 call. For real AIX and NT calling sequences, we also replace the
6043 function name with the real name (1 or 2 leading .'s), rather than
6044 the function descriptor name. This saves a lot of overriding code
6045 to read the prefixes. */
6047 void
6048 rs6000_encode_section_info (decl)
6049 tree decl;
6051 if (TREE_CODE (decl) == FUNCTION_DECL)
6053 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
6054 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
6055 && ! DECL_WEAK (decl))
6056 SYMBOL_REF_FLAG (sym_ref) = 1;
6058 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
6060 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
6061 size_t len2 = strlen (XSTR (sym_ref, 0));
6062 char *str;
6064 if (ggc_p)
6065 str = ggc_alloc_string (NULL, len1 + len2);
6066 else
6067 str = permalloc (len1 + len2 + 1);
6069 str[0] = '.';
6070 str[1] = '.';
6071 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
6073 XSTR (sym_ref, 0) = str;
6076 else if (rs6000_sdata != SDATA_NONE
6077 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6078 && TREE_CODE (decl) == VAR_DECL)
6080 int size = int_size_in_bytes (TREE_TYPE (decl));
6081 tree section_name = DECL_SECTION_NAME (decl);
6082 const char *name = (char *)0;
6083 int len = 0;
6085 if (section_name)
6087 if (TREE_CODE (section_name) == STRING_CST)
6089 name = TREE_STRING_POINTER (section_name);
6090 len = TREE_STRING_LENGTH (section_name);
6092 else
6093 abort ();
6096 if ((size > 0 && size <= g_switch_value)
6097 || (name
6098 && ((len == sizeof (".sdata") - 1
6099 && strcmp (name, ".sdata") == 0)
6100 || (len == sizeof (".sdata2") - 1
6101 && strcmp (name, ".sdata2") == 0)
6102 || (len == sizeof (".sbss") - 1
6103 && strcmp (name, ".sbss") == 0)
6104 || (len == sizeof (".sbss2") - 1
6105 && strcmp (name, ".sbss2") == 0)
6106 || (len == sizeof (".PPC.EMB.sdata0") - 1
6107 && strcmp (name, ".PPC.EMB.sdata0") == 0)
6108 || (len == sizeof (".PPC.EMB.sbss0") - 1
6109 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
6111 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
6112 size_t len = strlen (XSTR (sym_ref, 0));
6113 char *str;
6115 if (ggc_p)
6116 str = ggc_alloc_string (NULL, len + 1);
6117 else
6118 str = permalloc (len + 2);
6119 str[0] = '@';
6120 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
6122 XSTR (sym_ref, 0) = str;
6127 #endif /* USING_SVR4_H */
6130 /* Return a REG that occurs in ADDR with coefficient 1.
6131 ADDR can be effectively incremented by incrementing REG.
6133 r0 is special and we must not select it as an address
6134 register by this routine since our caller will try to
6135 increment the returned register via an "la" instruction. */
6137 struct rtx_def *
6138 find_addr_reg (addr)
6139 rtx addr;
6141 while (GET_CODE (addr) == PLUS)
6143 if (GET_CODE (XEXP (addr, 0)) == REG
6144 && REGNO (XEXP (addr, 0)) != 0)
6145 addr = XEXP (addr, 0);
6146 else if (GET_CODE (XEXP (addr, 1)) == REG
6147 && REGNO (XEXP (addr, 1)) != 0)
6148 addr = XEXP (addr, 1);
6149 else if (CONSTANT_P (XEXP (addr, 0)))
6150 addr = XEXP (addr, 1);
6151 else if (CONSTANT_P (XEXP (addr, 1)))
6152 addr = XEXP (addr, 0);
6153 else
6154 abort ();
6156 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
6157 return addr;
6158 abort ();
6161 void
6162 rs6000_fatal_bad_address (op)
6163 rtx op;
6165 fatal_insn ("bad address", op);
6168 /* Called to register all of our global variables with the garbage
6169 collector. */
6171 static void
6172 rs6000_add_gc_roots ()
6174 ggc_add_rtx_root (&rs6000_compare_op0, 1);
6175 ggc_add_rtx_root (&rs6000_compare_op1, 1);