Commited on behalf of geoffk@cygnus.com:
[official-gcc.git] / gcc / config / rs6000 / rs6000.c
blobba8562be34279677811b6b0a4b8135f63f4dd911
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000 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"
43 #include "hashtab.h"
44 #include "tm_p.h"
46 #ifndef TARGET_NO_PROTOTYPE
47 #define TARGET_NO_PROTOTYPE 0
48 #endif
50 extern int profile_block_flag;
52 #define min(A,B) ((A) < (B) ? (A) : (B))
53 #define max(A,B) ((A) > (B) ? (A) : (B))
55 /* Target cpu type */
57 enum processor_type rs6000_cpu;
58 struct rs6000_cpu_select rs6000_select[3] =
60 /* switch name, tune arch */
61 { (const char *)0, "--with-cpu=", 1, 1 },
62 { (const char *)0, "-mcpu=", 1, 1 },
63 { (const char *)0, "-mtune=", 1, 0 },
66 /* Set to non-zero by "fix" operation to indicate that itrunc and
67 uitrunc must be defined. */
69 int rs6000_trunc_used;
71 /* Set to non-zero once they have been defined. */
73 static int trunc_defined;
75 /* Set to non-zero once AIX common-mode calls have been defined. */
76 static int common_mode_defined;
78 /* Save information from a "cmpxx" operation until the branch or scc is
79 emitted. */
80 rtx rs6000_compare_op0, rs6000_compare_op1;
81 int rs6000_compare_fp_p;
83 /* Label number of label created for -mrelocatable, to call to so we can
84 get the address of the GOT section */
85 int rs6000_pic_labelno;
87 #ifdef USING_SVR4_H
88 /* Which abi to adhere to */
89 const char *rs6000_abi_name = RS6000_ABI_NAME;
91 /* Semantics of the small data area */
92 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
94 /* Which small data model to use */
95 const char *rs6000_sdata_name = (char *)0;
97 /* Counter for labels which are to be placed in .fixup. */
98 int fixuplabelno = 0;
99 #endif
101 /* Whether a System V.4 varargs area was created. */
102 int rs6000_sysv_varargs_p;
104 /* ABI enumeration available for subtarget to use. */
105 enum rs6000_abi rs6000_current_abi;
107 /* Debug flags */
108 const char *rs6000_debug_name;
109 int rs6000_debug_stack; /* debug stack applications */
110 int rs6000_debug_arg; /* debug argument handling */
112 /* Flag to say the TOC is initialized */
113 int toc_initialized;
114 char toc_label_name[10];
116 /* Alias set for saves and restores from the rs6000 stack. */
117 static int rs6000_sr_alias_set;
119 static void rs6000_add_gc_roots PARAMS ((void));
120 static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
121 static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx));
122 static void rs6000_emit_stack_tie PARAMS ((void));
123 static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
124 static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
125 static unsigned rs6000_hash_constant PARAMS ((rtx));
126 static unsigned toc_hash_function PARAMS ((const void *));
127 static int toc_hash_eq PARAMS ((const void *, const void *));
128 static int toc_hash_mark_entry PARAMS ((void **, void *));
129 static void toc_hash_mark_table PARAMS ((void *));
130 static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
132 /* Default register names. */
133 char rs6000_reg_names[][8] =
135 "0", "1", "2", "3", "4", "5", "6", "7",
136 "8", "9", "10", "11", "12", "13", "14", "15",
137 "16", "17", "18", "19", "20", "21", "22", "23",
138 "24", "25", "26", "27", "28", "29", "30", "31",
139 "0", "1", "2", "3", "4", "5", "6", "7",
140 "8", "9", "10", "11", "12", "13", "14", "15",
141 "16", "17", "18", "19", "20", "21", "22", "23",
142 "24", "25", "26", "27", "28", "29", "30", "31",
143 "mq", "lr", "ctr","ap",
144 "0", "1", "2", "3", "4", "5", "6", "7",
145 "xer"
148 #ifdef TARGET_REGNAMES
149 static char alt_reg_names[][8] =
151 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
152 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
153 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
154 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
155 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
156 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
157 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
158 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
159 "mq", "lr", "ctr", "ap",
160 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
161 "xer"
163 #endif
165 #ifndef MASK_STRICT_ALIGN
166 #define MASK_STRICT_ALIGN 0
167 #endif
169 /* Override command line options. Mostly we process the processor
170 type and sometimes adjust other TARGET_ options. */
172 void
173 rs6000_override_options (default_cpu)
174 const char *default_cpu;
176 size_t i, j;
177 struct rs6000_cpu_select *ptr;
179 /* Simplify the entries below by making a mask for any POWER
180 variant and any PowerPC variant. */
182 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
183 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
184 | MASK_PPC_GFXOPT | MASK_POWERPC64)
185 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
187 static struct ptt
189 const char *name; /* Canonical processor name. */
190 enum processor_type processor; /* Processor type enum value. */
191 int target_enable; /* Target flags to enable. */
192 int target_disable; /* Target flags to disable. */
193 } processor_target_table[]
194 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
195 POWER_MASKS | POWERPC_MASKS},
196 {"power", PROCESSOR_POWER,
197 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
198 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
199 {"power2", PROCESSOR_POWER,
200 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
201 POWERPC_MASKS | MASK_NEW_MNEMONICS},
202 {"power3", PROCESSOR_PPC630,
203 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
204 POWER_MASKS | MASK_PPC_GPOPT},
205 {"powerpc", PROCESSOR_POWERPC,
206 MASK_POWERPC | MASK_NEW_MNEMONICS,
207 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
208 {"powerpc64", PROCESSOR_POWERPC64,
209 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
210 POWER_MASKS | POWERPC_OPT_MASKS},
211 {"rios", PROCESSOR_RIOS1,
212 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
213 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
214 {"rios1", PROCESSOR_RIOS1,
215 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
216 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
217 {"rsc", PROCESSOR_PPC601,
218 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
219 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
220 {"rsc1", PROCESSOR_PPC601,
221 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
222 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
223 {"rios2", PROCESSOR_RIOS2,
224 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
225 POWERPC_MASKS | MASK_NEW_MNEMONICS},
226 {"rs64a", PROCESSOR_RS64A,
227 MASK_POWERPC | MASK_NEW_MNEMONICS,
228 POWER_MASKS | POWERPC_OPT_MASKS},
229 {"401", PROCESSOR_PPC403,
230 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
231 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
232 {"403", PROCESSOR_PPC403,
233 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
234 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
235 {"505", PROCESSOR_MPCCORE,
236 MASK_POWERPC | MASK_NEW_MNEMONICS,
237 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
238 {"601", PROCESSOR_PPC601,
239 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
240 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
241 {"602", PROCESSOR_PPC603,
242 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
243 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
244 {"603", PROCESSOR_PPC603,
245 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
246 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
247 {"603e", PROCESSOR_PPC603,
248 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
249 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
250 {"ec603e", PROCESSOR_PPC603,
251 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
252 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
253 {"604", PROCESSOR_PPC604,
254 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
255 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
256 {"604e", PROCESSOR_PPC604e,
257 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
258 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
259 {"620", PROCESSOR_PPC620,
260 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
261 POWER_MASKS | MASK_PPC_GPOPT},
262 {"630", PROCESSOR_PPC630,
263 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
264 POWER_MASKS | MASK_PPC_GPOPT},
265 {"740", PROCESSOR_PPC750,
266 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
267 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
268 {"750", PROCESSOR_PPC750,
269 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
270 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
271 {"801", PROCESSOR_MPCCORE,
272 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
273 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
274 {"821", PROCESSOR_MPCCORE,
275 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
276 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
277 {"823", PROCESSOR_MPCCORE,
278 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
279 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
280 {"860", PROCESSOR_MPCCORE,
281 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
282 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
284 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
286 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
287 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
289 profile_block_flag = 0;
291 /* Identify the processor type */
292 rs6000_select[0].string = default_cpu;
293 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
295 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
297 ptr = &rs6000_select[i];
298 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
300 for (j = 0; j < ptt_size; j++)
301 if (! strcmp (ptr->string, processor_target_table[j].name))
303 if (ptr->set_tune_p)
304 rs6000_cpu = processor_target_table[j].processor;
306 if (ptr->set_arch_p)
308 target_flags |= processor_target_table[j].target_enable;
309 target_flags &= ~processor_target_table[j].target_disable;
311 break;
314 if (j == ptt_size)
315 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
319 /* If we are optimizing big endian systems for space, use the
320 store multiple instructions. */
321 if (BYTES_BIG_ENDIAN && optimize_size)
322 target_flags |= MASK_MULTIPLE;
324 /* If -mmultiple or -mno-multiple was explicitly used, don't
325 override with the processor default */
326 if (TARGET_MULTIPLE_SET)
327 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
329 /* If -mstring or -mno-string was explicitly used, don't
330 override with the processor default */
331 if (TARGET_STRING_SET)
332 target_flags = (target_flags & ~MASK_STRING) | string;
334 /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu
335 is a 750, because the hardware doesn't support the instructions used in
336 little endian mode, and causes an alignment trap. The 750 does not cause
337 an alignment trap (except when the target is unaligned). */
339 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
341 if (TARGET_MULTIPLE)
343 target_flags &= ~MASK_MULTIPLE;
344 if (TARGET_MULTIPLE_SET)
345 warning ("-mmultiple is not supported on little endian systems");
348 if (TARGET_STRING)
350 target_flags &= ~MASK_STRING;
351 if (TARGET_STRING_SET)
352 warning ("-mstring is not supported on little endian systems");
356 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
358 warning ("-f%s ignored for AIX (all code is position independent)",
359 (flag_pic > 1) ? "PIC" : "pic");
360 flag_pic = 0;
363 /* Set debug flags */
364 if (rs6000_debug_name)
366 if (! strcmp (rs6000_debug_name, "all"))
367 rs6000_debug_stack = rs6000_debug_arg = 1;
368 else if (! strcmp (rs6000_debug_name, "stack"))
369 rs6000_debug_stack = 1;
370 else if (! strcmp (rs6000_debug_name, "arg"))
371 rs6000_debug_arg = 1;
372 else
373 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
376 #ifdef TARGET_REGNAMES
377 /* If the user desires alternate register names, copy in the alternate names
378 now. */
379 if (TARGET_REGNAMES)
380 bcopy ((char *)alt_reg_names, (char *)rs6000_reg_names,
381 sizeof (rs6000_reg_names));
382 #endif
384 #ifdef SUBTARGET_OVERRIDE_OPTIONS
385 SUBTARGET_OVERRIDE_OPTIONS;
386 #endif
388 /* Register global variables with the garbage collector. */
389 rs6000_add_gc_roots ();
391 /* Allocate an alias set for register saves & restores from stack. */
392 rs6000_sr_alias_set = new_alias_set ();
394 if (TARGET_TOC)
395 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
398 void
399 optimization_options (level, size)
400 int level;
401 int size ATTRIBUTE_UNUSED;
403 #ifdef HAVE_decrement_and_branch_on_count
404 /* When optimizing, enable use of BCT instruction. */
405 if (level >= 1)
406 flag_branch_on_count_reg = 1;
407 #endif
410 /* Do anything needed at the start of the asm file. */
412 void
413 rs6000_file_start (file, default_cpu)
414 FILE *file;
415 const char *default_cpu;
417 size_t i;
418 char buffer[80];
419 const char *start = buffer;
420 struct rs6000_cpu_select *ptr;
422 if (flag_verbose_asm)
424 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
425 rs6000_select[0].string = default_cpu;
427 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
429 ptr = &rs6000_select[i];
430 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
432 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
433 start = "";
437 #ifdef USING_SVR4_H
438 switch (rs6000_sdata)
440 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
441 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
442 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
443 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
446 if (rs6000_sdata && g_switch_value)
448 fprintf (file, "%s -G %d", start, g_switch_value);
449 start = "";
451 #endif
453 if (*start == '\0')
454 putc ('\n', file);
459 /* Create a CONST_DOUBLE from a string. */
461 struct rtx_def *
462 rs6000_float_const (string, mode)
463 const char *string;
464 enum machine_mode mode;
466 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
467 return immed_real_const_1 (value, mode);
470 /* Return non-zero if this function is known to have a null epilogue. */
473 direct_return ()
475 if (reload_completed)
477 rs6000_stack_t *info = rs6000_stack_info ();
479 if (info->first_gp_reg_save == 32
480 && info->first_fp_reg_save == 64
481 && ! info->lr_save_p
482 && ! info->cr_save_p
483 && ! info->push_p)
484 return 1;
487 return 0;
490 /* Returns 1 always. */
493 any_operand (op, mode)
494 register rtx op ATTRIBUTE_UNUSED;
495 enum machine_mode mode ATTRIBUTE_UNUSED;
497 return 1;
500 /* Returns 1 if op is the count register */
502 count_register_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 (REGNO (op) == COUNT_REGISTER_REGNUM)
510 return 1;
512 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
513 return 1;
515 return 0;
519 xer_operand(op, mode)
520 register rtx op;
521 enum machine_mode mode ATTRIBUTE_UNUSED;
523 if (GET_CODE (op) != REG)
524 return 0;
526 if (XER_REGNO_P (REGNO (op)))
527 return 1;
529 return 0;
532 /* Return 1 if OP is a constant that can fit in a D field. */
535 short_cint_operand (op, mode)
536 register rtx op;
537 enum machine_mode mode ATTRIBUTE_UNUSED;
539 return (GET_CODE (op) == CONST_INT
540 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
543 /* Similar for a unsigned D field. */
546 u_short_cint_operand (op, mode)
547 register rtx op;
548 enum machine_mode mode ATTRIBUTE_UNUSED;
550 return (GET_CODE (op) == CONST_INT
551 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
554 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
557 non_short_cint_operand (op, mode)
558 register rtx op;
559 enum machine_mode mode ATTRIBUTE_UNUSED;
561 return (GET_CODE (op) == CONST_INT
562 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
565 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
566 ctr, or lr). */
569 gpc_reg_operand (op, mode)
570 register rtx op;
571 enum machine_mode mode;
573 return (register_operand (op, mode)
574 && (GET_CODE (op) != REG
575 || (REGNO (op) >= ARG_POINTER_REGNUM
576 && !XER_REGNO_P (REGNO (op)))
577 || REGNO (op) < MQ_REGNO));
580 /* Returns 1 if OP is either a pseudo-register or a register denoting a
581 CR field. */
584 cc_reg_operand (op, mode)
585 register rtx op;
586 enum machine_mode mode;
588 return (register_operand (op, mode)
589 && (GET_CODE (op) != REG
590 || REGNO (op) >= FIRST_PSEUDO_REGISTER
591 || CR_REGNO_P (REGNO (op))));
594 /* Returns 1 if OP is either a pseudo-register or a register denoting a
595 CR field that isn't CR0. */
598 cc_reg_not_cr0_operand (op, mode)
599 register rtx op;
600 enum machine_mode mode;
602 return (register_operand (op, mode)
603 && (GET_CODE (op) != REG
604 || REGNO (op) >= FIRST_PSEUDO_REGISTER
605 || CR_REGNO_NOT_CR0_P (REGNO (op))));
608 /* Returns 1 if OP is either a constant integer valid for a D-field or a
609 non-special register. If a register, it must be in the proper mode unless
610 MODE is VOIDmode. */
613 reg_or_short_operand (op, mode)
614 register rtx op;
615 enum machine_mode mode;
617 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
620 /* Similar, except check if the negation of the constant would be valid for
621 a D-field. */
624 reg_or_neg_short_operand (op, mode)
625 register rtx op;
626 enum machine_mode mode;
628 if (GET_CODE (op) == CONST_INT)
629 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
631 return gpc_reg_operand (op, mode);
634 /* Return 1 if the operand is either a register or an integer whose high-order
635 16 bits are zero. */
638 reg_or_u_short_operand (op, mode)
639 register rtx op;
640 enum machine_mode mode;
642 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
645 /* Return 1 is the operand is either a non-special register or ANY
646 constant integer. */
649 reg_or_cint_operand (op, mode)
650 register rtx op;
651 enum machine_mode mode;
653 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
656 /* Return 1 is the operand is either a non-special register or ANY
657 32-bit signed constant integer. */
660 reg_or_arith_cint_operand (op, mode)
661 register rtx op;
662 enum machine_mode mode;
664 return (gpc_reg_operand (op, mode)
665 || (GET_CODE (op) == CONST_INT
666 #if HOST_BITS_PER_WIDE_INT != 32
667 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
668 < 0x100000000u)
669 #endif
673 /* Return 1 is the operand is either a non-special register or ANY
674 32-bit unsigned constant integer. */
677 reg_or_logical_cint_operand (op, mode)
678 register rtx op;
679 enum machine_mode mode;
681 if (GET_CODE (op) == CONST_INT)
683 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
685 if (GET_MODE_BITSIZE (mode) <= 32)
686 abort();
688 if (INTVAL (op) < 0)
689 return 0;
692 return ((INTVAL (op) & GET_MODE_MASK (mode)
693 & (~ (unsigned HOST_WIDE_INT) 0xffffffffu)) == 0);
695 else if (GET_CODE (op) == CONST_DOUBLE)
697 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
698 || mode != DImode)
699 abort();
701 return CONST_DOUBLE_HIGH (op) == 0;
703 else
704 return gpc_reg_operand (op, mode);
707 /* Return 1 if the operand is an operand that can be loaded via the GOT */
710 got_operand (op, mode)
711 register rtx op;
712 enum machine_mode mode ATTRIBUTE_UNUSED;
714 return (GET_CODE (op) == SYMBOL_REF
715 || GET_CODE (op) == CONST
716 || GET_CODE (op) == LABEL_REF);
719 /* Return 1 if the operand is a simple references that can be loaded via
720 the GOT (labels involving addition aren't allowed). */
723 got_no_const_operand (op, mode)
724 register rtx op;
725 enum machine_mode mode ATTRIBUTE_UNUSED;
727 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
730 /* Return the number of instructions it takes to form a constant in an
731 integer register. */
733 static int
734 num_insns_constant_wide (value)
735 HOST_WIDE_INT value;
737 /* signed constant loadable with {cal|addi} */
738 if (CONST_OK_FOR_LETTER_P (value, 'I'))
739 return 1;
741 /* constant loadable with {cau|addis} */
742 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
743 return 1;
745 #if HOST_BITS_PER_WIDE_INT == 64
746 else if (TARGET_POWERPC64)
748 unsigned HOST_WIDE_INT low = value & 0xffffffffu;
749 HOST_WIDE_INT high = value >> 32;
751 if (high == 0 && (low & 0x80000000u) == 0)
752 return 2;
754 else if (high == -1 && (low & 0x80000000u) != 0)
755 return 2;
757 else if (! low)
758 return num_insns_constant_wide (high) + 1;
760 else
761 return (num_insns_constant_wide (high)
762 + num_insns_constant_wide (low) + 1);
764 #endif
766 else
767 return 2;
771 num_insns_constant (op, mode)
772 rtx op;
773 enum machine_mode mode;
775 if (GET_CODE (op) == CONST_INT)
776 return num_insns_constant_wide (INTVAL (op));
778 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
780 long l;
781 REAL_VALUE_TYPE rv;
783 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
784 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
785 return num_insns_constant_wide ((HOST_WIDE_INT)l);
788 else if (GET_CODE (op) == CONST_DOUBLE)
790 HOST_WIDE_INT low;
791 HOST_WIDE_INT high;
792 long l[2];
793 REAL_VALUE_TYPE rv;
794 int endian = (WORDS_BIG_ENDIAN == 0);
796 if (mode == VOIDmode || mode == DImode)
798 high = CONST_DOUBLE_HIGH (op);
799 low = CONST_DOUBLE_LOW (op);
801 else
803 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
804 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
805 high = l[endian];
806 low = l[1 - endian];
809 if (TARGET_32BIT)
810 return (num_insns_constant_wide (low)
811 + num_insns_constant_wide (high));
813 else
815 if (high == 0 && (low & 0x80000000u) == 0)
816 return num_insns_constant_wide (low);
818 else if (high == -1 && (low & 0x80000000u) != 0)
819 return num_insns_constant_wide (low);
821 else if (mask64_operand (op, mode))
822 return 2;
824 else if (low == 0)
825 return num_insns_constant_wide (high) + 1;
827 else
828 return (num_insns_constant_wide (high)
829 + num_insns_constant_wide (low) + 1);
833 else
834 abort ();
837 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
838 with one instruction per word. We only do this if we can safely read
839 CONST_DOUBLE_{LOW,HIGH}. */
842 easy_fp_constant (op, mode)
843 register rtx op;
844 register enum machine_mode mode;
846 if (GET_CODE (op) != CONST_DOUBLE
847 || GET_MODE (op) != mode
848 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
849 return 0;
851 /* Consider all constants with -msoft-float to be easy */
852 if (TARGET_SOFT_FLOAT && mode != DImode)
853 return 1;
855 /* If we are using V.4 style PIC, consider all constants to be hard */
856 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
857 return 0;
859 #ifdef TARGET_RELOCATABLE
860 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
861 if (TARGET_RELOCATABLE)
862 return 0;
863 #endif
865 if (mode == DFmode)
867 long k[2];
868 REAL_VALUE_TYPE rv;
870 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
871 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
873 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
874 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
877 else if (mode == SFmode)
879 long l;
880 REAL_VALUE_TYPE rv;
882 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
883 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
885 return num_insns_constant_wide (l) == 1;
888 else if (mode == DImode)
889 return ((TARGET_POWERPC64
890 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
891 || (num_insns_constant (op, DImode) <= 2));
893 else
894 abort ();
897 /* Return 1 if the operand is in volatile memory. Note that during the
898 RTL generation phase, memory_operand does not return TRUE for
899 volatile memory references. So this function allows us to
900 recognize volatile references where its safe. */
903 volatile_mem_operand (op, mode)
904 register rtx op;
905 enum machine_mode mode;
907 if (GET_CODE (op) != MEM)
908 return 0;
910 if (!MEM_VOLATILE_P (op))
911 return 0;
913 if (mode != GET_MODE (op))
914 return 0;
916 if (reload_completed)
917 return memory_operand (op, mode);
919 if (reload_in_progress)
920 return strict_memory_address_p (mode, XEXP (op, 0));
922 return memory_address_p (mode, XEXP (op, 0));
925 /* Return 1 if the operand is an offsettable memory operand. */
928 offsettable_mem_operand (op, mode)
929 register rtx op;
930 enum machine_mode mode;
932 return ((GET_CODE (op) == MEM)
933 && offsettable_address_p (reload_completed || reload_in_progress,
934 mode, XEXP (op, 0)));
937 /* Return 1 if the operand is either an easy FP constant (see above) or
938 memory. */
941 mem_or_easy_const_operand (op, mode)
942 register rtx op;
943 enum machine_mode mode;
945 return memory_operand (op, mode) || easy_fp_constant (op, mode);
948 /* Return 1 if the operand is either a non-special register or an item
949 that can be used as the operand of a `mode' add insn. */
952 add_operand (op, mode)
953 register rtx op;
954 enum machine_mode mode;
956 return (reg_or_short_operand (op, mode)
957 || (GET_CODE (op) == CONST_INT
958 && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')));
961 /* Return 1 if OP is a constant but not a valid add_operand. */
964 non_add_cint_operand (op, mode)
965 register rtx op;
966 enum machine_mode mode ATTRIBUTE_UNUSED;
968 return (GET_CODE (op) == CONST_INT
969 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
970 && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'));
973 /* Return 1 if the operand is a non-special register or a constant that
974 can be used as the operand of an OR or XOR insn on the RS/6000. */
977 logical_operand (op, mode)
978 register rtx op;
979 enum machine_mode mode;
981 /* an unsigned representation of 'op'. */
982 unsigned HOST_WIDE_INT opl, oph;
984 if (gpc_reg_operand (op, mode))
985 return 1;
987 if (GET_CODE (op) == CONST_INT)
989 opl = INTVAL (op) & GET_MODE_MASK (mode);
990 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
991 oph = 0;
992 else
993 oph = INTVAL (op) >> (HOST_BITS_PER_WIDE_INT - 1);
995 else if (GET_CODE (op) == CONST_DOUBLE)
997 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
998 abort();
1000 opl = CONST_DOUBLE_LOW (op);
1001 oph = CONST_DOUBLE_HIGH (op);
1003 else
1004 return 0;
1006 return (oph == 0
1007 && ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1008 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000u) == 0));
1011 /* Return 1 if C is a constant that is not a logical operand (as
1012 above), but could be split into one. */
1015 non_logical_cint_operand (op, mode)
1016 register rtx op;
1017 enum machine_mode mode;
1019 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1020 && ! logical_operand (op, mode)
1021 && reg_or_logical_cint_operand (op, mode));
1024 /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
1025 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1026 Reject all ones and all zeros, since these should have been optimized
1027 away and confuse the making of MB and ME. */
1030 mask_operand (op, mode)
1031 register rtx op;
1032 enum machine_mode mode ATTRIBUTE_UNUSED;
1034 HOST_WIDE_INT c;
1035 int i;
1036 int last_bit_value;
1037 int transitions = 0;
1039 if (GET_CODE (op) != CONST_INT)
1040 return 0;
1042 c = INTVAL (op);
1044 if (c == 0 || c == ~0)
1045 return 0;
1047 last_bit_value = c & 1;
1049 for (i = 1; i < 32; i++)
1050 if (((c >>= 1) & 1) != last_bit_value)
1051 last_bit_value ^= 1, transitions++;
1053 return transitions <= 2;
1056 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1057 It is if there are no more than one 1->0 or 0->1 transitions.
1058 Reject all ones and all zeros, since these should have been optimized
1059 away and confuse the making of MB and ME. */
1062 mask64_operand (op, mode)
1063 register rtx op;
1064 enum machine_mode mode;
1066 if (GET_CODE (op) == CONST_INT)
1068 HOST_WIDE_INT c = INTVAL (op);
1069 int i;
1070 int last_bit_value;
1071 int transitions = 0;
1073 if (c == 0 || c == ~0)
1074 return 0;
1076 last_bit_value = c & 1;
1078 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1079 if (((c >>= 1) & 1) != last_bit_value)
1080 last_bit_value ^= 1, transitions++;
1082 #if HOST_BITS_PER_WIDE_INT == 32
1083 /* Consider CONST_INT sign-extended. */
1084 transitions += (last_bit_value != 1);
1085 #endif
1087 return transitions <= 1;
1089 else if (GET_CODE (op) == CONST_DOUBLE
1090 && (mode == VOIDmode || mode == DImode))
1092 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1093 #if HOST_BITS_PER_WIDE_INT == 32
1094 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1095 #endif
1096 int i;
1097 int last_bit_value;
1098 int transitions = 0;
1100 if ((low == 0
1101 #if HOST_BITS_PER_WIDE_INT == 32
1102 && high == 0
1103 #endif
1105 || (low == ~0
1106 #if HOST_BITS_PER_WIDE_INT == 32
1107 && high == ~0
1108 #endif
1110 return 0;
1112 last_bit_value = low & 1;
1114 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1115 if (((low >>= 1) & 1) != last_bit_value)
1116 last_bit_value ^= 1, transitions++;
1118 #if HOST_BITS_PER_WIDE_INT == 32
1119 if ((high & 1) != last_bit_value)
1120 last_bit_value ^= 1, transitions++;
1122 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1123 if (((high >>= 1) & 1) != last_bit_value)
1124 last_bit_value ^= 1, transitions++;
1125 #endif
1127 return transitions <= 1;
1129 else
1130 return 0;
1133 /* Return 1 if the operand is either a non-special register or a constant
1134 that can be used as the operand of a PowerPC64 logical AND insn. */
1137 and64_operand (op, mode)
1138 register rtx op;
1139 enum machine_mode mode;
1141 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1142 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1144 return (logical_operand (op, mode) || mask64_operand (op, mode));
1147 /* Return 1 if the operand is either a non-special register or a
1148 constant that can be used as the operand of an RS/6000 logical AND insn. */
1151 and_operand (op, mode)
1152 register rtx op;
1153 enum machine_mode mode;
1155 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1156 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1158 return (logical_operand (op, mode) || mask_operand (op, mode));
1161 /* Return 1 if the operand is a general register or memory operand. */
1164 reg_or_mem_operand (op, mode)
1165 register rtx op;
1166 register enum machine_mode mode;
1168 return (gpc_reg_operand (op, mode)
1169 || memory_operand (op, mode)
1170 || volatile_mem_operand (op, mode));
1173 /* Return 1 if the operand is a general register or memory operand without
1174 pre_inc or pre_dec which produces invalid form of PowerPC lwa
1175 instruction. */
1178 lwa_operand (op, mode)
1179 register rtx op;
1180 register enum machine_mode mode;
1182 rtx inner = op;
1184 if (reload_completed && GET_CODE (inner) == SUBREG)
1185 inner = SUBREG_REG (inner);
1187 return gpc_reg_operand (inner, mode)
1188 || (memory_operand (inner, mode)
1189 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1190 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1193 /* Return 1 if the operand, used inside a MEM, is a valid first argument
1194 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1195 forced to lr. */
1198 call_operand (op, mode)
1199 register rtx op;
1200 enum machine_mode mode;
1202 if (mode != VOIDmode && GET_MODE (op) != mode)
1203 return 0;
1205 return (GET_CODE (op) == SYMBOL_REF
1206 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1210 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
1211 this file and the function is not weakly defined. */
1214 current_file_function_operand (op, mode)
1215 register rtx op;
1216 enum machine_mode mode ATTRIBUTE_UNUSED;
1218 return (GET_CODE (op) == SYMBOL_REF
1219 && (SYMBOL_REF_FLAG (op)
1220 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1221 && ! DECL_WEAK (current_function_decl))));
1225 /* Return 1 if this operand is a valid input for a move insn. */
1228 input_operand (op, mode)
1229 register rtx op;
1230 enum machine_mode mode;
1232 /* Memory is always valid. */
1233 if (memory_operand (op, mode))
1234 return 1;
1236 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1237 if (GET_CODE (op) == CONSTANT_P_RTX)
1238 return 1;
1240 /* For floating-point, easy constants are valid. */
1241 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1242 && CONSTANT_P (op)
1243 && easy_fp_constant (op, mode))
1244 return 1;
1246 /* Allow any integer constant. */
1247 if (GET_MODE_CLASS (mode) == MODE_INT
1248 && (GET_CODE (op) == CONST_INT
1249 || GET_CODE (op) == CONST_DOUBLE))
1250 return 1;
1252 /* For floating-point or multi-word mode, the only remaining valid type
1253 is a register. */
1254 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1255 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1256 return register_operand (op, mode);
1258 /* The only cases left are integral modes one word or smaller (we
1259 do not get called for MODE_CC values). These can be in any
1260 register. */
1261 if (register_operand (op, mode))
1262 return 1;
1264 /* A SYMBOL_REF referring to the TOC is valid. */
1265 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
1266 return 1;
1268 /* A constant pool expression (relative to the TOC) is valid */
1269 if (TOC_RELATIVE_EXPR_P (op))
1270 return 1;
1272 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1273 to be valid. */
1274 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1275 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1276 && small_data_operand (op, Pmode))
1277 return 1;
1279 return 0;
1282 /* Return 1 for an operand in small memory on V.4/eabi */
1285 small_data_operand (op, mode)
1286 rtx op ATTRIBUTE_UNUSED;
1287 enum machine_mode mode ATTRIBUTE_UNUSED;
1289 #if TARGET_ELF
1290 rtx sym_ref;
1292 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
1293 return 0;
1295 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1296 return 0;
1298 if (GET_CODE (op) == SYMBOL_REF)
1299 sym_ref = op;
1301 else if (GET_CODE (op) != CONST
1302 || GET_CODE (XEXP (op, 0)) != PLUS
1303 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1304 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
1305 return 0;
1307 else
1309 rtx sum = XEXP (op, 0);
1310 HOST_WIDE_INT summand;
1312 /* We have to be careful here, because it is the referenced address
1313 that must be 32k from _SDA_BASE_, not just the symbol. */
1314 summand = INTVAL (XEXP (sum, 1));
1315 if (summand < 0 || summand > g_switch_value)
1316 return 0;
1318 sym_ref = XEXP (sum, 0);
1321 if (*XSTR (sym_ref, 0) != '@')
1322 return 0;
1324 return 1;
1326 #else
1327 return 0;
1328 #endif
1331 static int
1332 constant_pool_expr_1 (op, have_sym, have_toc)
1333 rtx op;
1334 int *have_sym;
1335 int *have_toc;
1337 switch (GET_CODE(op))
1339 case SYMBOL_REF:
1340 if (CONSTANT_POOL_ADDRESS_P (op))
1342 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op)))
1344 *have_sym = 1;
1345 return 1;
1347 else
1348 return 0;
1350 else if (! strcmp (XSTR (op, 0), toc_label_name))
1352 *have_toc = 1;
1353 return 1;
1355 else
1356 return 0;
1357 case PLUS:
1358 case MINUS:
1359 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) &&
1360 constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc);
1361 case CONST:
1362 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
1363 case CONST_INT:
1364 return 1;
1365 default:
1366 return 0;
1371 constant_pool_expr_p (op)
1372 rtx op;
1374 int have_sym = 0;
1375 int have_toc = 0;
1376 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
1380 toc_relative_expr_p (op)
1381 rtx op;
1383 int have_sym = 0;
1384 int have_toc = 0;
1385 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
1388 /* Try machine-dependent ways of modifying an illegitimate address
1389 to be legitimate. If we find one, return the new, valid address.
1390 This is used from only one place: `memory_address' in explow.c.
1392 OLDX is the address as it was before break_out_memory_refs was called.
1393 In some cases it is useful to look at this to decide what needs to be done.
1395 MODE is passed so that this macro can use GO_IF_LEGITIMATE_ADDRESS.
1397 It is always safe for this macro to do nothing. It exists to recognize
1398 opportunities to optimize the output.
1400 On RS/6000, first check for the sum of a register with a constant
1401 integer that is out of range. If so, generate code to add the
1402 constant with the low-order 16 bits masked to the register and force
1403 this result into another register (this can be done with `cau').
1404 Then generate an address of REG+(CONST&0xffff), allowing for the
1405 possibility of bit 16 being a one.
1407 Then check for the sum of a register and something not constant, try to
1408 load the other things into a register and return the sum. */
1410 rs6000_legitimize_address (x, oldx, mode)
1411 rtx x;
1412 rtx oldx ATTRIBUTE_UNUSED;
1413 enum machine_mode mode;
1415 if (GET_CODE (x) == PLUS
1416 && GET_CODE (XEXP (x, 0)) == REG
1417 && GET_CODE (XEXP (x, 1)) == CONST_INT
1418 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
1420 HOST_WIDE_INT high_int, low_int;
1421 rtx sum;
1422 high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff);
1423 low_int = INTVAL (XEXP (x, 1)) & 0xffff;
1424 if (low_int & 0x8000)
1425 high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
1426 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
1427 GEN_INT (high_int)), 0);
1428 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
1430 else if (GET_CODE (x) == PLUS
1431 && GET_CODE (XEXP (x, 0)) == REG
1432 && GET_CODE (XEXP (x, 1)) != CONST_INT
1433 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1434 && (TARGET_POWERPC64 || mode != DImode)
1435 && mode != TImode)
1437 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
1438 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
1440 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
1441 && GET_CODE (x) != CONST_INT
1442 && GET_CODE (x) != CONST_DOUBLE
1443 && CONSTANT_P (x)
1444 && (TARGET_HARD_FLOAT || mode != DFmode)
1445 && mode != DImode
1446 && mode != TImode)
1448 rtx reg = gen_reg_rtx (Pmode);
1449 emit_insn (gen_elf_high (reg, (x)));
1450 return gen_rtx_LO_SUM (Pmode, reg, (x));
1452 else if (TARGET_TOC
1453 && CONSTANT_POOL_EXPR_P (x)
1454 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x)))
1456 return create_TOC_reference (x);
1458 else
1459 return NULL_RTX;
1462 /* Emit a move from SOURCE to DEST in mode MODE. */
1463 void
1464 rs6000_emit_move (dest, source, mode)
1465 rtx dest;
1466 rtx source;
1467 enum machine_mode mode;
1469 rtx operands[2];
1470 operands[0] = dest;
1471 operands[1] = source;
1473 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
1474 if (GET_CODE (operands[1]) == CONST_DOUBLE
1475 && ! FLOAT_MODE_P (mode)
1476 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1478 /* FIXME. This should never happen. */
1479 /* Since it seems that it does, do the safe thing and convert
1480 to a CONST_INT. */
1481 operands[1] =
1482 GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode));
1484 if (GET_CODE (operands[1]) == CONST_DOUBLE
1485 && ! FLOAT_MODE_P (mode)
1486 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
1487 && CONST_DOUBLE_LOW (operands[1]) >= 0)
1488 || (CONST_DOUBLE_HIGH (operands[1]) == -1
1489 && CONST_DOUBLE_LOW (operands[1]) < 0)))
1490 abort ();
1492 if (! no_new_pseudos && GET_CODE (operands[0]) != REG)
1493 operands[1] = force_reg (mode, operands[1]);
1495 if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT
1496 && GET_CODE (operands[0]) == MEM)
1498 int regnum;
1500 if (reload_in_progress || reload_completed)
1501 regnum = true_regnum (operands[1]);
1502 else if (GET_CODE (operands[1]) == REG)
1503 regnum = REGNO (operands[1]);
1504 else
1505 regnum = -1;
1507 /* If operands[1] is a register, on POWER it may have
1508 double-precision data in it, so truncate it to single
1509 precision. */
1510 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
1512 rtx newreg;
1513 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
1514 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
1515 operands[1] = newreg;
1519 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1520 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
1522 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1523 return;
1526 /* FIXME: In the long term, this switch statement should go away
1527 and be replaced by a sequence of tests based on things like
1528 mode == Pmode. */
1529 switch (mode)
1531 case HImode:
1532 case QImode:
1533 if (CONSTANT_P (operands[1])
1534 && GET_CODE (operands[1]) != CONST_INT)
1536 operands[1] = force_const_mem (mode, operands[1]);
1537 if (! memory_address_p (mode, XEXP (operands[1], 0))
1538 && ! reload_in_progress)
1539 operands[1] = change_address (operands[1], mode,
1540 XEXP (operands[1], 0));
1542 break;
1544 case DFmode:
1545 case SFmode:
1546 if (CONSTANT_P (operands[1])
1547 && ! easy_fp_constant (operands[1], mode))
1549 operands[1] = force_const_mem (mode, operands[1]);
1550 if (! memory_address_p (mode, XEXP (operands[1], 0))
1551 && ! reload_in_progress)
1552 operands[1] = change_address (operands[1], mode,
1553 XEXP (operands[1], 0));
1555 break;
1557 case SImode:
1558 /* Use default pattern for address of ELF small data */
1559 if (TARGET_ELF
1560 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1561 && (GET_CODE (operands[1]) == SYMBOL_REF || GET_CODE (operands[1]) == CONST)
1562 && small_data_operand (operands[1], SImode))
1564 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1565 return;
1568 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1569 && flag_pic == 1 && got_operand (operands[1], SImode))
1571 emit_insn (gen_movsi_got (operands[0], operands[1]));
1572 return;
1575 if (TARGET_ELF && TARGET_NO_TOC && ! TARGET_64BIT
1576 && ! flag_pic
1577 && CONSTANT_P (operands[1])
1578 && GET_CODE (operands[1]) != HIGH
1579 && GET_CODE (operands[1]) != CONST_INT)
1581 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (SImode));
1583 /* If this is a function address on -mcall-aixdesc,
1584 convert it to the address of the descriptor. */
1585 if (DEFAULT_ABI == ABI_AIX
1586 && GET_CODE (operands[1]) == SYMBOL_REF
1587 && XSTR (operands[1], 0)[0] == '.')
1589 const char *name = XSTR (operands[1], 0);
1590 rtx new_ref;
1591 while (*name == '.')
1592 name++;
1593 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
1594 CONSTANT_POOL_ADDRESS_P (new_ref)
1595 = CONSTANT_POOL_ADDRESS_P (operands[1]);
1596 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
1597 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
1598 operands[1] = new_ref;
1601 emit_insn (gen_elf_high (target, operands[1]));
1602 emit_insn (gen_elf_low (operands[0], target, operands[1]));
1603 return;
1606 if (CONSTANT_P (operands[1])
1607 && GET_CODE (operands[1]) != CONST_INT
1608 && GET_CODE (operands[1]) != HIGH
1609 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
1610 && ! TOC_RELATIVE_EXPR_P (operands[1]))
1612 /* Emit a USE operation so that the constant isn't deleted if
1613 expensive optimizations are turned on because nobody
1614 references it. This should only be done for operands that
1615 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
1616 This should not be done for operands that contain LABEL_REFs.
1617 For now, we just handle the obvious case. */
1618 if (GET_CODE (operands[1]) != LABEL_REF)
1619 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
1621 /* If we are to limit the number of things we put in the TOC and
1622 this is a symbol plus a constant we can add in one insn,
1623 just put the symbol in the TOC and add the constant. Don't do
1624 this if reload is in progress. */
1625 if (GET_CODE (operands[1]) == CONST
1626 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
1627 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1628 && add_operand (XEXP (XEXP (operands[1], 0), 1), SImode)
1629 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
1630 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
1631 && ! side_effects_p (operands[0]))
1633 rtx sym = force_const_mem (SImode, XEXP (XEXP (operands[1], 0), 0));
1634 rtx other = XEXP (XEXP (operands[1], 0), 1);
1636 emit_insn (gen_addsi3 (operands[0], force_reg (SImode, sym), other));
1637 return;
1640 operands[1] = force_const_mem (SImode, operands[1]);
1642 if (TARGET_TOC
1643 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
1644 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (
1645 XEXP (operands[1], 0))))
1647 operands[1] = gen_rtx_MEM (SImode,
1648 create_TOC_reference (XEXP (operands[1], 0)));
1649 MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set ();
1650 RTX_UNCHANGING_P (operands[1]) = 1;
1653 if (! memory_address_p (SImode, XEXP (operands[1], 0))
1654 && ! reload_in_progress)
1655 operands[1] = change_address (operands[1], SImode,
1656 XEXP (operands[1], 0));
1658 break;
1660 case DImode:
1661 if (TARGET_64BIT
1662 && CONSTANT_P (operands[1])
1663 #if HOST_BITS_PER_WIDE_INT == 32
1664 && GET_CODE (operands[1]) != CONST_INT
1665 #endif
1666 && ! easy_fp_constant (operands[1], DImode)
1667 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
1668 && ! TOC_RELATIVE_EXPR_P (operands[1]))
1670 /* Emit a USE operation so that the constant isn't deleted if
1671 expensive optimizations are turned on because nobody
1672 references it. This should only be done for operands that
1673 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
1674 This should not be done for operands that contain LABEL_REFs.
1675 For now, we just handle the obvious case. */
1676 if (GET_CODE (operands[1]) != LABEL_REF)
1677 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
1679 /* If we are to limit the number of things we put in the TOC and
1680 this is a symbol plus a constant we can add in one insn,
1681 just put the symbol in the TOC and add the constant. Don't do
1682 this if reload is in progress. */
1683 if (GET_CODE (operands[1]) == CONST
1684 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
1685 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1686 && add_operand (XEXP (XEXP (operands[1], 0), 1), DImode)
1687 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
1688 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
1689 && ! side_effects_p (operands[0]))
1691 rtx sym = force_const_mem (DImode, XEXP (XEXP (operands[1], 0), 0));
1692 rtx other = XEXP (XEXP (operands[1], 0), 1);
1694 emit_insn (gen_adddi3 (operands[0], force_reg (DImode, sym), other));
1695 return;
1698 operands[1] = force_const_mem (DImode, operands[1]);
1700 if (TARGET_TOC
1701 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
1702 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (
1703 XEXP (operands[1], 0))))
1705 operands[1] = gen_rtx_MEM (DImode,
1706 create_TOC_reference (XEXP (operands[1], 0)));
1708 MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set ();
1709 RTX_UNCHANGING_P (operands[1]) = 1;
1712 if (! memory_address_p (DImode, XEXP (operands[1], 0))
1713 && ! reload_in_progress)
1714 operands[1] = change_address (operands[1], DImode,
1715 XEXP (operands[1], 0));
1717 break;
1719 case TImode:
1720 if (GET_CODE (operands[0]) == MEM
1721 && GET_CODE (XEXP (operands[0], 0)) != REG
1722 && ! reload_in_progress)
1723 operands[0] = change_address (operands[0], TImode,
1724 copy_addr_to_reg (XEXP (operands[0], 0)));
1726 if (GET_CODE (operands[1]) == MEM
1727 && GET_CODE (XEXP (operands[1], 0)) != REG
1728 && ! reload_in_progress)
1729 operands[1] = change_address (operands[1], TImode,
1730 copy_addr_to_reg (XEXP (operands[1], 0)));
1731 break;
1733 default:
1734 abort ();
1737 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1740 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1741 for a call to a function whose data type is FNTYPE.
1742 For a library call, FNTYPE is 0.
1744 For incoming args we set the number of arguments in the prototype large
1745 so we never return a PARALLEL. */
1747 void
1748 init_cumulative_args (cum, fntype, libname, incoming)
1749 CUMULATIVE_ARGS *cum;
1750 tree fntype;
1751 rtx libname ATTRIBUTE_UNUSED;
1752 int incoming;
1754 static CUMULATIVE_ARGS zero_cumulative;
1756 *cum = zero_cumulative;
1757 cum->words = 0;
1758 cum->fregno = FP_ARG_MIN_REG;
1759 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
1760 cum->call_cookie = CALL_NORMAL;
1761 cum->sysv_gregno = GP_ARG_MIN_REG;
1763 if (incoming)
1764 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
1766 else if (cum->prototype)
1767 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1768 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1769 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1771 else
1772 cum->nargs_prototype = 0;
1774 cum->orig_nargs = cum->nargs_prototype;
1776 /* Check for longcall's */
1777 if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1778 cum->call_cookie = CALL_LONG;
1780 if (TARGET_DEBUG_ARG)
1782 fprintf (stderr, "\ninit_cumulative_args:");
1783 if (fntype)
1785 tree ret_type = TREE_TYPE (fntype);
1786 fprintf (stderr, " ret code = %s,",
1787 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1790 if (cum->call_cookie & CALL_LONG)
1791 fprintf (stderr, " longcall,");
1793 fprintf (stderr, " proto = %d, nargs = %d\n",
1794 cum->prototype, cum->nargs_prototype);
1798 /* If defined, a C expression which determines whether, and in which
1799 direction, to pad out an argument with extra space. The value
1800 should be of type `enum direction': either `upward' to pad above
1801 the argument, `downward' to pad below, or `none' to inhibit
1802 padding.
1804 For the AIX ABI structs are always stored left shifted in their
1805 argument slot. */
1807 enum direction
1808 function_arg_padding (mode, type)
1809 enum machine_mode mode;
1810 tree type;
1812 if (type != 0 && AGGREGATE_TYPE_P (type))
1813 return upward;
1815 /* This is the default definition. */
1816 return (! BYTES_BIG_ENDIAN
1817 ? upward
1818 : ((mode == BLKmode
1819 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1820 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1821 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
1822 ? downward : upward));
1825 /* If defined, a C expression that gives the alignment boundary, in bits,
1826 of an argument with the specified mode and type. If it is not defined,
1827 PARM_BOUNDARY is used for all arguments.
1829 V.4 wants long longs to be double word aligned. */
1832 function_arg_boundary (mode, type)
1833 enum machine_mode mode;
1834 tree type ATTRIBUTE_UNUSED;
1836 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1837 && (mode == DImode || mode == DFmode))
1838 return 64;
1839 else
1840 return PARM_BOUNDARY;
1843 /* Update the data in CUM to advance over an argument
1844 of mode MODE and data type TYPE.
1845 (TYPE is null for libcalls where that information may not be available.) */
1847 void
1848 function_arg_advance (cum, mode, type, named)
1849 CUMULATIVE_ARGS *cum;
1850 enum machine_mode mode;
1851 tree type;
1852 int named;
1854 cum->nargs_prototype--;
1856 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1858 if (TARGET_HARD_FLOAT
1859 && (mode == SFmode || mode == DFmode))
1861 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1862 cum->fregno++;
1863 else
1865 if (mode == DFmode)
1866 cum->words += cum->words & 1;
1867 cum->words += RS6000_ARG_SIZE (mode, type, 1);
1870 else
1872 int n_words;
1873 int gregno = cum->sysv_gregno;
1875 /* Aggregates and IEEE quad get passed by reference. */
1876 if ((type && AGGREGATE_TYPE_P (type))
1877 || mode == TFmode)
1878 n_words = 1;
1879 else
1880 n_words = RS6000_ARG_SIZE (mode, type, 1);
1882 /* Long long is put in odd registers. */
1883 if (n_words == 2 && (gregno & 1) == 0)
1884 gregno += 1;
1886 /* Long long is not split between registers and stack. */
1887 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
1889 /* Long long is aligned on the stack. */
1890 if (n_words == 2)
1891 cum->words += cum->words & 1;
1892 cum->words += n_words;
1895 /* Note: continuing to accumulate gregno past when we've started
1896 spilling to the stack indicates the fact that we've started
1897 spilling to the stack to expand_builtin_saveregs. */
1898 cum->sysv_gregno = gregno + n_words;
1901 if (TARGET_DEBUG_ARG)
1903 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1904 cum->words, cum->fregno);
1905 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
1906 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
1907 fprintf (stderr, "mode = %4s, named = %d\n",
1908 GET_MODE_NAME (mode), named);
1911 else
1913 int align = (TARGET_32BIT && (cum->words & 1) != 0
1914 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1915 cum->words += align;
1917 if (named)
1919 cum->words += RS6000_ARG_SIZE (mode, type, named);
1920 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
1921 cum->fregno++;
1924 if (TARGET_DEBUG_ARG)
1926 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1927 cum->words, cum->fregno);
1928 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
1929 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
1930 fprintf (stderr, "named = %d, align = %d\n", named, align);
1935 /* Determine where to put an argument to a function.
1936 Value is zero to push the argument on the stack,
1937 or a hard register in which to store the argument.
1939 MODE is the argument's machine mode.
1940 TYPE is the data type of the argument (as a tree).
1941 This is null for libcalls where that information may
1942 not be available.
1943 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1944 the preceding args and about the function being called.
1945 NAMED is nonzero if this argument is a named parameter
1946 (otherwise it is an extra parameter matching an ellipsis).
1948 On RS/6000 the first eight words of non-FP are normally in registers
1949 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
1950 Under V.4, the first 8 FP args are in registers.
1952 If this is floating-point and no prototype is specified, we use
1953 both an FP and integer register (or possibly FP reg and stack). Library
1954 functions (when TYPE is zero) always have the proper types for args,
1955 so we can pass the FP value just in one register. emit_library_function
1956 doesn't support PARALLEL anyway. */
1958 struct rtx_def *
1959 function_arg (cum, mode, type, named)
1960 CUMULATIVE_ARGS *cum;
1961 enum machine_mode mode;
1962 tree type;
1963 int named;
1965 enum rs6000_abi abi = DEFAULT_ABI;
1967 /* Return a marker to indicate whether CR1 needs to set or clear the bit
1968 that V.4 uses to say fp args were passed in registers. Assume that we
1969 don't need the marker for software floating point, or compiler generated
1970 library calls. */
1971 if (mode == VOIDmode)
1973 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
1974 && TARGET_HARD_FLOAT
1975 && cum->nargs_prototype < 0
1976 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
1978 return GEN_INT (cum->call_cookie
1979 | ((cum->fregno == FP_ARG_MIN_REG)
1980 ? CALL_V4_SET_FP_ARGS
1981 : CALL_V4_CLEAR_FP_ARGS));
1984 return GEN_INT (cum->call_cookie);
1987 if (abi == ABI_V4 || abi == ABI_SOLARIS)
1989 if (TARGET_HARD_FLOAT
1990 && (mode == SFmode || mode == DFmode))
1992 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1993 return gen_rtx_REG (mode, cum->fregno);
1994 else
1995 return NULL;
1997 else
1999 int n_words;
2000 int gregno = cum->sysv_gregno;
2002 /* Aggregates and IEEE quad get passed by reference. */
2003 if ((type && AGGREGATE_TYPE_P (type))
2004 || mode == TFmode)
2005 n_words = 1;
2006 else
2007 n_words = RS6000_ARG_SIZE (mode, type, 1);
2009 /* Long long is put in odd registers. */
2010 if (n_words == 2 && (gregno & 1) == 0)
2011 gregno += 1;
2013 /* Long long is not split between registers and stack. */
2014 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
2015 return gen_rtx_REG (mode, gregno);
2016 else
2017 return NULL;
2020 else
2022 int align = (TARGET_32BIT && (cum->words & 1) != 0
2023 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2024 int align_words = cum->words + align;
2026 if (! named)
2027 return NULL_RTX;
2029 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2030 return NULL_RTX;
2032 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2034 if (! type
2035 || ((cum->nargs_prototype > 0)
2036 /* IBM AIX extended its linkage convention definition always
2037 to require FP args after register save area hole on the
2038 stack. */
2039 && (DEFAULT_ABI != ABI_AIX
2040 || ! TARGET_XL_CALL
2041 || (align_words < GP_ARG_NUM_REG))))
2042 return gen_rtx_REG (mode, cum->fregno);
2044 return gen_rtx_PARALLEL (mode,
2045 gen_rtvec (2,
2046 gen_rtx_EXPR_LIST (VOIDmode,
2047 ((align_words >= GP_ARG_NUM_REG)
2048 ? NULL_RTX
2049 : (align_words
2050 + RS6000_ARG_SIZE (mode, type, named)
2051 > GP_ARG_NUM_REG
2052 /* If this is partially on the stack, then
2053 we only include the portion actually
2054 in registers here. */
2055 ? gen_rtx_REG (SImode,
2056 GP_ARG_MIN_REG + align_words)
2057 : gen_rtx_REG (mode,
2058 GP_ARG_MIN_REG + align_words))),
2059 const0_rtx),
2060 gen_rtx_EXPR_LIST (VOIDmode,
2061 gen_rtx_REG (mode, cum->fregno),
2062 const0_rtx)));
2064 else if (align_words < GP_ARG_NUM_REG)
2065 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
2066 else
2067 return NULL_RTX;
2071 /* For an arg passed partly in registers and partly in memory,
2072 this is the number of registers used.
2073 For args passed entirely in registers or entirely in memory, zero. */
2076 function_arg_partial_nregs (cum, mode, type, named)
2077 CUMULATIVE_ARGS *cum;
2078 enum machine_mode mode;
2079 tree type;
2080 int named;
2082 if (! named)
2083 return 0;
2085 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2086 return 0;
2088 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2090 if (cum->nargs_prototype >= 0)
2091 return 0;
2094 if (cum->words < GP_ARG_NUM_REG
2095 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
2097 int ret = GP_ARG_NUM_REG - cum->words;
2098 if (ret && TARGET_DEBUG_ARG)
2099 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2101 return ret;
2104 return 0;
2107 /* A C expression that indicates when an argument must be passed by
2108 reference. If nonzero for an argument, a copy of that argument is
2109 made in memory and a pointer to the argument is passed instead of
2110 the argument itself. The pointer is passed in whatever way is
2111 appropriate for passing a pointer to that type.
2113 Under V.4, structures and unions are passed by reference. */
2116 function_arg_pass_by_reference (cum, mode, type, named)
2117 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2118 enum machine_mode mode ATTRIBUTE_UNUSED;
2119 tree type;
2120 int named ATTRIBUTE_UNUSED;
2122 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2123 && ((type && AGGREGATE_TYPE_P (type))
2124 || mode == TFmode))
2126 if (TARGET_DEBUG_ARG)
2127 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
2129 return 1;
2132 return 0;
2135 /* Perform any needed actions needed for a function that is receiving a
2136 variable number of arguments.
2138 CUM is as above.
2140 MODE and TYPE are the mode and type of the current parameter.
2142 PRETEND_SIZE is a variable that should be set to the amount of stack
2143 that must be pushed by the prolog to pretend that our caller pushed
2146 Normally, this macro will push all remaining incoming registers on the
2147 stack and set PRETEND_SIZE to the length of the registers pushed. */
2149 void
2150 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2151 CUMULATIVE_ARGS *cum;
2152 enum machine_mode mode;
2153 tree type;
2154 int *pretend_size;
2155 int no_rtl;
2158 CUMULATIVE_ARGS next_cum;
2159 int reg_size = TARGET_32BIT ? 4 : 8;
2160 rtx save_area, mem;
2161 int first_reg_offset, set;
2163 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2165 tree fntype;
2166 int stdarg_p;
2168 fntype = TREE_TYPE (current_function_decl);
2169 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
2170 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2171 != void_type_node));
2173 /* For varargs, we do not want to skip the dummy va_dcl argument.
2174 For stdargs, we do want to skip the last named argument. */
2175 next_cum = *cum;
2176 if (stdarg_p)
2177 function_arg_advance (&next_cum, mode, type, 1);
2179 /* Indicate to allocate space on the stack for varargs save area. */
2180 /* ??? Does this really have to be located at a magic spot on the
2181 stack, or can we allocate this with assign_stack_local instead. */
2182 rs6000_sysv_varargs_p = 1;
2183 if (! no_rtl)
2184 save_area = plus_constant (virtual_stack_vars_rtx,
2185 - RS6000_VARARGS_SIZE);
2187 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
2189 else
2191 save_area = virtual_incoming_args_rtx;
2192 rs6000_sysv_varargs_p = 0;
2194 first_reg_offset = cum->words;
2195 if (MUST_PASS_IN_STACK (mode, type))
2196 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
2199 set = get_varargs_alias_set ();
2200 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
2202 mem = gen_rtx_MEM (BLKmode,
2203 plus_constant (save_area,
2204 first_reg_offset * reg_size)),
2205 MEM_ALIAS_SET (mem) = set;
2207 move_block_from_reg
2208 (GP_ARG_MIN_REG + first_reg_offset, mem,
2209 GP_ARG_NUM_REG - first_reg_offset,
2210 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
2212 /* ??? Does ABI_V4 need this at all? */
2213 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
2216 /* Save FP registers if needed. */
2217 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2218 && TARGET_HARD_FLOAT && ! no_rtl
2219 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
2221 int fregno = next_cum.fregno;
2222 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
2223 rtx lab = gen_label_rtx ();
2224 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
2226 emit_jump_insn (gen_rtx_SET (VOIDmode,
2227 pc_rtx,
2228 gen_rtx_IF_THEN_ELSE (VOIDmode,
2229 gen_rtx_NE (VOIDmode, cr1,
2230 const0_rtx),
2231 gen_rtx_LABEL_REF (VOIDmode, lab),
2232 pc_rtx)));
2234 while (fregno <= FP_ARG_V4_MAX_REG)
2236 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
2237 MEM_ALIAS_SET (mem) = set;
2238 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
2239 fregno++;
2240 off += 8;
2243 emit_label (lab);
2247 /* Create the va_list data type. */
2249 tree
2250 rs6000_build_va_list ()
2252 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
2254 /* For AIX, prefer 'char *' because that's what the system
2255 header files like. */
2256 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2257 return build_pointer_type (char_type_node);
2259 record = make_lang_type (RECORD_TYPE);
2260 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2262 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
2263 unsigned_char_type_node);
2264 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
2265 unsigned_char_type_node);
2266 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
2267 ptr_type_node);
2268 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
2269 ptr_type_node);
2271 DECL_FIELD_CONTEXT (f_gpr) = record;
2272 DECL_FIELD_CONTEXT (f_fpr) = record;
2273 DECL_FIELD_CONTEXT (f_ovf) = record;
2274 DECL_FIELD_CONTEXT (f_sav) = record;
2276 TREE_CHAIN (record) = type_decl;
2277 TYPE_NAME (record) = type_decl;
2278 TYPE_FIELDS (record) = f_gpr;
2279 TREE_CHAIN (f_gpr) = f_fpr;
2280 TREE_CHAIN (f_fpr) = f_ovf;
2281 TREE_CHAIN (f_ovf) = f_sav;
2283 layout_type (record);
2285 /* The correct type is an array type of one element. */
2286 return build_array_type (record, build_index_type (size_zero_node));
2289 /* Implement va_start. */
2291 void
2292 rs6000_va_start (stdarg_p, valist, nextarg)
2293 int stdarg_p;
2294 tree valist;
2295 rtx nextarg;
2297 HOST_WIDE_INT words, n_gpr, n_fpr;
2298 tree f_gpr, f_fpr, f_ovf, f_sav;
2299 tree gpr, fpr, ovf, sav, t;
2301 /* Only SVR4 needs something special. */
2302 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2304 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2305 return;
2308 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2309 f_fpr = TREE_CHAIN (f_gpr);
2310 f_ovf = TREE_CHAIN (f_fpr);
2311 f_sav = TREE_CHAIN (f_ovf);
2313 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2314 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2315 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2316 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2317 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2319 /* Count number of gp and fp argument registers used. */
2320 words = current_function_args_info.words;
2321 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
2322 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
2324 if (TARGET_DEBUG_ARG)
2325 fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n",
2326 words, n_gpr, n_fpr);
2328 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
2329 TREE_SIDE_EFFECTS (t) = 1;
2330 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2332 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
2333 TREE_SIDE_EFFECTS (t) = 1;
2334 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2336 /* Find the overflow area. */
2337 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
2338 if (words != 0)
2339 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
2340 build_int_2 (words * UNITS_PER_WORD, 0));
2341 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2342 TREE_SIDE_EFFECTS (t) = 1;
2343 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2345 /* Find the register save area. */
2346 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
2347 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
2348 build_int_2 (-RS6000_VARARGS_SIZE, -1));
2349 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
2350 TREE_SIDE_EFFECTS (t) = 1;
2351 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2354 /* Implement va_arg. */
2357 rs6000_va_arg (valist, type)
2358 tree valist, type;
2360 tree f_gpr, f_fpr, f_ovf, f_sav;
2361 tree gpr, fpr, ovf, sav, reg, t, u;
2362 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
2363 rtx lab_false, lab_over, addr_rtx, r;
2365 /* For AIX, the rule is that structures are passed left-aligned in
2366 their stack slot. However, GCC does not presently do this:
2367 structures which are the same size as integer types are passed
2368 right-aligned, as if they were in fact integers. This only
2369 matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */
2370 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2372 HOST_WIDE_INT align, rounded_size;
2373 enum machine_mode mode;
2374 tree addr_tree;
2376 /* Compute the rounded size of the type. */
2377 align = PARM_BOUNDARY / BITS_PER_UNIT;
2378 rounded_size = (((int_size_in_bytes (type) + align - 1) / align)
2379 * align);
2381 addr_tree = valist;
2383 mode = TYPE_MODE (type);
2384 if (mode != BLKmode)
2386 HOST_WIDE_INT adj;
2387 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2388 if (rounded_size > align)
2389 adj = rounded_size;
2391 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2392 build_int_2 (rounded_size - adj, 0));
2395 addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2396 addr_rtx = copy_to_reg (addr_rtx);
2398 /* Compute new value for AP. */
2399 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2400 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2401 build_int_2 (rounded_size, 0)));
2402 TREE_SIDE_EFFECTS (t) = 1;
2403 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2405 return addr_rtx;
2408 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2409 f_fpr = TREE_CHAIN (f_gpr);
2410 f_ovf = TREE_CHAIN (f_fpr);
2411 f_sav = TREE_CHAIN (f_ovf);
2413 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2414 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2415 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2416 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2417 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2419 size = int_size_in_bytes (type);
2420 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2422 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
2424 /* Aggregates and long doubles are passed by reference. */
2425 indirect_p = 1;
2426 reg = gpr;
2427 n_reg = 1;
2428 sav_ofs = 0;
2429 sav_scale = 4;
2430 size = rsize = UNITS_PER_WORD;
2432 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
2434 /* FP args go in FP registers, if present. */
2435 indirect_p = 0;
2436 reg = fpr;
2437 n_reg = 1;
2438 sav_ofs = 8*4;
2439 sav_scale = 8;
2441 else
2443 /* Otherwise into GP registers. */
2444 indirect_p = 0;
2445 reg = gpr;
2446 n_reg = rsize;
2447 sav_ofs = 0;
2448 sav_scale = 4;
2452 * Pull the value out of the saved registers ...
2455 lab_false = gen_label_rtx ();
2456 lab_over = gen_label_rtx ();
2457 addr_rtx = gen_reg_rtx (Pmode);
2459 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
2460 GEN_INT (8 - n_reg + 1),
2461 GE, const1_rtx, QImode, 1, 1, lab_false);
2463 /* Long long is aligned in the registers. */
2464 if (n_reg > 1)
2466 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
2467 build_int_2 (n_reg - 1, 0));
2468 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
2469 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
2470 TREE_SIDE_EFFECTS (u) = 1;
2471 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
2474 if (sav_ofs)
2475 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2476 else
2477 t = sav;
2479 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
2480 TREE_SIDE_EFFECTS (u) = 1;
2482 u = build1 (CONVERT_EXPR, integer_type_node, u);
2483 TREE_SIDE_EFFECTS (u) = 1;
2485 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
2486 TREE_SIDE_EFFECTS (u) = 1;
2488 t = build (PLUS_EXPR, ptr_type_node, t, u);
2489 TREE_SIDE_EFFECTS (t) = 1;
2491 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2492 if (r != addr_rtx)
2493 emit_move_insn (addr_rtx, r);
2495 emit_jump_insn (gen_jump (lab_over));
2496 emit_barrier ();
2497 emit_label (lab_false);
2500 * ... otherwise out of the overflow area.
2503 /* Make sure we don't find reg 7 for the next int arg. */
2504 if (n_reg > 1)
2506 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
2507 TREE_SIDE_EFFECTS (t) = 1;
2508 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2511 /* Care for on-stack alignment if needed. */
2512 if (rsize <= 1)
2513 t = ovf;
2514 else
2516 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
2517 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
2519 t = save_expr (t);
2521 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2522 if (r != addr_rtx)
2523 emit_move_insn (addr_rtx, r);
2525 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
2526 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2527 TREE_SIDE_EFFECTS (t) = 1;
2528 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2530 emit_label (lab_over);
2532 if (indirect_p)
2534 r = gen_rtx_MEM (Pmode, addr_rtx);
2535 MEM_ALIAS_SET (r) = get_varargs_alias_set ();
2536 emit_move_insn (addr_rtx, r);
2539 return addr_rtx;
2542 /* Generate a memory reference for expand_block_move, copying volatile,
2543 and other bits from an original memory reference. */
2545 static rtx
2546 expand_block_move_mem (mode, addr, orig_mem)
2547 enum machine_mode mode;
2548 rtx addr;
2549 rtx orig_mem;
2551 rtx mem = gen_rtx_MEM (mode, addr);
2553 MEM_COPY_ATTRIBUTES (mem, orig_mem);
2554 #ifdef MEM_UNALIGNED_P
2555 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
2556 #endif
2557 return mem;
2560 /* Expand a block move operation, and return 1 if successful. Return 0
2561 if we should let the compiler generate normal code.
2563 operands[0] is the destination
2564 operands[1] is the source
2565 operands[2] is the length
2566 operands[3] is the alignment */
2568 #define MAX_MOVE_REG 4
2571 expand_block_move (operands)
2572 rtx operands[];
2574 rtx orig_dest = operands[0];
2575 rtx orig_src = operands[1];
2576 rtx bytes_rtx = operands[2];
2577 rtx align_rtx = operands[3];
2578 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2579 int align;
2580 int bytes;
2581 int offset;
2582 int num_reg;
2583 int i;
2584 rtx src_reg;
2585 rtx dest_reg;
2586 rtx src_addr;
2587 rtx dest_addr;
2588 rtx tmp_reg;
2589 rtx stores[MAX_MOVE_REG];
2590 int move_bytes;
2592 /* If this is not a fixed size move, just call memcpy */
2593 if (! constp)
2594 return 0;
2596 /* If this is not a fixed size alignment, abort */
2597 if (GET_CODE (align_rtx) != CONST_INT)
2598 abort ();
2599 align = INTVAL (align_rtx);
2601 /* Anything to move? */
2602 bytes = INTVAL (bytes_rtx);
2603 if (bytes <= 0)
2604 return 1;
2606 /* Don't support real large moves. If string instructions are not used,
2607 then don't generate more than 8 loads. */
2608 if (TARGET_STRING)
2610 if (bytes > 8*4)
2611 return 0;
2613 else if (! STRICT_ALIGNMENT)
2615 if (TARGET_POWERPC64 && align >= 4)
2617 if (bytes > 8*8)
2618 return 0;
2620 else
2621 if (bytes > 8*4)
2622 return 0;
2624 else if (bytes > 8*align)
2625 return 0;
2627 /* Move the address into scratch registers. */
2628 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2629 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2631 if (TARGET_STRING) /* string instructions are available */
2633 for ( ; bytes > 0; bytes -= move_bytes)
2635 if (bytes > 24 /* move up to 32 bytes at a time */
2636 && ! fixed_regs[5]
2637 && ! fixed_regs[6]
2638 && ! fixed_regs[7]
2639 && ! fixed_regs[8]
2640 && ! fixed_regs[9]
2641 && ! fixed_regs[10]
2642 && ! fixed_regs[11]
2643 && ! fixed_regs[12])
2645 move_bytes = (bytes > 32) ? 32 : bytes;
2646 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
2647 dest_reg,
2648 orig_dest),
2649 expand_block_move_mem (BLKmode,
2650 src_reg,
2651 orig_src),
2652 GEN_INT ((move_bytes == 32)
2653 ? 0 : move_bytes),
2654 align_rtx));
2656 else if (bytes > 16 /* move up to 24 bytes at a time */
2657 && ! fixed_regs[5]
2658 && ! fixed_regs[6]
2659 && ! fixed_regs[7]
2660 && ! fixed_regs[8]
2661 && ! fixed_regs[9]
2662 && ! fixed_regs[10])
2664 move_bytes = (bytes > 24) ? 24 : bytes;
2665 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
2666 dest_reg,
2667 orig_dest),
2668 expand_block_move_mem (BLKmode,
2669 src_reg,
2670 orig_src),
2671 GEN_INT (move_bytes),
2672 align_rtx));
2674 else if (bytes > 8 /* move up to 16 bytes at a time */
2675 && ! fixed_regs[5]
2676 && ! fixed_regs[6]
2677 && ! fixed_regs[7]
2678 && ! fixed_regs[8])
2680 move_bytes = (bytes > 16) ? 16 : bytes;
2681 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
2682 dest_reg,
2683 orig_dest),
2684 expand_block_move_mem (BLKmode,
2685 src_reg,
2686 orig_src),
2687 GEN_INT (move_bytes),
2688 align_rtx));
2690 else if (bytes >= 8 && TARGET_POWERPC64
2691 /* 64-bit loads and stores require word-aligned displacements. */
2692 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2694 move_bytes = 8;
2695 tmp_reg = gen_reg_rtx (DImode);
2696 emit_move_insn (tmp_reg,
2697 expand_block_move_mem (DImode,
2698 src_reg, orig_src));
2699 emit_move_insn (expand_block_move_mem (DImode,
2700 dest_reg, orig_dest),
2701 tmp_reg);
2703 else if (bytes > 4)
2704 { /* move up to 8 bytes at a time */
2705 move_bytes = (bytes > 8) ? 8 : bytes;
2706 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
2707 dest_reg,
2708 orig_dest),
2709 expand_block_move_mem (BLKmode,
2710 src_reg,
2711 orig_src),
2712 GEN_INT (move_bytes),
2713 align_rtx));
2715 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2716 { /* move 4 bytes */
2717 move_bytes = 4;
2718 tmp_reg = gen_reg_rtx (SImode);
2719 emit_move_insn (tmp_reg,
2720 expand_block_move_mem (SImode,
2721 src_reg, orig_src));
2722 emit_move_insn (expand_block_move_mem (SImode,
2723 dest_reg, orig_dest),
2724 tmp_reg);
2726 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2727 { /* move 2 bytes */
2728 move_bytes = 2;
2729 tmp_reg = gen_reg_rtx (HImode);
2730 emit_move_insn (tmp_reg,
2731 expand_block_move_mem (HImode,
2732 src_reg, orig_src));
2733 emit_move_insn (expand_block_move_mem (HImode,
2734 dest_reg, orig_dest),
2735 tmp_reg);
2737 else if (bytes == 1) /* move 1 byte */
2739 move_bytes = 1;
2740 tmp_reg = gen_reg_rtx (QImode);
2741 emit_move_insn (tmp_reg,
2742 expand_block_move_mem (QImode,
2743 src_reg, orig_src));
2744 emit_move_insn (expand_block_move_mem (QImode,
2745 dest_reg, orig_dest),
2746 tmp_reg);
2748 else
2749 { /* move up to 4 bytes at a time */
2750 move_bytes = (bytes > 4) ? 4 : bytes;
2751 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
2752 dest_reg,
2753 orig_dest),
2754 expand_block_move_mem (BLKmode,
2755 src_reg,
2756 orig_src),
2757 GEN_INT (move_bytes),
2758 align_rtx));
2761 if (bytes > move_bytes)
2763 if (! TARGET_POWERPC64)
2765 emit_insn (gen_addsi3 (src_reg, src_reg,
2766 GEN_INT (move_bytes)));
2767 emit_insn (gen_addsi3 (dest_reg, dest_reg,
2768 GEN_INT (move_bytes)));
2770 else
2772 emit_insn (gen_adddi3 (src_reg, src_reg,
2773 GEN_INT (move_bytes)));
2774 emit_insn (gen_adddi3 (dest_reg, dest_reg,
2775 GEN_INT (move_bytes)));
2781 else /* string instructions not available */
2783 num_reg = offset = 0;
2784 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2786 /* Calculate the correct offset for src/dest */
2787 if (offset == 0)
2789 src_addr = src_reg;
2790 dest_addr = dest_reg;
2792 else
2794 src_addr = plus_constant (src_reg, offset);
2795 dest_addr = plus_constant (dest_reg, offset);
2798 /* Generate the appropriate load and store, saving the stores
2799 for later. */
2800 if (bytes >= 8 && TARGET_POWERPC64
2801 /* 64-bit loads and stores require word-aligned displacements. */
2802 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2804 move_bytes = 8;
2805 tmp_reg = gen_reg_rtx (DImode);
2806 emit_insn (gen_movdi (tmp_reg,
2807 expand_block_move_mem (DImode,
2808 src_addr,
2809 orig_src)));
2810 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
2811 dest_addr,
2812 orig_dest),
2813 tmp_reg);
2815 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2817 move_bytes = 4;
2818 tmp_reg = gen_reg_rtx (SImode);
2819 emit_insn (gen_movsi (tmp_reg,
2820 expand_block_move_mem (SImode,
2821 src_addr,
2822 orig_src)));
2823 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
2824 dest_addr,
2825 orig_dest),
2826 tmp_reg);
2828 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2830 move_bytes = 2;
2831 tmp_reg = gen_reg_rtx (HImode);
2832 emit_insn (gen_movhi (tmp_reg,
2833 expand_block_move_mem (HImode,
2834 src_addr,
2835 orig_src)));
2836 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
2837 dest_addr,
2838 orig_dest),
2839 tmp_reg);
2841 else
2843 move_bytes = 1;
2844 tmp_reg = gen_reg_rtx (QImode);
2845 emit_insn (gen_movqi (tmp_reg,
2846 expand_block_move_mem (QImode,
2847 src_addr,
2848 orig_src)));
2849 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
2850 dest_addr,
2851 orig_dest),
2852 tmp_reg);
2855 if (num_reg >= MAX_MOVE_REG)
2857 for (i = 0; i < num_reg; i++)
2858 emit_insn (stores[i]);
2859 num_reg = 0;
2863 for (i = 0; i < num_reg; i++)
2864 emit_insn (stores[i]);
2867 return 1;
2871 /* Return 1 if OP is a load multiple operation. It is known to be a
2872 PARALLEL and the first section will be tested. */
2875 load_multiple_operation (op, mode)
2876 rtx op;
2877 enum machine_mode mode ATTRIBUTE_UNUSED;
2879 int count = XVECLEN (op, 0);
2880 int dest_regno;
2881 rtx src_addr;
2882 int i;
2884 /* Perform a quick check so we don't blow up below. */
2885 if (count <= 1
2886 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2887 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
2888 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
2889 return 0;
2891 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
2892 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
2894 for (i = 1; i < count; i++)
2896 rtx elt = XVECEXP (op, 0, i);
2898 if (GET_CODE (elt) != SET
2899 || GET_CODE (SET_DEST (elt)) != REG
2900 || GET_MODE (SET_DEST (elt)) != SImode
2901 || REGNO (SET_DEST (elt)) != dest_regno + i
2902 || GET_CODE (SET_SRC (elt)) != MEM
2903 || GET_MODE (SET_SRC (elt)) != SImode
2904 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2905 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2906 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2907 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
2908 return 0;
2911 return 1;
2914 /* Similar, but tests for store multiple. Here, the second vector element
2915 is a CLOBBER. It will be tested later. */
2918 store_multiple_operation (op, mode)
2919 rtx op;
2920 enum machine_mode mode ATTRIBUTE_UNUSED;
2922 int count = XVECLEN (op, 0) - 1;
2923 int src_regno;
2924 rtx dest_addr;
2925 int i;
2927 /* Perform a quick check so we don't blow up below. */
2928 if (count <= 1
2929 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2930 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
2931 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
2932 return 0;
2934 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
2935 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
2937 for (i = 1; i < count; i++)
2939 rtx elt = XVECEXP (op, 0, i + 1);
2941 if (GET_CODE (elt) != SET
2942 || GET_CODE (SET_SRC (elt)) != REG
2943 || GET_MODE (SET_SRC (elt)) != SImode
2944 || REGNO (SET_SRC (elt)) != src_regno + i
2945 || GET_CODE (SET_DEST (elt)) != MEM
2946 || GET_MODE (SET_DEST (elt)) != SImode
2947 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2948 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2949 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2950 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
2951 return 0;
2954 return 1;
2957 /* Return 1 for an PARALLEL suitable for mtcrf. */
2960 mtcrf_operation (op, mode)
2961 rtx op;
2962 enum machine_mode mode ATTRIBUTE_UNUSED;
2964 int count = XVECLEN (op, 0);
2965 int i;
2966 int bitmap = 0;
2967 rtx src_reg;
2969 /* Perform a quick check so we don't blow up below. */
2970 if (count < 2
2971 || GET_CODE (XVECEXP (op, 0, 0)) != USE
2972 || GET_CODE (XEXP (XVECEXP (op, 0, 0), 0)) != CONST_INT
2973 || GET_CODE (XVECEXP (op, 0, 1)) != SET
2974 || GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != UNSPEC
2975 || XVECLEN (SET_SRC (XVECEXP (op, 0, 1)), 0) != 2)
2976 return 0;
2977 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 1)), 0, 0);
2979 if (GET_CODE (src_reg) != REG
2980 || GET_MODE (src_reg) != SImode
2981 || ! INT_REGNO_P (REGNO (src_reg)))
2982 return 0;
2984 for (i = 1; i < count; i++)
2986 rtx exp = XVECEXP (op, 0, i);
2987 rtx unspec;
2988 int maskval;
2990 if (GET_CODE (exp) != SET
2991 || GET_CODE (SET_DEST (exp)) != REG
2992 || GET_MODE (SET_DEST (exp)) != CCmode
2993 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
2994 return 0;
2995 unspec = SET_SRC (exp);
2996 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
2997 bitmap |= maskval;
2999 if (GET_CODE (unspec) != UNSPEC
3000 || XINT (unspec, 1) != 20
3001 || XVECLEN (unspec, 0) != 2
3002 || XVECEXP (unspec, 0, 0) != src_reg
3003 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
3004 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
3005 return 0;
3007 return INTVAL (XEXP (XVECEXP (op, 0, 0), 0)) == bitmap;
3010 /* Return 1 for an PARALLEL suitable for lmw. */
3013 lmw_operation (op, mode)
3014 rtx op;
3015 enum machine_mode mode ATTRIBUTE_UNUSED;
3017 int count = XVECLEN (op, 0);
3018 int dest_regno;
3019 rtx src_addr;
3020 int base_regno;
3021 HOST_WIDE_INT offset;
3022 int i;
3024 /* Perform a quick check so we don't blow up below. */
3025 if (count <= 1
3026 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3027 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
3028 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
3029 return 0;
3031 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
3032 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
3034 if (dest_regno > 31
3035 || count != 32 - dest_regno)
3036 return 0;
3038 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr))
3040 offset = 0;
3041 base_regno = REGNO (src_addr);
3042 if (base_regno == 0)
3043 return 0;
3045 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr))
3047 offset = INTVAL (XEXP (src_addr, 1));
3048 base_regno = REGNO (XEXP (src_addr, 0));
3050 else
3051 return 0;
3053 for (i = 0; i < count; i++)
3055 rtx elt = XVECEXP (op, 0, i);
3056 rtx newaddr;
3057 rtx addr_reg;
3058 HOST_WIDE_INT newoffset;
3060 if (GET_CODE (elt) != SET
3061 || GET_CODE (SET_DEST (elt)) != REG
3062 || GET_MODE (SET_DEST (elt)) != SImode
3063 || REGNO (SET_DEST (elt)) != dest_regno + i
3064 || GET_CODE (SET_SRC (elt)) != MEM
3065 || GET_MODE (SET_SRC (elt)) != SImode)
3066 return 0;
3067 newaddr = XEXP (SET_SRC (elt), 0);
3068 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3070 newoffset = 0;
3071 addr_reg = newaddr;
3073 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3075 addr_reg = XEXP (newaddr, 0);
3076 newoffset = INTVAL (XEXP (newaddr, 1));
3078 else
3079 return 0;
3080 if (REGNO (addr_reg) != base_regno
3081 || newoffset != offset + 4 * i)
3082 return 0;
3085 return 1;
3088 /* Return 1 for an PARALLEL suitable for stmw. */
3091 stmw_operation (op, mode)
3092 rtx op;
3093 enum machine_mode mode ATTRIBUTE_UNUSED;
3095 int count = XVECLEN (op, 0);
3096 int src_regno;
3097 rtx dest_addr;
3098 int base_regno;
3099 HOST_WIDE_INT offset;
3100 int i;
3102 /* Perform a quick check so we don't blow up below. */
3103 if (count <= 1
3104 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3105 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3106 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3107 return 0;
3109 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3110 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3112 if (src_regno > 31
3113 || count != 32 - src_regno)
3114 return 0;
3116 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr))
3118 offset = 0;
3119 base_regno = REGNO (dest_addr);
3120 if (base_regno == 0)
3121 return 0;
3123 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr))
3125 offset = INTVAL (XEXP (dest_addr, 1));
3126 base_regno = REGNO (XEXP (dest_addr, 0));
3128 else
3129 return 0;
3131 for (i = 0; i < count; i++)
3133 rtx elt = XVECEXP (op, 0, i);
3134 rtx newaddr;
3135 rtx addr_reg;
3136 HOST_WIDE_INT newoffset;
3138 if (GET_CODE (elt) != SET
3139 || GET_CODE (SET_SRC (elt)) != REG
3140 || GET_MODE (SET_SRC (elt)) != SImode
3141 || REGNO (SET_SRC (elt)) != src_regno + i
3142 || GET_CODE (SET_DEST (elt)) != MEM
3143 || GET_MODE (SET_DEST (elt)) != SImode)
3144 return 0;
3145 newaddr = XEXP (SET_DEST (elt), 0);
3146 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3148 newoffset = 0;
3149 addr_reg = newaddr;
3151 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3153 addr_reg = XEXP (newaddr, 0);
3154 newoffset = INTVAL (XEXP (newaddr, 1));
3156 else
3157 return 0;
3158 if (REGNO (addr_reg) != base_regno
3159 || newoffset != offset + 4 * i)
3160 return 0;
3163 return 1;
3166 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
3167 We only check the opcode against the mode of the CC value here. */
3170 branch_comparison_operator (op, mode)
3171 register rtx op;
3172 enum machine_mode mode ATTRIBUTE_UNUSED;
3174 enum rtx_code code = GET_CODE (op);
3175 enum machine_mode cc_mode;
3177 if (GET_RTX_CLASS (code) != '<')
3178 return 0;
3180 cc_mode = GET_MODE (XEXP (op, 0));
3181 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3182 return 0;
3184 if ((code == GT || code == LT || code == GE || code == LE)
3185 && cc_mode == CCUNSmode)
3186 return 0;
3188 if ((code == GTU || code == LTU || code == GEU || code == LEU)
3189 && (cc_mode != CCUNSmode))
3190 return 0;
3192 return 1;
3195 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
3196 We check the opcode against the mode of the CC value and disallow EQ or
3197 NE comparisons for integers. */
3200 scc_comparison_operator (op, mode)
3201 register rtx op;
3202 enum machine_mode mode;
3204 enum rtx_code code = GET_CODE (op);
3205 enum machine_mode cc_mode;
3207 if (GET_MODE (op) != mode && mode != VOIDmode)
3208 return 0;
3210 if (GET_RTX_CLASS (code) != '<')
3211 return 0;
3213 cc_mode = GET_MODE (XEXP (op, 0));
3214 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3215 return 0;
3217 if (code == NE && cc_mode != CCFPmode)
3218 return 0;
3220 if ((code == GT || code == LT || code == GE || code == LE)
3221 && cc_mode == CCUNSmode)
3222 return 0;
3224 if ((code == GTU || code == LTU || code == GEU || code == LEU)
3225 && (cc_mode != CCUNSmode))
3226 return 0;
3228 if (cc_mode == CCEQmode && code != EQ && code != NE)
3229 return 0;
3231 return 1;
3235 trap_comparison_operator (op, mode)
3236 rtx op;
3237 enum machine_mode mode;
3239 if (mode != VOIDmode && mode != GET_MODE (op))
3240 return 0;
3241 return (GET_RTX_CLASS (GET_CODE (op)) == '<'
3242 || GET_CODE (op) == EQ || GET_CODE (op) == NE);
3246 boolean_operator (op, mode)
3247 rtx op;
3248 enum machine_mode mode ATTRIBUTE_UNUSED;
3250 enum rtx_code code = GET_CODE (op);
3251 return (code == AND || code == IOR || code == XOR);
3255 boolean_or_operator (op, mode)
3256 rtx op;
3257 enum machine_mode mode ATTRIBUTE_UNUSED;
3259 enum rtx_code code = GET_CODE (op);
3260 return (code == IOR || code == XOR);
3263 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
3264 mask required to convert the result of a rotate insn into a shift
3265 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
3268 includes_lshift_p (shiftop, andop)
3269 register rtx shiftop;
3270 register rtx andop;
3272 int shift_mask = (~0 << INTVAL (shiftop));
3274 return (INTVAL (andop) & ~shift_mask) == 0;
3277 /* Similar, but for right shift. */
3280 includes_rshift_p (shiftop, andop)
3281 register rtx shiftop;
3282 register rtx andop;
3284 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3286 shift_mask >>= INTVAL (shiftop);
3288 return (INTVAL (andop) & ~ shift_mask) == 0;
3291 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
3292 for lfq and stfq insns.
3294 Note reg1 and reg2 *must* be hard registers. To be sure we will
3295 abort if we are passed pseudo registers. */
3298 registers_ok_for_quad_peep (reg1, reg2)
3299 rtx reg1, reg2;
3301 /* We might have been passed a SUBREG. */
3302 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
3303 return 0;
3305 return (REGNO (reg1) == REGNO (reg2) - 1);
3308 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
3309 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
3312 addrs_ok_for_quad_peep (addr1, addr2)
3313 register rtx addr1;
3314 register rtx addr2;
3316 int reg1;
3317 int offset1;
3319 /* Extract an offset (if used) from the first addr. */
3320 if (GET_CODE (addr1) == PLUS)
3322 /* If not a REG, return zero. */
3323 if (GET_CODE (XEXP (addr1, 0)) != REG)
3324 return 0;
3325 else
3327 reg1 = REGNO (XEXP (addr1, 0));
3328 /* The offset must be constant! */
3329 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
3330 return 0;
3331 offset1 = INTVAL (XEXP (addr1, 1));
3334 else if (GET_CODE (addr1) != REG)
3335 return 0;
3336 else
3338 reg1 = REGNO (addr1);
3339 /* This was a simple (mem (reg)) expression. Offset is 0. */
3340 offset1 = 0;
3343 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
3344 if (GET_CODE (addr2) != PLUS)
3345 return 0;
3347 if (GET_CODE (XEXP (addr2, 0)) != REG
3348 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
3349 return 0;
3351 if (reg1 != REGNO (XEXP (addr2, 0)))
3352 return 0;
3354 /* The offset for the second addr must be 8 more than the first addr. */
3355 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
3356 return 0;
3358 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
3359 instructions. */
3360 return 1;
3363 /* Return the register class of a scratch register needed to copy IN into
3364 or out of a register in CLASS in MODE. If it can be done directly,
3365 NO_REGS is returned. */
3367 enum reg_class
3368 secondary_reload_class (class, mode, in)
3369 enum reg_class class;
3370 enum machine_mode mode ATTRIBUTE_UNUSED;
3371 rtx in;
3373 int regno;
3375 #if TARGET_ELF
3376 /* We can not copy a symbolic operand directly into anything other than
3377 BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS
3378 is needed as an intermediate register. */
3379 if (class != BASE_REGS
3380 && (GET_CODE (in) == SYMBOL_REF
3381 || GET_CODE (in) == HIGH
3382 || GET_CODE (in) == LABEL_REF
3383 || GET_CODE (in) == CONST))
3384 return BASE_REGS;
3385 #endif
3387 if (GET_CODE (in) == REG)
3389 regno = REGNO (in);
3390 if (regno >= FIRST_PSEUDO_REGISTER)
3392 regno = true_regnum (in);
3393 if (regno >= FIRST_PSEUDO_REGISTER)
3394 regno = -1;
3397 else if (GET_CODE (in) == SUBREG)
3399 regno = true_regnum (in);
3400 if (regno >= FIRST_PSEUDO_REGISTER)
3401 regno = -1;
3403 else
3404 regno = -1;
3406 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
3407 into anything. */
3408 if (class == GENERAL_REGS || class == BASE_REGS
3409 || (regno >= 0 && INT_REGNO_P (regno)))
3410 return NO_REGS;
3412 /* Constants, memory, and FP registers can go into FP registers. */
3413 if ((regno == -1 || FP_REGNO_P (regno))
3414 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
3415 return NO_REGS;
3417 /* We can copy among the CR registers. */
3418 if ((class == CR_REGS || class == CR0_REGS)
3419 && regno >= 0 && CR_REGNO_P (regno))
3420 return NO_REGS;
3422 /* Otherwise, we need GENERAL_REGS. */
3423 return GENERAL_REGS;
3426 /* Given a comparison operation, return the bit number in CCR to test. We
3427 know this is a valid comparison.
3429 SCC_P is 1 if this is for an scc. That means that %D will have been
3430 used instead of %C, so the bits will be in different places.
3432 Return -1 if OP isn't a valid comparison for some reason. */
3435 ccr_bit (op, scc_p)
3436 register rtx op;
3437 int scc_p;
3439 enum rtx_code code = GET_CODE (op);
3440 enum machine_mode cc_mode;
3441 int cc_regnum;
3442 int base_bit;
3443 rtx reg;
3445 if (GET_RTX_CLASS (code) != '<')
3446 return -1;
3448 reg = XEXP (op, 0);
3450 if (GET_CODE (reg) != REG
3451 || ! CR_REGNO_P (REGNO (reg)))
3452 abort ();
3454 cc_mode = GET_MODE (reg);
3455 cc_regnum = REGNO (reg);
3456 base_bit = 4 * (cc_regnum - CR0_REGNO);
3458 /* In CCEQmode cases we have made sure that the result is always in the
3459 third bit of the CR field. */
3461 if (cc_mode == CCEQmode)
3462 return base_bit + 3;
3464 switch (code)
3466 case NE:
3467 return scc_p ? base_bit + 3 : base_bit + 2;
3468 case EQ:
3469 return base_bit + 2;
3470 case GT: case GTU: case UNLE:
3471 return base_bit + 1;
3472 case LT: case LTU: case UNGE:
3473 return base_bit;
3474 case ORDERED: case UNORDERED:
3475 return base_bit + 3;
3477 case GE: case GEU:
3478 /* If floating-point, we will have done a cror to put the bit in the
3479 unordered position. So test that bit. For integer, this is ! LT
3480 unless this is an scc insn. */
3481 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
3483 case LE: case LEU:
3484 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
3486 case UNEQ: case UNGT: case UNLT: case LTGT:
3487 return base_bit + 3;
3489 default:
3490 abort ();
3494 /* Return the GOT register. */
3496 struct rtx_def *
3497 rs6000_got_register (value)
3498 rtx value ATTRIBUTE_UNUSED;
3500 /* The second flow pass currently (June 1999) can't update regs_ever_live
3501 without disturbing other parts of the compiler, so update it here to
3502 make the prolog/epilogue code happy. */
3503 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
3504 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
3506 current_function_uses_pic_offset_table = 1;
3508 return pic_offset_table_rtx;
3511 /* Define the structure for the machine field in struct function. */
3512 struct machine_function
3514 int sysv_varargs_p;
3517 /* Functions to save and restore sysv_varargs_p.
3518 These will be called, via pointer variables,
3519 from push_function_context and pop_function_context. */
3521 void
3522 rs6000_save_machine_status (p)
3523 struct function *p;
3525 struct machine_function *machine =
3526 (struct machine_function *) xmalloc (sizeof (struct machine_function));
3528 p->machine = machine;
3529 machine->sysv_varargs_p = rs6000_sysv_varargs_p;
3532 void
3533 rs6000_restore_machine_status (p)
3534 struct function *p;
3536 struct machine_function *machine = p->machine;
3538 rs6000_sysv_varargs_p = machine->sysv_varargs_p;
3540 free (machine);
3541 p->machine = (struct machine_function *)0;
3544 /* Do anything needed before RTL is emitted for each function. */
3546 void
3547 rs6000_init_expanders ()
3549 /* Reset varargs */
3550 rs6000_sysv_varargs_p = 0;
3552 /* Arrange to save and restore machine status around nested functions. */
3553 save_machine_status = rs6000_save_machine_status;
3554 restore_machine_status = rs6000_restore_machine_status;
3558 /* Print an operand. Recognize special options, documented below. */
3560 #if TARGET_ELF
3561 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
3562 #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
3563 #else
3564 #define SMALL_DATA_RELOC "sda21"
3565 #define SMALL_DATA_REG 0
3566 #endif
3568 void
3569 print_operand (file, x, code)
3570 FILE *file;
3571 rtx x;
3572 int code;
3574 int i;
3575 HOST_WIDE_INT val;
3577 /* These macros test for integers and extract the low-order bits. */
3578 #define INT_P(X) \
3579 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
3580 && GET_MODE (X) == VOIDmode)
3582 #define INT_LOWPART(X) \
3583 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
3585 switch (code)
3587 case '.':
3588 /* Write out an instruction after the call which may be replaced
3589 with glue code by the loader. This depends on the AIX version. */
3590 asm_fprintf (file, RS6000_CALL_GLUE);
3591 return;
3593 case '$':
3594 /* Write out either a '.' or '$' for the current location, depending
3595 on whether this is Solaris or not. */
3596 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
3597 return;
3599 /* %a is output_address. */
3601 case 'A':
3602 /* If X is a constant integer whose low-order 5 bits are zero,
3603 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
3604 in the AIX assembler where "sri" with a zero shift count
3605 write a trash instruction. */
3606 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
3607 putc ('l', file);
3608 else
3609 putc ('r', file);
3610 return;
3612 case 'b':
3613 /* Low-order 16 bits of constant, unsigned. */
3614 if (! INT_P (x))
3615 output_operand_lossage ("invalid %%b value");
3617 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
3618 return;
3620 case 'B':
3621 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
3622 for 64-bit mask direction. */
3623 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
3624 return;
3626 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
3627 output_operand. */
3629 case 'C':
3631 enum rtx_code code = GET_CODE (x);
3633 /* This is an optional cror needed for certain floating-point
3634 comparisons. Otherwise write nothing. */
3635 if ((code == LE || code == GE
3636 || code == UNEQ || code == LTGT
3637 || code == UNGT || code == UNLT)
3638 && GET_MODE (XEXP (x, 0)) == CCFPmode)
3640 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3641 int bit0, bit1;
3643 if (code == UNEQ)
3644 bit0 = 2;
3645 else if (code == UNGT || code == GE)
3646 bit0 = 1;
3647 else
3648 bit0 = 0;
3649 if (code == LTGT)
3650 bit1 = 1;
3651 else if (code == LE || code == GE)
3652 bit1 = 2;
3653 else
3654 bit1 = 3;
3656 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
3657 base_bit + bit1, base_bit + bit0);
3660 return;
3662 case 'D':
3663 /* Similar, except that this is for an scc, so we must be able to
3664 encode the test in a single bit that is one. We do the above
3665 for any LE, GE, GEU, or LEU and invert the bit for NE. */
3666 if (GET_CODE (x) == LE || GET_CODE (x) == GE
3667 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
3669 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3671 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
3672 base_bit + 2,
3673 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
3676 else if (GET_CODE (x) == NE)
3678 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3680 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
3681 base_bit + 2, base_bit + 2);
3683 return;
3685 case 'E':
3686 /* X is a CR register. Print the number of the third bit of the CR */
3687 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3688 output_operand_lossage ("invalid %%E value");
3690 fprintf(file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 3);
3691 return;
3693 case 'f':
3694 /* X is a CR register. Print the shift count needed to move it
3695 to the high-order four bits. */
3696 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3697 output_operand_lossage ("invalid %%f value");
3698 else
3699 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
3700 return;
3702 case 'F':
3703 /* Similar, but print the count for the rotate in the opposite
3704 direction. */
3705 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3706 output_operand_lossage ("invalid %%F value");
3707 else
3708 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
3709 return;
3711 case 'G':
3712 /* X is a constant integer. If it is negative, print "m",
3713 otherwise print "z". This is to make a aze or ame insn. */
3714 if (GET_CODE (x) != CONST_INT)
3715 output_operand_lossage ("invalid %%G value");
3716 else if (INTVAL (x) >= 0)
3717 putc ('z', file);
3718 else
3719 putc ('m', file);
3720 return;
3722 case 'h':
3723 /* If constant, output low-order five bits. Otherwise,
3724 write normally. */
3725 if (INT_P (x))
3726 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
3727 else
3728 print_operand (file, x, 0);
3729 return;
3731 case 'H':
3732 /* If constant, output low-order six bits. Otherwise,
3733 write normally. */
3734 if (INT_P (x))
3735 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
3736 else
3737 print_operand (file, x, 0);
3738 return;
3740 case 'I':
3741 /* Print `i' if this is a constant, else nothing. */
3742 if (INT_P (x))
3743 putc ('i', file);
3744 return;
3746 case 'j':
3747 /* Write the bit number in CCR for jump. */
3748 i = ccr_bit (x, 0);
3749 if (i == -1)
3750 output_operand_lossage ("invalid %%j code");
3751 else
3752 fprintf (file, "%d", i);
3753 return;
3755 case 'J':
3756 /* Similar, but add one for shift count in rlinm for scc and pass
3757 scc flag to `ccr_bit'. */
3758 i = ccr_bit (x, 1);
3759 if (i == -1)
3760 output_operand_lossage ("invalid %%J code");
3761 else
3762 /* If we want bit 31, write a shift count of zero, not 32. */
3763 fprintf (file, "%d", i == 31 ? 0 : i + 1);
3764 return;
3766 case 'k':
3767 /* X must be a constant. Write the 1's complement of the
3768 constant. */
3769 if (! INT_P (x))
3770 output_operand_lossage ("invalid %%k value");
3772 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
3773 return;
3775 case 'K':
3776 /* X must be a symbolic constant on ELF. Write an
3777 expression suitable for an 'addi' that adds in the low 16
3778 bits of the MEM. */
3779 if (GET_CODE (x) != CONST)
3781 print_operand_address (file, x);
3782 fputs ("@l", file);
3784 else
3786 if (GET_CODE (XEXP (x, 0)) != PLUS
3787 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
3788 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3789 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
3790 output_operand_lossage ("invalid %%K value");
3791 print_operand_address (file, XEXP (XEXP (x, 0), 0));
3792 fputs ("@l", file);
3793 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
3795 return;
3797 /* %l is output_asm_label. */
3799 case 'L':
3800 /* Write second word of DImode or DFmode reference. Works on register
3801 or non-indexed memory only. */
3802 if (GET_CODE (x) == REG)
3803 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
3804 else if (GET_CODE (x) == MEM)
3806 /* Handle possible auto-increment. Since it is pre-increment and
3807 we have already done it, we can just use an offset of word. */
3808 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3809 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3810 output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0),
3811 UNITS_PER_WORD));
3812 else
3813 output_address (plus_constant_for_output (XEXP (x, 0),
3814 UNITS_PER_WORD));
3815 if (small_data_operand (x, GET_MODE (x)))
3816 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3817 reg_names[SMALL_DATA_REG]);
3819 return;
3821 case 'm':
3822 /* MB value for a mask operand. */
3823 if (! mask_operand (x, VOIDmode))
3824 output_operand_lossage ("invalid %%m value");
3826 val = INT_LOWPART (x);
3828 /* If the high bit is set and the low bit is not, the value is zero.
3829 If the high bit is zero, the value is the first 1 bit we find from
3830 the left. */
3831 if ((val & 0x80000000u) && ((val & 1) == 0))
3833 putc ('0', file);
3834 return;
3836 else if ((val & 0x80000000u) == 0)
3838 for (i = 1; i < 32; i++)
3839 if ((val <<= 1) & 0x80000000u)
3840 break;
3841 fprintf (file, "%d", i);
3842 return;
3845 /* Otherwise, look for the first 0 bit from the right. The result is its
3846 number plus 1. We know the low-order bit is one. */
3847 for (i = 0; i < 32; i++)
3848 if (((val >>= 1) & 1) == 0)
3849 break;
3851 /* If we ended in ...01, i would be 0. The correct value is 31, so
3852 we want 31 - i. */
3853 fprintf (file, "%d", 31 - i);
3854 return;
3856 case 'M':
3857 /* ME value for a mask operand. */
3858 if (! mask_operand (x, VOIDmode))
3859 output_operand_lossage ("invalid %%M value");
3861 val = INT_LOWPART (x);
3863 /* If the low bit is set and the high bit is not, the value is 31.
3864 If the low bit is zero, the value is the first 1 bit we find from
3865 the right. */
3866 if ((val & 1) && ((val & 0x80000000u) == 0))
3868 fputs ("31", file);
3869 return;
3871 else if ((val & 1) == 0)
3873 for (i = 0; i < 32; i++)
3874 if ((val >>= 1) & 1)
3875 break;
3877 /* If we had ....10, i would be 0. The result should be
3878 30, so we need 30 - i. */
3879 fprintf (file, "%d", 30 - i);
3880 return;
3883 /* Otherwise, look for the first 0 bit from the left. The result is its
3884 number minus 1. We know the high-order bit is one. */
3885 for (i = 0; i < 32; i++)
3886 if (((val <<= 1) & 0x80000000u) == 0)
3887 break;
3889 fprintf (file, "%d", i);
3890 return;
3892 /* %n outputs the negative of its operand. */
3894 case 'N':
3895 /* Write the number of elements in the vector times 4. */
3896 if (GET_CODE (x) != PARALLEL)
3897 output_operand_lossage ("invalid %%N value");
3899 fprintf (file, "%d", XVECLEN (x, 0) * 4);
3900 return;
3902 case 'O':
3903 /* Similar, but subtract 1 first. */
3904 if (GET_CODE (x) != PARALLEL)
3905 output_operand_lossage ("invalid %%O value");
3907 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
3908 return;
3910 case 'p':
3911 /* X is a CONST_INT that is a power of two. Output the logarithm. */
3912 if (! INT_P (x)
3913 || (i = exact_log2 (INT_LOWPART (x))) < 0)
3914 output_operand_lossage ("invalid %%p value");
3916 fprintf (file, "%d", i);
3917 return;
3919 case 'P':
3920 /* The operand must be an indirect memory reference. The result
3921 is the register number. */
3922 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
3923 || REGNO (XEXP (x, 0)) >= 32)
3924 output_operand_lossage ("invalid %%P value");
3926 fprintf (file, "%d", REGNO (XEXP (x, 0)));
3927 return;
3929 case 'q':
3930 /* This outputs the logical code corresponding to a boolean
3931 expression. The expression may have one or both operands
3932 negated (if one, only the first one). */
3934 const char *const *t;
3935 const char *s;
3936 enum rtx_code code = GET_CODE (x);
3937 static const char * const tbl[3][3] = {
3938 { "and", "andc", "nor" },
3939 { "or", "orc", "nand" },
3940 { "xor", "eqv", "xor" } };
3942 if (code == AND)
3943 t = tbl[0];
3944 else if (code == IOR)
3945 t = tbl[1];
3946 else if (code == XOR)
3947 t = tbl[2];
3948 else
3949 output_operand_lossage ("invalid %%q value");
3951 if (GET_CODE (XEXP (x, 0)) != NOT)
3952 s = t[0];
3953 else
3955 if (GET_CODE (XEXP (x, 1)) == NOT)
3956 s = t[2];
3957 else
3958 s = t[1];
3961 fputs (s, file);
3963 return;
3965 case 'R':
3966 /* X is a CR register. Print the mask for `mtcrf'. */
3967 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3968 output_operand_lossage ("invalid %%R value");
3969 else
3970 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
3971 return;
3973 case 's':
3974 /* Low 5 bits of 32 - value */
3975 if (! INT_P (x))
3976 output_operand_lossage ("invalid %%s value");
3978 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
3979 return;
3981 case 'S':
3982 /* PowerPC64 mask position. All 0's and all 1's are excluded.
3983 CONST_INT 32-bit mask is considered sign-extended so any
3984 transition must occur within the CONST_INT, not on the boundary. */
3985 if (! mask64_operand (x, VOIDmode))
3986 output_operand_lossage ("invalid %%S value");
3988 val = INT_LOWPART (x);
3990 if (val & 1) /* Clear Left */
3992 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
3993 if (!((val >>= 1) & 1))
3994 break;
3996 #if HOST_BITS_PER_WIDE_INT == 32
3997 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
3999 val = CONST_DOUBLE_HIGH (x);
4001 if (val == 0)
4002 --i;
4003 else
4004 for (i = 32; i < 64; i++)
4005 if (!((val >>= 1) & 1))
4006 break;
4008 #endif
4009 /* i = index of last set bit from right
4010 mask begins at 63 - i from left */
4011 if (i > 63)
4012 output_operand_lossage ("%%S computed all 1's mask");
4013 fprintf (file, "%d", 63 - i);
4014 return;
4016 else /* Clear Right */
4018 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4019 if ((val >>= 1) & 1)
4020 break;
4022 #if HOST_BITS_PER_WIDE_INT == 32
4023 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4025 val = CONST_DOUBLE_HIGH (x);
4027 if (val == (HOST_WIDE_INT) -1)
4028 --i;
4029 else
4030 for (i = 32; i < 64; i++)
4031 if ((val >>= 1) & 1)
4032 break;
4034 #endif
4035 /* i = index of last clear bit from right
4036 mask ends at 62 - i from left */
4037 if (i > 62)
4038 output_operand_lossage ("%%S computed all 0's mask");
4039 fprintf (file, "%d", 62 - i);
4040 return;
4043 case 'u':
4044 /* High-order 16 bits of constant for use in unsigned operand. */
4045 if (! INT_P (x))
4046 output_operand_lossage ("invalid %%u value");
4048 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
4049 (INT_LOWPART (x) >> 16) & 0xffff);
4050 return;
4052 case 'v':
4053 /* High-order 16 bits of constant for use in signed operand. */
4054 if (! INT_P (x))
4055 output_operand_lossage ("invalid %%v value");
4058 int value = (INT_LOWPART (x) >> 16) & 0xffff;
4060 /* Solaris assembler doesn't like lis 0,0x8000 */
4061 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
4062 fprintf (file, "%d", value | (~0 << 16));
4063 else
4064 fprintf (file, "0x%x", value);
4065 return;
4068 case 'U':
4069 /* Print `u' if this has an auto-increment or auto-decrement. */
4070 if (GET_CODE (x) == MEM
4071 && (GET_CODE (XEXP (x, 0)) == PRE_INC
4072 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
4073 putc ('u', file);
4074 return;
4076 case 'V':
4077 /* Print the trap code for this operand. */
4078 switch (GET_CODE (x))
4080 case EQ:
4081 fputs ("eq", file); /* 4 */
4082 break;
4083 case NE:
4084 fputs ("ne", file); /* 24 */
4085 break;
4086 case LT:
4087 fputs ("lt", file); /* 16 */
4088 break;
4089 case LE:
4090 fputs ("le", file); /* 20 */
4091 break;
4092 case GT:
4093 fputs ("gt", file); /* 8 */
4094 break;
4095 case GE:
4096 fputs ("ge", file); /* 12 */
4097 break;
4098 case LTU:
4099 fputs ("llt", file); /* 2 */
4100 break;
4101 case LEU:
4102 fputs ("lle", file); /* 6 */
4103 break;
4104 case GTU:
4105 fputs ("lgt", file); /* 1 */
4106 break;
4107 case GEU:
4108 fputs ("lge", file); /* 5 */
4109 break;
4110 default:
4111 abort ();
4113 break;
4115 case 'w':
4116 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
4117 normally. */
4118 if (INT_P (x))
4119 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
4120 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
4121 else
4122 print_operand (file, x, 0);
4123 return;
4125 case 'W':
4126 /* If constant, low-order 16 bits of constant, unsigned.
4127 Otherwise, write normally. */
4128 if (INT_P (x))
4129 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
4130 else
4131 print_operand (file, x, 0);
4132 return;
4134 case 'X':
4135 if (GET_CODE (x) == MEM
4136 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
4137 putc ('x', file);
4138 return;
4140 case 'Y':
4141 /* Like 'L', for third word of TImode */
4142 if (GET_CODE (x) == REG)
4143 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
4144 else if (GET_CODE (x) == MEM)
4146 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4147 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4148 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
4149 else
4150 output_address (plus_constant (XEXP (x, 0), 8));
4151 if (small_data_operand (x, GET_MODE (x)))
4152 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4153 reg_names[SMALL_DATA_REG]);
4155 return;
4157 case 'z':
4158 /* X is a SYMBOL_REF. Write out the name preceded by a
4159 period and without any trailing data in brackets. Used for function
4160 names. If we are configured for System V (or the embedded ABI) on
4161 the PowerPC, do not emit the period, since those systems do not use
4162 TOCs and the like. */
4163 if (GET_CODE (x) != SYMBOL_REF)
4164 abort ();
4166 if (XSTR (x, 0)[0] != '.')
4168 switch (DEFAULT_ABI)
4170 default:
4171 abort ();
4173 case ABI_AIX:
4174 putc ('.', file);
4175 break;
4177 case ABI_V4:
4178 case ABI_AIX_NODESC:
4179 case ABI_SOLARIS:
4180 break;
4183 #if TARGET_AIX
4184 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
4185 #else
4186 assemble_name (file, XSTR (x, 0));
4187 #endif
4188 return;
4190 case 'Z':
4191 /* Like 'L', for last word of TImode. */
4192 if (GET_CODE (x) == REG)
4193 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
4194 else if (GET_CODE (x) == MEM)
4196 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4197 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4198 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
4199 else
4200 output_address (plus_constant (XEXP (x, 0), 12));
4201 if (small_data_operand (x, GET_MODE (x)))
4202 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4203 reg_names[SMALL_DATA_REG]);
4205 return;
4207 case 0:
4208 if (GET_CODE (x) == REG)
4209 fprintf (file, "%s", reg_names[REGNO (x)]);
4210 else if (GET_CODE (x) == MEM)
4212 /* We need to handle PRE_INC and PRE_DEC here, since we need to
4213 know the width from the mode. */
4214 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
4215 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
4216 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4217 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
4218 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
4219 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4220 else
4221 output_address (XEXP (x, 0));
4223 else
4224 output_addr_const (file, x);
4225 return;
4227 default:
4228 output_operand_lossage ("invalid %%xn code");
4232 /* Print the address of an operand. */
4234 void
4235 print_operand_address (file, x)
4236 FILE *file;
4237 register rtx x;
4239 if (GET_CODE (x) == REG)
4240 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
4241 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
4242 || GET_CODE (x) == LABEL_REF)
4244 output_addr_const (file, x);
4245 if (small_data_operand (x, GET_MODE (x)))
4246 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4247 reg_names[SMALL_DATA_REG]);
4248 else if (TARGET_TOC)
4249 abort();
4251 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
4253 if (REGNO (XEXP (x, 0)) == 0)
4254 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
4255 reg_names[ REGNO (XEXP (x, 0)) ]);
4256 else
4257 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
4258 reg_names[ REGNO (XEXP (x, 1)) ]);
4260 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4262 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
4263 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4265 #if TARGET_ELF
4266 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
4267 && CONSTANT_P (XEXP (x, 1)))
4269 output_addr_const (file, XEXP (x, 1));
4270 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4272 #endif
4273 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
4275 if (TARGET_AIX)
4277 rtx contains_minus = XEXP (x, 1);
4278 rtx minus;
4280 /* Find the (minus (sym) (toc)) buried in X, and temporarily
4281 turn it into (sym) for output_addr_const. */
4282 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
4283 contains_minus = XEXP (contains_minus, 0);
4285 minus = XEXP (contains_minus, 0);
4286 XEXP (contains_minus, 0) = XEXP (minus, 0);
4287 output_addr_const (file, XEXP (x, 1));
4288 XEXP (contains_minus, 0) = minus;
4290 else
4291 output_addr_const (file, XEXP (x, 1));
4293 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
4295 else
4296 abort ();
4299 /* Return the string to output a conditional branch to LABEL, which is
4300 the operand number of the label, or -1 if the branch is really a
4301 conditional return.
4303 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
4304 condition code register and its mode specifies what kind of
4305 comparison we made.
4307 REVERSED is non-zero if we should reverse the sense of the comparison.
4309 INSN is the insn. */
4311 char *
4312 output_cbranch (op, label, reversed, insn)
4313 rtx op;
4314 const char * label;
4315 int reversed;
4316 rtx insn;
4318 static char string[64];
4319 enum rtx_code code = GET_CODE (op);
4320 rtx cc_reg = XEXP (op, 0);
4321 enum machine_mode mode = GET_MODE (cc_reg);
4322 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
4323 int need_longbranch = label != NULL && get_attr_length (insn) == 12;
4324 int really_reversed = reversed ^ need_longbranch;
4325 char *s = string;
4326 const char *ccode;
4327 const char *pred;
4328 rtx note;
4330 /* Work out which way this really branches. */
4331 if (really_reversed)
4333 /* Reversal of FP compares takes care -- an ordered compare
4334 becomes an unordered compare and vice versa. */
4335 if (mode == CCFPmode)
4336 code = reverse_condition_maybe_unordered (code);
4337 else
4338 code = reverse_condition (code);
4341 /* If needed, print the CROR required for various floating-point
4342 comparisons; and decide on the condition code to test. */
4343 if ((code == LE || code == GE
4344 || code == UNEQ || code == LTGT
4345 || code == UNGT || code == UNLT)
4346 && mode == CCFPmode)
4348 int base_bit = 4 * cc_regno;
4349 int bit0, bit1;
4351 if (code == UNEQ)
4352 bit0 = 2;
4353 else if (code == UNGT || code == GE)
4354 bit0 = 1;
4355 else
4356 bit0 = 0;
4357 if (code == LTGT)
4358 bit1 = 1;
4359 else if (code == LE || code == GE)
4360 bit1 = 2;
4361 else
4362 bit1 = 3;
4364 s += sprintf (s, "cror %d,%d,%d\n\t", base_bit + 3,
4365 base_bit + bit1, base_bit + bit0);
4366 ccode = "so";
4368 else switch (code)
4370 /* Not all of these are actually distinct opcodes, but
4371 we distinguish them for clarity of the resulting assembler. */
4372 case NE: ccode = "ne"; break;
4373 case EQ: ccode = "eq"; break;
4374 case GE: case GEU: ccode = "ge"; break;
4375 case GT: case GTU: ccode = "gt"; break;
4376 case LE: case LEU: ccode = "le"; break;
4377 case LT: case LTU: ccode = "lt"; break;
4378 case UNORDERED: ccode = "un"; break;
4379 case ORDERED: ccode = "nu"; break;
4380 case UNGE: ccode = "nl"; break;
4381 case UNLE: ccode = "ng"; break;
4382 default:
4383 abort();
4386 /* Maybe we have a guess as to how likely the branch is.
4387 The old mnemonics don't have a way to specify this information. */
4388 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
4389 if (note != NULL_RTX)
4391 /* PROB is the difference from 50%. */
4392 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
4394 /* For branches that are very close to 50%, assume not-taken. */
4395 if (abs (prob) > REG_BR_PROB_BASE / 20
4396 && ((prob > 0) ^ need_longbranch))
4397 pred = "+";
4398 else
4399 pred = "-";
4401 else
4402 pred = "";
4404 if (label == NULL)
4405 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
4406 else
4407 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
4409 /* We need to escape any '%' characters in the reg_names string.
4410 Assume they'd only be the first character... */
4411 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
4412 *s++ = '%';
4413 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
4415 if (label != NULL)
4417 /* If the branch distance was too far, we may have to use an
4418 unconditional branch to go the distance. */
4419 if (need_longbranch)
4420 s += sprintf (s, ",%c$+8 ; b %s", '%', label);
4421 else
4422 s += sprintf (s, ",%s", label);
4425 return string;
4428 /* This page contains routines that are used to determine what the function
4429 prologue and epilogue code will do and write them out. */
4431 /* Return the first fixed-point register that is required to be saved. 32 if
4432 none. */
4435 first_reg_to_save ()
4437 int first_reg;
4439 /* Find lowest numbered live register. */
4440 for (first_reg = 13; first_reg <= 31; first_reg++)
4441 if (regs_ever_live[first_reg]
4442 && (! call_used_regs[first_reg]
4443 || (first_reg == PIC_OFFSET_TABLE_REGNUM
4444 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4445 && flag_pic == 1)))
4446 break;
4448 if (profile_flag)
4450 /* AIX must save/restore every register that contains a parameter
4451 before/after the .__mcount call plus an additional register
4452 for the static chain, if needed; use registers from 30 down to 22
4453 to do this. */
4454 if (DEFAULT_ABI == ABI_AIX)
4456 int last_parm_reg, profile_first_reg;
4458 /* Figure out last used parameter register. The proper thing
4459 to do is to walk incoming args of the function. A function
4460 might have live parameter registers even if it has no
4461 incoming args. */
4462 for (last_parm_reg = 10;
4463 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4464 last_parm_reg--)
4467 /* Calculate first reg for saving parameter registers
4468 and static chain.
4469 Skip reg 31 which may contain the frame pointer. */
4470 profile_first_reg = (33 - last_parm_reg
4471 - (current_function_needs_context ? 1 : 0));
4472 /* Do not save frame pointer if no parameters needs to be saved. */
4473 if (profile_first_reg == 31)
4474 profile_first_reg = 32;
4476 if (first_reg > profile_first_reg)
4477 first_reg = profile_first_reg;
4480 /* SVR4 may need one register to preserve the static chain. */
4481 else if (current_function_needs_context)
4483 /* Skip reg 31 which may contain the frame pointer. */
4484 if (first_reg > 30)
4485 first_reg = 30;
4489 return first_reg;
4492 /* Similar, for FP regs. */
4495 first_fp_reg_to_save ()
4497 int first_reg;
4499 /* Find lowest numbered live register. */
4500 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
4501 if (regs_ever_live[first_reg])
4502 break;
4504 return first_reg;
4507 /* Calculate the stack information for the current function. This is
4508 complicated by having two separate calling sequences, the AIX calling
4509 sequence and the V.4 calling sequence.
4511 AIX stack frames look like:
4512 32-bit 64-bit
4513 SP----> +---------------------------------------+
4514 | back chain to caller | 0 0
4515 +---------------------------------------+
4516 | saved CR | 4 8 (8-11)
4517 +---------------------------------------+
4518 | saved LR | 8 16
4519 +---------------------------------------+
4520 | reserved for compilers | 12 24
4521 +---------------------------------------+
4522 | reserved for binders | 16 32
4523 +---------------------------------------+
4524 | saved TOC pointer | 20 40
4525 +---------------------------------------+
4526 | Parameter save area (P) | 24 48
4527 +---------------------------------------+
4528 | Alloca space (A) | 24+P etc.
4529 +---------------------------------------+
4530 | Local variable space (L) | 24+P+A
4531 +---------------------------------------+
4532 | Float/int conversion temporary (X) | 24+P+A+L
4533 +---------------------------------------+
4534 | Save area for GP registers (G) | 24+P+A+X+L
4535 +---------------------------------------+
4536 | Save area for FP registers (F) | 24+P+A+X+L+G
4537 +---------------------------------------+
4538 old SP->| back chain to caller's caller |
4539 +---------------------------------------+
4541 The required alignment for AIX configurations is two words (i.e., 8
4542 or 16 bytes).
4545 V.4 stack frames look like:
4547 SP----> +---------------------------------------+
4548 | back chain to caller | 0
4549 +---------------------------------------+
4550 | caller's saved LR | 4
4551 +---------------------------------------+
4552 | Parameter save area (P) | 8
4553 +---------------------------------------+
4554 | Alloca space (A) | 8+P
4555 +---------------------------------------+
4556 | Varargs save area (V) | 8+P+A
4557 +---------------------------------------+
4558 | Local variable space (L) | 8+P+A+V
4559 +---------------------------------------+
4560 | Float/int conversion temporary (X) | 8+P+A+V+L
4561 +---------------------------------------+
4562 | saved CR (C) | 8+P+A+V+L+X
4563 +---------------------------------------+
4564 | Save area for GP registers (G) | 8+P+A+V+L+X+C
4565 +---------------------------------------+
4566 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
4567 +---------------------------------------+
4568 old SP->| back chain to caller's caller |
4569 +---------------------------------------+
4571 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
4572 given. (But note below and in sysv4.h that we require only 8 and
4573 may round up the size of our stack frame anyways. The historical
4574 reason is early versions of powerpc-linux which didn't properly
4575 align the stack at program startup. A happy side-effect is that
4576 -mno-eabi libraries can be used with -meabi programs.)
4579 The EABI configuration defaults to the V.4 layout, unless
4580 -mcall-aix is used, in which case the AIX layout is used. However,
4581 the stack alignment requirements may differ. If -mno-eabi is not
4582 given, the required stack alignment is 8 bytes; if -mno-eabi is
4583 given, the required alignment is 16 bytes. (But see V.4 comment
4584 above.) */
4586 #ifndef ABI_STACK_BOUNDARY
4587 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
4588 #endif
4590 rs6000_stack_t *
4591 rs6000_stack_info ()
4593 static rs6000_stack_t info, zero_info;
4594 rs6000_stack_t *info_ptr = &info;
4595 int reg_size = TARGET_POWERPC64 ? 8 : 4;
4596 enum rs6000_abi abi;
4597 int total_raw_size;
4599 /* Zero all fields portably */
4600 info = zero_info;
4602 /* Select which calling sequence */
4603 info_ptr->abi = abi = DEFAULT_ABI;
4605 /* Calculate which registers need to be saved & save area size */
4606 info_ptr->first_gp_reg_save = first_reg_to_save ();
4607 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
4608 even if it currently looks like we won't. */
4609 if (flag_pic == 1
4610 && (abi == ABI_V4 || abi == ABI_SOLARIS)
4611 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
4612 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
4613 else
4614 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4616 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
4617 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
4619 /* Does this function call anything? */
4620 info_ptr->calls_p = ! current_function_is_leaf;
4622 /* Determine if we need to save the link register */
4623 if (regs_ever_live[LINK_REGISTER_REGNUM]
4624 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4625 #ifdef TARGET_RELOCATABLE
4626 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
4627 #endif
4628 || (info_ptr->first_fp_reg_save != 64
4629 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
4630 || (abi == ABI_V4 && current_function_calls_alloca)
4631 || (abi == ABI_SOLARIS && current_function_calls_alloca)
4632 || info_ptr->calls_p)
4634 info_ptr->lr_save_p = 1;
4635 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4638 /* Determine if we need to save the condition code registers. */
4639 if (regs_ever_live[CR2_REGNO]
4640 || regs_ever_live[CR3_REGNO]
4641 || regs_ever_live[CR4_REGNO])
4643 info_ptr->cr_save_p = 1;
4644 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4645 info_ptr->cr_size = reg_size;
4648 /* Determine various sizes */
4649 info_ptr->reg_size = reg_size;
4650 info_ptr->fixed_size = RS6000_SAVE_AREA;
4651 info_ptr->varargs_size = RS6000_VARARGS_AREA;
4652 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
4653 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
4654 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
4655 + info_ptr->gp_size
4656 + info_ptr->cr_size
4657 + info_ptr->lr_size
4658 + info_ptr->toc_size, 8);
4660 /* Calculate the offsets */
4661 switch (abi)
4663 case ABI_NONE:
4664 default:
4665 abort ();
4667 case ABI_AIX:
4668 case ABI_AIX_NODESC:
4669 info_ptr->fp_save_offset = - info_ptr->fp_size;
4670 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
4671 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
4672 info_ptr->lr_save_offset = 2*reg_size;
4673 break;
4675 case ABI_V4:
4676 case ABI_SOLARIS:
4677 info_ptr->fp_save_offset = - info_ptr->fp_size;
4678 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
4679 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
4680 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
4681 info_ptr->lr_save_offset = reg_size;
4682 break;
4685 total_raw_size = (info_ptr->vars_size
4686 + info_ptr->parm_size
4687 + info_ptr->save_size
4688 + info_ptr->varargs_size
4689 + info_ptr->fixed_size);
4691 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
4693 /* Determine if we need to allocate any stack frame:
4695 For AIX we need to push the stack if a frame pointer is needed (because
4696 the stack might be dynamically adjusted), if we are debugging, if we
4697 make calls, or if the sum of fp_save, gp_save, and local variables
4698 are more than the space needed to save all non-volatile registers:
4699 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved).
4701 For V.4 we don't have the stack cushion that AIX uses, but assume that
4702 the debugger can handle stackless frames. */
4704 if (info_ptr->calls_p)
4705 info_ptr->push_p = 1;
4707 else if (abi == ABI_V4 || abi == ABI_SOLARIS)
4708 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
4709 || info_ptr->calls_p);
4711 else
4712 info_ptr->push_p = (frame_pointer_needed
4713 || write_symbols != NO_DEBUG
4714 || ((total_raw_size - info_ptr->fixed_size)
4715 > (TARGET_32BIT ? 220 : 288)));
4717 /* Zero offsets if we're not saving those registers */
4718 if (info_ptr->fp_size == 0)
4719 info_ptr->fp_save_offset = 0;
4721 if (info_ptr->gp_size == 0)
4722 info_ptr->gp_save_offset = 0;
4724 if (! info_ptr->lr_save_p)
4725 info_ptr->lr_save_offset = 0;
4727 if (! info_ptr->cr_save_p)
4728 info_ptr->cr_save_offset = 0;
4730 if (! info_ptr->toc_save_p)
4731 info_ptr->toc_save_offset = 0;
4733 return info_ptr;
4736 void
4737 debug_stack_info (info)
4738 rs6000_stack_t *info;
4740 const char *abi_string;
4742 if (! info)
4743 info = rs6000_stack_info ();
4745 fprintf (stderr, "\nStack information for function %s:\n",
4746 ((current_function_decl && DECL_NAME (current_function_decl))
4747 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
4748 : "<unknown>"));
4750 switch (info->abi)
4752 default: abi_string = "Unknown"; break;
4753 case ABI_NONE: abi_string = "NONE"; break;
4754 case ABI_AIX: abi_string = "AIX"; break;
4755 case ABI_AIX_NODESC: abi_string = "AIX"; break;
4756 case ABI_V4: abi_string = "V.4"; break;
4757 case ABI_SOLARIS: abi_string = "Solaris"; break;
4760 fprintf (stderr, "\tABI = %5s\n", abi_string);
4762 if (info->first_gp_reg_save != 32)
4763 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
4765 if (info->first_fp_reg_save != 64)
4766 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
4768 if (info->lr_save_p)
4769 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
4771 if (info->cr_save_p)
4772 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
4774 if (info->toc_save_p)
4775 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
4777 if (info->push_p)
4778 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
4780 if (info->calls_p)
4781 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
4783 if (info->gp_save_offset)
4784 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
4786 if (info->fp_save_offset)
4787 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
4789 if (info->lr_save_offset)
4790 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
4792 if (info->cr_save_offset)
4793 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
4795 if (info->toc_save_offset)
4796 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
4798 if (info->varargs_save_offset)
4799 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
4801 if (info->total_size)
4802 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
4804 if (info->varargs_size)
4805 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
4807 if (info->vars_size)
4808 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
4810 if (info->parm_size)
4811 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
4813 if (info->fixed_size)
4814 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
4816 if (info->gp_size)
4817 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
4819 if (info->fp_size)
4820 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
4822 if (info->lr_size)
4823 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
4825 if (info->cr_size)
4826 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
4828 if (info->toc_size)
4829 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
4831 if (info->save_size)
4832 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
4834 if (info->reg_size != 4)
4835 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
4837 fprintf (stderr, "\n");
4840 /* Emit instructions needed to load the TOC register.
4841 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
4842 a constant pool; or for SVR4 -fpic. */
4844 void
4845 rs6000_emit_load_toc_table (fromprolog)
4846 int fromprolog;
4848 rtx dest;
4849 dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4851 if (TARGET_ELF)
4853 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4854 && flag_pic == 1)
4856 rtx temp = (fromprolog
4857 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
4858 : gen_reg_rtx (Pmode));
4859 if (TARGET_32BIT)
4860 emit_insn (gen_load_toc_v4_pic_si (temp));
4861 else
4862 emit_insn (gen_load_toc_v4_pic_di (temp));
4863 emit_move_insn (dest, temp);
4865 else if (flag_pic == 2)
4867 char buf[30];
4868 rtx tempLR = (fromprolog
4869 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
4870 : gen_reg_rtx (Pmode));
4871 rtx temp0 = (fromprolog
4872 ? gen_rtx_REG (Pmode, 0)
4873 : gen_reg_rtx (Pmode));
4874 rtx symF;
4876 /* possibly create the toc section */
4877 if (! toc_initialized)
4879 toc_section ();
4880 function_section (current_function_decl);
4883 if (fromprolog)
4885 rtx symL;
4887 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
4888 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1));
4890 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
4891 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1));
4893 emit_insn (gen_load_toc_v4_PIC_1 (tempLR, symF));
4894 emit_move_insn (dest, tempLR);
4895 emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, symL, symF));
4897 else
4899 rtx tocsym;
4900 static int reload_toc_labelno = 0;
4902 tocsym = gen_rtx_SYMBOL_REF (Pmode,
4903 ggc_alloc_string (toc_label_name, -1));
4905 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
4906 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1));
4908 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
4909 emit_move_insn (dest, tempLR);
4910 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
4912 emit_insn (gen_addsi3 (dest, temp0, dest));
4914 else if (flag_pic == 0 && TARGET_MINIMAL_TOC)
4916 /* This is for AIX code running in non-PIC ELF. */
4917 char buf[30];
4918 rtx realsym;
4919 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
4920 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1));
4922 emit_insn (gen_elf_high (dest, realsym));
4923 emit_insn (gen_elf_low (dest, dest, realsym));
4925 else
4926 abort();
4928 else
4930 if (TARGET_32BIT)
4931 emit_insn (gen_load_toc_aix_si (dest));
4932 else
4933 emit_insn (gen_load_toc_aix_di (dest));
4937 int
4938 get_TOC_alias_set ()
4940 static int set = -1;
4941 if (set == -1)
4942 set = new_alias_set ();
4943 return set;
4946 /* This retuns nonzero if the current function uses the TOC. This is
4947 determined by the presence of (unspec ... 7), which is generated by
4948 the various load_toc_* patterns. */
4950 uses_TOC ()
4952 rtx insn;
4954 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4955 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
4957 rtx pat = PATTERN (insn);
4958 int i;
4960 if (GET_CODE(pat) == PARALLEL)
4961 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
4962 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
4963 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
4964 return 1;
4966 return 0;
4970 create_TOC_reference(symbol)
4971 rtx symbol;
4973 return gen_rtx_PLUS (Pmode,
4974 gen_rtx_REG (Pmode, TOC_REGISTER),
4975 gen_rtx_CONST (Pmode,
4976 gen_rtx_MINUS (Pmode, symbol,
4977 gen_rtx_SYMBOL_REF (Pmode,
4978 ggc_alloc_string (toc_label_name, -1)))));
4981 #if TARGET_AIX
4982 /* __throw will restore its own return address to be the same as the
4983 return address of the function that the throw is being made to.
4984 This is unfortunate, because we want to check the original
4985 return address to see if we need to restore the TOC.
4986 So we have to squirrel it away here.
4987 This is used only in compiling __throw and __rethrow.
4989 Most of this code should be removed by CSE. */
4990 static rtx insn_after_throw;
4992 /* This does the saving... */
4993 void
4994 rs6000_aix_emit_builtin_unwind_init ()
4996 rtx mem;
4997 rtx stack_top = gen_reg_rtx (Pmode);
4998 rtx opcode_addr = gen_reg_rtx (Pmode);
5000 insn_after_throw = gen_reg_rtx (SImode);
5002 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5003 emit_move_insn (stack_top, mem);
5005 mem = gen_rtx_MEM (Pmode,
5006 gen_rtx_PLUS (Pmode, stack_top,
5007 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5008 emit_move_insn (opcode_addr, mem);
5009 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
5012 /* Emit insns to _restore_ the TOC register, at runtime (specifically in _eh.o).
5013 Only used on AIX.
5015 The idea is that on AIX, function calls look like this:
5016 bl somefunction-trampoline
5017 lwz r2,20(sp)
5019 and later,
5020 somefunction-trampoline:
5021 stw r2,20(sp)
5022 ... load function address in the count register ...
5023 bctr
5024 or like this, if the linker determines that this is not a cross-module call
5025 and so the TOC need not be restored:
5026 bl somefunction
5028 or like this, if the compiler could determine that this is not a
5029 cross-module call:
5030 bl somefunction
5031 now, the tricky bit here is that register 2 is saved and restored
5032 by the _linker_, so we can't readily generate debugging information
5033 for it. So we need to go back up the call chain looking at the
5034 insns at return addresses to see which calls saved the TOC register
5035 and so see where it gets restored from.
5037 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
5038 just before the actual epilogue.
5040 On the bright side, this incurs no space or time overhead unless an
5041 exception is thrown, except for the extra code in libgcc.a.
5043 The parameter STACKSIZE is a register containing (at runtime)
5044 the amount to be popped off the stack in addition to the stack frame
5045 of this routine (which will be __throw or __rethrow, and so is
5046 guaranteed to have a stack frame). */
5047 void
5048 rs6000_emit_eh_toc_restore (stacksize)
5049 rtx stacksize;
5051 rtx top_of_stack;
5052 rtx bottom_of_stack = gen_reg_rtx (Pmode);
5053 rtx tocompare = gen_reg_rtx (SImode);
5054 rtx opcode = gen_reg_rtx (SImode);
5055 rtx opcode_addr = gen_reg_rtx (Pmode);
5056 rtx mem;
5057 rtx loop_start = gen_label_rtx ();
5058 rtx no_toc_restore_needed = gen_label_rtx ();
5059 rtx loop_exit = gen_label_rtx ();
5061 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5062 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5063 emit_move_insn (bottom_of_stack, mem);
5065 top_of_stack = expand_binop (Pmode, add_optab,
5066 bottom_of_stack, stacksize,
5067 NULL_RTX, 1, OPTAB_WIDEN);
5069 emit_move_insn (tocompare,
5070 GEN_INT (trunc_int_for_mode (TARGET_32BIT
5071 ? 0x80410014
5072 : 0xE8410028, SImode)));
5074 if (insn_after_throw == NULL_RTX)
5075 abort();
5076 emit_move_insn (opcode, insn_after_throw);
5078 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
5079 emit_label (loop_start);
5081 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
5082 SImode, NULL_RTX, 0, NULL_RTX,
5083 no_toc_restore_needed);
5085 mem = gen_rtx_MEM (Pmode,
5086 gen_rtx_PLUS (Pmode, bottom_of_stack,
5087 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
5088 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
5090 emit_label (no_toc_restore_needed);
5091 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
5092 Pmode, NULL_RTX, 0, NULL_RTX,
5093 loop_exit);
5095 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
5096 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5097 emit_move_insn (bottom_of_stack, mem);
5099 mem = gen_rtx_MEM (Pmode,
5100 gen_rtx_PLUS (Pmode, bottom_of_stack,
5101 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5102 emit_move_insn (opcode_addr, mem);
5103 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
5105 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
5106 emit_jump (loop_start);
5107 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
5108 emit_label (loop_exit);
5110 #endif /* TARGET_AIX */
5112 /* This ties together stack memory
5113 (MEM with an alias set of rs6000_sr_alias_set)
5114 and the change to the stack pointer. */
5115 static void
5116 rs6000_emit_stack_tie ()
5118 rtx mem;
5119 mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
5120 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5121 emit_insn (gen_stack_tie (mem));
5124 /* Emit the correct code for allocating stack space, as insns.
5125 If COPY_R12, make sure a copy of the old frame is left in r12.
5126 The generated code may use hard register 0 as a temporary. */
5128 static void
5129 rs6000_emit_allocate_stack (size, copy_r12)
5130 HOST_WIDE_INT size;
5131 int copy_r12;
5133 rtx insn;
5134 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5135 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
5136 rtx todec = GEN_INT (-size);
5138 if (current_function_limit_stack)
5140 if (REG_P (stack_limit_rtx)
5141 && REGNO (stack_limit_rtx) > 1
5142 && REGNO (stack_limit_rtx) <= 31)
5144 emit_insn (Pmode == SImode
5145 ? gen_addsi3 (tmp_reg,
5146 stack_limit_rtx,
5147 GEN_INT (size))
5148 : gen_adddi3 (tmp_reg,
5149 stack_limit_rtx,
5150 GEN_INT (size)));
5152 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5153 const0_rtx));
5155 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
5156 && TARGET_32BIT
5157 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5159 rtx toload = gen_rtx_CONST (VOIDmode,
5160 gen_rtx_PLUS (Pmode,
5161 stack_limit_rtx,
5162 GEN_INT (size)));
5164 emit_insn (gen_elf_high (tmp_reg, toload));
5165 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
5166 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5167 const0_rtx));
5169 else
5170 warning ("stack limit expression is not supported");
5173 if (copy_r12 || ! TARGET_UPDATE)
5174 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
5176 if (TARGET_UPDATE)
5178 if (size > 32767)
5180 /* Need a note here so that try_split doesn't get confused. */
5181 if (get_last_insn() == NULL_RTX)
5182 emit_note (0, NOTE_INSN_DELETED);
5183 insn = emit_move_insn (tmp_reg, todec);
5184 try_split (PATTERN (insn), insn, 0);
5185 todec = tmp_reg;
5188 if (Pmode == SImode)
5189 insn = emit_insn (gen_movsi_update (stack_reg, stack_reg,
5190 todec, stack_reg));
5191 else
5192 insn = emit_insn (gen_movdi_update (stack_reg, stack_reg,
5193 todec, stack_reg));
5195 else
5197 if (Pmode == SImode)
5198 insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec));
5199 else
5200 insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec));
5201 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
5202 gen_rtx_REG (Pmode, 12));
5205 RTX_FRAME_RELATED_P (insn) = 1;
5206 REG_NOTES (insn) =
5207 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5208 gen_rtx_SET (VOIDmode, stack_reg,
5209 gen_rtx_PLUS (Pmode, stack_reg,
5210 GEN_INT (-size))),
5211 REG_NOTES (insn));
5214 /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced with
5215 (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 is not
5216 NULL.
5217 It would be nice if dwarf2out_frame_debug_expr could deduce these
5218 equivalences by itself so it wasn't necessary to hold its hand so much. */
5220 static void
5221 rs6000_frame_related (insn, reg, val, reg2, rreg)
5222 rtx insn;
5223 rtx reg;
5224 HOST_WIDE_INT val;
5225 rtx reg2;
5226 rtx rreg;
5228 rtx real, temp;
5230 real = copy_rtx (PATTERN (insn));
5232 real = replace_rtx (real, reg,
5233 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
5234 STACK_POINTER_REGNUM),
5235 GEN_INT (val)));
5237 /* We expect that 'real' is either a SET or a PARALLEL containing
5238 SETs (and possibly other stuff). In a PARALLEL, all the SETs
5239 are important so they all have to be marked RTX_FRAME_RELATED_P. */
5241 if (GET_CODE (real) == SET)
5243 rtx set = real;
5245 temp = simplify_rtx (SET_SRC (set));
5246 if (temp)
5247 SET_SRC (set) = temp;
5248 temp = simplify_rtx (SET_DEST (set));
5249 if (temp)
5250 SET_DEST (set) = temp;
5251 if (GET_CODE (SET_DEST (set)) == MEM)
5253 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5254 if (temp)
5255 XEXP (SET_DEST (set), 0) = temp;
5258 else if (GET_CODE (real) == PARALLEL)
5260 int i;
5261 for (i = 0; i < XVECLEN (real, 0); i++)
5262 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
5264 rtx set = XVECEXP (real, 0, i);
5266 temp = simplify_rtx (SET_SRC (set));
5267 if (temp)
5268 SET_SRC (set) = temp;
5269 temp = simplify_rtx (SET_DEST (set));
5270 if (temp)
5271 SET_DEST (set) = temp;
5272 if (GET_CODE (SET_DEST (set)) == MEM)
5274 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5275 if (temp)
5276 XEXP (SET_DEST (set), 0) = temp;
5278 RTX_FRAME_RELATED_P (set) = 1;
5281 else
5282 abort();
5284 if (reg2 != NULL_RTX)
5285 real = replace_rtx (real, reg2, rreg);
5287 RTX_FRAME_RELATED_P (insn) = 1;
5288 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5289 real,
5290 REG_NOTES (insn));
5293 /* Emit function prologue as insns. */
5295 void
5296 rs6000_emit_prologue()
5298 rs6000_stack_t *info = rs6000_stack_info ();
5299 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5300 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5301 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5302 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
5303 rtx frame_reg_rtx = sp_reg_rtx;
5304 rtx cr_save_rtx = NULL;
5305 rtx insn;
5306 int saving_FPRs_inline;
5307 int using_store_multiple;
5308 HOST_WIDE_INT sp_offset = 0;
5310 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5311 && info->first_gp_reg_save < 31);
5312 saving_FPRs_inline = (info->first_fp_reg_save == 64
5313 || FP_SAVE_INLINE (info->first_fp_reg_save));
5315 /* For V.4, update stack before we do any saving and set back pointer. */
5316 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5318 if (info->total_size < 32767)
5319 sp_offset = info->total_size;
5320 else
5321 frame_reg_rtx = frame_ptr_rtx;
5322 rs6000_emit_allocate_stack (info->total_size,
5323 (frame_reg_rtx != sp_reg_rtx
5324 && (info->cr_save_p
5325 || info->lr_save_p
5326 || info->first_fp_reg_save < 64
5327 || info->first_gp_reg_save < 32
5328 )));
5329 if (frame_reg_rtx != sp_reg_rtx)
5330 rs6000_emit_stack_tie ();
5333 /* If we use the link register, get it into r0. */
5334 if (info->lr_save_p)
5335 emit_move_insn (gen_rtx_REG (Pmode, 0),
5336 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5338 /* If we need to save CR, put it into r12. */
5339 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
5341 cr_save_rtx = gen_rtx_REG (SImode, 12);
5342 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5345 /* Do any required saving of fpr's. If only one or two to save, do it
5346 ourself. Otherwise, call function. */
5347 if (saving_FPRs_inline)
5349 int i;
5350 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5351 if ((regs_ever_live[info->first_fp_reg_save+i]
5352 && ! call_used_regs[info->first_fp_reg_save+i]))
5354 rtx addr, reg, mem;
5355 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5356 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5357 GEN_INT (info->fp_save_offset
5358 + sp_offset
5359 + 8*i));
5360 mem = gen_rtx_MEM (DFmode, addr);
5361 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5363 insn = emit_move_insn (mem, reg);
5364 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5365 NULL_RTX, NULL_RTX);
5368 else if (info->first_fp_reg_save != 64)
5370 int i;
5371 char rname[30];
5372 char *alloc_rname;
5373 rtvec p;
5374 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
5376 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
5377 gen_rtx_REG (Pmode,
5378 LINK_REGISTER_REGNUM));
5379 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
5380 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
5381 alloc_rname = ggc_alloc_string (rname, -1);
5382 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
5383 gen_rtx_SYMBOL_REF (Pmode,
5384 alloc_rname));
5385 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5387 rtx addr, reg, mem;
5388 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5389 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5390 GEN_INT (info->fp_save_offset
5391 + sp_offset + 8*i));
5392 mem = gen_rtx_MEM (DFmode, addr);
5393 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5395 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
5397 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5398 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5399 NULL_RTX, NULL_RTX);
5402 /* Save GPRs. This is done as a PARALLEL if we are using
5403 the store-multiple instructions. */
5404 if (using_store_multiple)
5406 rtvec p, dwarfp;
5407 int i;
5408 p = rtvec_alloc (32 - info->first_gp_reg_save);
5409 dwarfp = rtvec_alloc (32 - info->first_gp_reg_save);
5410 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5412 rtx addr, reg, mem;
5413 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5414 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5415 GEN_INT (info->gp_save_offset
5416 + sp_offset
5417 + reg_size * i));
5418 mem = gen_rtx_MEM (reg_mode, addr);
5419 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5421 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
5423 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5424 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5425 NULL_RTX, NULL_RTX);
5427 else
5429 int i;
5430 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5431 if ((regs_ever_live[info->first_gp_reg_save+i]
5432 && ! call_used_regs[info->first_gp_reg_save+i])
5433 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
5434 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5435 && flag_pic == 1))
5437 rtx addr, reg, mem;
5438 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5439 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5440 GEN_INT (info->gp_save_offset
5441 + sp_offset
5442 + reg_size * i));
5443 mem = gen_rtx_MEM (reg_mode, addr);
5444 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5446 insn = emit_move_insn (mem, reg);
5447 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5448 NULL_RTX, NULL_RTX);
5452 /* Save lr if we used it. */
5453 if (info->lr_save_p)
5455 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5456 GEN_INT (info->lr_save_offset + sp_offset));
5457 rtx reg = gen_rtx_REG (Pmode, 0);
5458 rtx mem = gen_rtx_MEM (Pmode, addr);
5459 /* This should not be of rs6000_sr_alias_set, because of
5460 __builtin_return_address. */
5462 insn = emit_move_insn (mem, reg);
5463 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5464 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5467 /* Save CR if we use any that must be preserved. */
5468 if (info->cr_save_p)
5470 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5471 GEN_INT (info->cr_save_offset + sp_offset));
5472 rtx mem = gen_rtx_MEM (SImode, addr);
5473 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5475 /* If r12 was used to hold the original sp, copy cr into r0 now
5476 that it's free. */
5477 if (REGNO (frame_reg_rtx) == 12)
5479 cr_save_rtx = gen_rtx_REG (SImode, 0);
5480 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5482 insn = emit_move_insn (mem, cr_save_rtx);
5484 /* Now, there's no way that dwarf2out_frame_debug_expr is going
5485 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
5486 OK. All we have to do is specify that _one_ condition code
5487 register is saved in this stack slot. The thrower's epilogue
5488 will then restore all the call-saved registers. */
5489 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5490 cr_save_rtx, gen_rtx_REG (SImode, CR0_REGNO));
5493 /* Update stack and set back pointer unless this is V.4,
5494 for which it was done previously. */
5495 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
5496 rs6000_emit_allocate_stack (info->total_size, FALSE);
5498 /* Set frame pointer, if needed. */
5499 if (frame_pointer_needed)
5501 insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM),
5502 sp_reg_rtx);
5503 RTX_FRAME_RELATED_P (insn) = 1;
5506 /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
5507 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
5508 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5509 && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
5511 /* If emit_load_toc_table will use the link register, we need to save
5512 it. We use R11 for this purpose because emit_load_toc_table
5513 can use register 0. This allows us to use a plain 'blr' to return
5514 from the procedure more often. */
5515 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 &&
5516 ! info->lr_save_p);
5517 if (save_LR_around_toc_setup)
5518 emit_move_insn (gen_rtx_REG (Pmode, 11),
5519 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5521 rs6000_emit_load_toc_table (TRUE);
5523 if (save_LR_around_toc_setup)
5524 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5525 gen_rtx_REG (Pmode, 11));
5530 /* Write function prologue. */
5531 void
5532 output_prolog (file, size)
5533 FILE *file;
5534 int size ATTRIBUTE_UNUSED;
5536 rs6000_stack_t *info = rs6000_stack_info ();
5538 if (TARGET_DEBUG_STACK)
5539 debug_stack_info (info);
5541 /* Write .extern for any function we will call to save and restore fp
5542 values. */
5543 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
5544 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
5545 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
5546 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
5548 /* Write .extern for truncation routines, if needed. */
5549 if (rs6000_trunc_used && ! trunc_defined)
5551 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
5552 RS6000_ITRUNC, RS6000_UITRUNC);
5553 trunc_defined = 1;
5556 /* Write .extern for AIX common mode routines, if needed. */
5557 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
5559 fputs ("\t.extern __mulh\n", file);
5560 fputs ("\t.extern __mull\n", file);
5561 fputs ("\t.extern __divss\n", file);
5562 fputs ("\t.extern __divus\n", file);
5563 fputs ("\t.extern __quoss\n", file);
5564 fputs ("\t.extern __quous\n", file);
5565 common_mode_defined = 1;
5568 if (! HAVE_prologue)
5570 start_sequence ();
5572 /* A NOTE_INSN_DELETED is supposed to be at the start
5573 and end of the "toplevel" insn chain. */
5574 emit_note (0, NOTE_INSN_DELETED);
5575 rs6000_emit_prologue ();
5576 emit_note (0, NOTE_INSN_DELETED);
5578 if (TARGET_DEBUG_STACK)
5579 debug_rtx_list (get_insns(), 100);
5580 final (get_insns(), file, FALSE, FALSE);
5581 end_sequence ();
5584 rs6000_pic_labelno++;
5587 /* Emit function epilogue as insns.
5589 At present, dwarf2out_frame_debug_expr doesn't understand
5590 register restores, so we don't bother setting RTX_FRAME_RELATED_P
5591 anywhere in the epilogue. Most of the insns below would in any case
5592 need special notes to explain where r11 is in relation to the stack. */
5594 void
5595 rs6000_emit_epilogue(sibcall)
5596 int sibcall;
5598 rs6000_stack_t *info;
5599 int restoring_FPRs_inline;
5600 int using_load_multiple;
5601 int using_mfcr_multiple;
5602 int use_backchain_to_restore_sp;
5603 int sp_offset = 0;
5604 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
5605 rtx frame_reg_rtx = sp_reg_rtx;
5606 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5607 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5608 int i;
5610 info = rs6000_stack_info ();
5611 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5612 && info->first_gp_reg_save < 31);
5613 restoring_FPRs_inline = (sibcall
5614 || info->first_fp_reg_save == 64
5615 || FP_SAVE_INLINE (info->first_fp_reg_save));
5616 use_backchain_to_restore_sp = (frame_pointer_needed
5617 || current_function_calls_alloca
5618 || info->total_size > 32767);
5619 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
5620 || rs6000_cpu == PROCESSOR_PPC603
5621 || rs6000_cpu == PROCESSOR_PPC750
5622 || optimize_size);
5624 /* If we have a frame pointer, a call to alloca, or a large stack
5625 frame, restore the old stack pointer using the backchain. Otherwise,
5626 we know what size to update it with. */
5627 if (use_backchain_to_restore_sp)
5629 /* Under V.4, don't reset the stack pointer until after we're done
5630 loading the saved registers. */
5631 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5632 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
5634 emit_move_insn (frame_reg_rtx,
5635 gen_rtx_MEM (Pmode, sp_reg_rtx));
5638 else if (info->push_p)
5640 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5641 sp_offset = info->total_size;
5642 else
5644 emit_insn (TARGET_32BIT
5645 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
5646 GEN_INT (info->total_size))
5647 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
5648 GEN_INT (info->total_size)));
5652 /* Get the old lr if we saved it. */
5653 if (info->lr_save_p)
5655 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5656 GEN_INT (info->lr_save_offset + sp_offset));
5657 rtx mem = gen_rtx_MEM (Pmode, addr);
5658 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5660 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
5663 /* Get the old cr if we saved it. */
5664 if (info->cr_save_p)
5666 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5667 GEN_INT (info->cr_save_offset + sp_offset));
5668 rtx mem = gen_rtx_MEM (SImode, addr);
5669 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5671 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
5674 /* Set LR here to try to overlap restores below. */
5675 if (info->lr_save_p)
5676 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5677 gen_rtx_REG (Pmode, 0));
5680 /* Restore GPRs. This is done as a PARALLEL if we are using
5681 the load-multiple instructions. */
5682 if (using_load_multiple)
5684 rtvec p;
5685 p = rtvec_alloc (32 - info->first_gp_reg_save);
5686 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5688 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5689 GEN_INT (info->gp_save_offset
5690 + sp_offset
5691 + reg_size * i));
5692 rtx mem = gen_rtx_MEM (reg_mode, addr);
5693 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5695 RTVEC_ELT (p, i) =
5696 gen_rtx_SET (VOIDmode,
5697 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
5698 mem);
5700 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5702 else
5703 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5704 if ((regs_ever_live[info->first_gp_reg_save+i]
5705 && ! call_used_regs[info->first_gp_reg_save+i])
5706 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
5707 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5708 && flag_pic == 1))
5710 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5711 GEN_INT (info->gp_save_offset
5712 + sp_offset
5713 + reg_size * i));
5714 rtx mem = gen_rtx_MEM (reg_mode, addr);
5715 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5717 emit_move_insn (gen_rtx_REG (reg_mode,
5718 info->first_gp_reg_save + i),
5719 mem);
5722 /* Restore fpr's if we need to do it without calling a function. */
5723 if (restoring_FPRs_inline)
5724 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5725 if ((regs_ever_live[info->first_fp_reg_save+i]
5726 && ! call_used_regs[info->first_fp_reg_save+i]))
5728 rtx addr, mem;
5729 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5730 GEN_INT (info->fp_save_offset
5731 + sp_offset
5732 + 8*i));
5733 mem = gen_rtx_MEM (DFmode, addr);
5734 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5736 emit_move_insn (gen_rtx_REG (DFmode,
5737 info->first_fp_reg_save + i),
5738 mem);
5741 /* If we saved cr, restore it here. Just those that were used. */
5742 if (info->cr_save_p)
5744 rtx r12_rtx = gen_rtx_REG (SImode, 12);
5746 if (using_mfcr_multiple)
5748 rtvec p;
5749 int mask = 0;
5750 int count = 0;
5752 for (i = 0; i < 8; i++)
5753 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
5755 mask |= 1 << (7-i);
5756 count++;
5758 if (count == 0)
5759 abort();
5761 p = rtvec_alloc (count + 1);
5763 RTVEC_ELT (p, 0) = gen_rtx_USE (VOIDmode, GEN_INT (mask));
5764 count = 1;
5765 for (i = 0; i < 8; i++)
5766 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
5768 rtvec r = rtvec_alloc (2);
5769 RTVEC_ELT (r, 0) = r12_rtx;
5770 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
5771 RTVEC_ELT (p, count) =
5772 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
5773 gen_rtx_UNSPEC (CCmode, r, 20));
5774 count++;
5776 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5778 else
5779 for (i = 0; i < 8; i++)
5780 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
5782 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
5783 CR0_REGNO+i),
5784 r12_rtx));
5788 /* If this is V.4, unwind the stack pointer after all of the loads
5789 have been done. We need to emit a block here so that sched
5790 doesn't decide to move the sp change before the register restores
5791 (which may not have any obvious dependency on the stack). This
5792 doesn't hurt performance, because there is no scheduling that can
5793 be done after this point. */
5794 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5796 if (frame_reg_rtx != sp_reg_rtx)
5797 rs6000_emit_stack_tie ();
5799 if (use_backchain_to_restore_sp)
5801 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
5803 else if (sp_offset != 0)
5805 emit_insn (Pmode == SImode
5806 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
5807 GEN_INT (sp_offset))
5808 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
5809 GEN_INT (sp_offset)));
5813 if (!sibcall)
5815 rtvec p;
5816 if (! restoring_FPRs_inline)
5817 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
5818 else
5819 p = rtvec_alloc (2);
5821 RTVEC_ELT (p, 0) = gen_rtx_USE (VOIDmode,
5822 gen_rtx_REG (Pmode,
5823 LINK_REGISTER_REGNUM));
5824 RTVEC_ELT (p, 1) = gen_rtx_RETURN (VOIDmode);
5826 /* If we have to restore more than two FP registers, branch to the
5827 restore function. It will return to our caller. */
5828 if (! restoring_FPRs_inline)
5830 int i;
5831 char rname[30];
5832 char *alloc_rname;
5834 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
5835 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
5836 alloc_rname = ggc_alloc_string (rname, -1);
5837 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
5838 gen_rtx_SYMBOL_REF (Pmode,
5839 alloc_rname));
5841 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5843 rtx addr, mem;
5844 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
5845 GEN_INT (info->fp_save_offset + 8*i));
5846 mem = gen_rtx_MEM (DFmode, addr);
5847 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5849 RTVEC_ELT (p, i+3) =
5850 gen_rtx_SET (VOIDmode,
5851 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
5852 mem);
5856 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
5860 /* Write function epilogue. */
5862 void
5863 output_epilog (file, size)
5864 FILE *file;
5865 int size ATTRIBUTE_UNUSED;
5867 rs6000_stack_t *info = rs6000_stack_info ();
5869 if (! HAVE_epilogue)
5871 rtx insn = get_last_insn ();
5872 /* If the last insn was a BARRIER, we don't have to write anything except
5873 the trace table. */
5874 if (GET_CODE (insn) == NOTE)
5875 insn = prev_nonnote_insn (insn);
5876 if (insn == 0 || GET_CODE (insn) != BARRIER)
5878 /* This is slightly ugly, but at least we don't have two
5879 copies of the epilogue-emitting code. */
5880 start_sequence ();
5882 /* A NOTE_INSN_DELETED is supposed to be at the start
5883 and end of the "toplevel" insn chain. */
5884 emit_note (0, NOTE_INSN_DELETED);
5885 rs6000_emit_epilogue (FALSE);
5886 emit_note (0, NOTE_INSN_DELETED);
5888 if (TARGET_DEBUG_STACK)
5889 debug_rtx_list (get_insns(), 100);
5890 final (get_insns(), file, FALSE, FALSE);
5891 end_sequence ();
5895 /* Output a traceback table here. See /usr/include/sys/debug.h for info
5896 on its format.
5898 We don't output a traceback table if -finhibit-size-directive was
5899 used. The documentation for -finhibit-size-directive reads
5900 ``don't output a @code{.size} assembler directive, or anything
5901 else that would cause trouble if the function is split in the
5902 middle, and the two halves are placed at locations far apart in
5903 memory.'' The traceback table has this property, since it
5904 includes the offset from the start of the function to the
5905 traceback table itself.
5907 System V.4 Powerpc's (and the embedded ABI derived from it) use a
5908 different traceback table. */
5909 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
5911 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
5912 int fixed_parms, float_parms, parm_info;
5913 int i;
5915 while (*fname == '.') /* V.4 encodes . in the name */
5916 fname++;
5918 /* Need label immediately before tbtab, so we can compute its offset
5919 from the function start. */
5920 if (*fname == '*')
5921 ++fname;
5922 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
5923 ASM_OUTPUT_LABEL (file, fname);
5925 /* The .tbtab pseudo-op can only be used for the first eight
5926 expressions, since it can't handle the possibly variable
5927 length fields that follow. However, if you omit the optional
5928 fields, the assembler outputs zeros for all optional fields
5929 anyways, giving each variable length field is minimum length
5930 (as defined in sys/debug.h). Thus we can not use the .tbtab
5931 pseudo-op at all. */
5933 /* An all-zero word flags the start of the tbtab, for debuggers
5934 that have to find it by searching forward from the entry
5935 point or from the current pc. */
5936 fputs ("\t.long 0\n", file);
5938 /* Tbtab format type. Use format type 0. */
5939 fputs ("\t.byte 0,", file);
5941 /* Language type. Unfortunately, there doesn't seem to be any
5942 official way to get this info, so we use language_string. C
5943 is 0. C++ is 9. No number defined for Obj-C, so use the
5944 value for C for now. There is no official value for Java,
5945 although IBM appears to be using 13. There is no official value
5946 for Chill, so we've choosen 44 pseudo-randomly. */
5947 if (! strcmp (language_string, "GNU C")
5948 || ! strcmp (language_string, "GNU Obj-C"))
5949 i = 0;
5950 else if (! strcmp (language_string, "GNU F77"))
5951 i = 1;
5952 else if (! strcmp (language_string, "GNU Ada"))
5953 i = 3;
5954 else if (! strcmp (language_string, "GNU Pascal"))
5955 i = 2;
5956 else if (! strcmp (language_string, "GNU C++"))
5957 i = 9;
5958 else if (! strcmp (language_string, "GNU Java"))
5959 i = 13;
5960 else if (! strcmp (language_string, "GNU CHILL"))
5961 i = 44;
5962 else
5963 abort ();
5964 fprintf (file, "%d,", i);
5966 /* 8 single bit fields: global linkage (not set for C extern linkage,
5967 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
5968 from start of procedure stored in tbtab, internal function, function
5969 has controlled storage, function has no toc, function uses fp,
5970 function logs/aborts fp operations. */
5971 /* Assume that fp operations are used if any fp reg must be saved. */
5972 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
5974 /* 6 bitfields: function is interrupt handler, name present in
5975 proc table, function calls alloca, on condition directives
5976 (controls stack walks, 3 bits), saves condition reg, saves
5977 link reg. */
5978 /* The `function calls alloca' bit seems to be set whenever reg 31 is
5979 set up as a frame pointer, even when there is no alloca call. */
5980 fprintf (file, "%d,",
5981 ((1 << 6) | (frame_pointer_needed << 5)
5982 | (info->cr_save_p << 1) | (info->lr_save_p)));
5984 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
5985 (6 bits). */
5986 fprintf (file, "%d,",
5987 (info->push_p << 7) | (64 - info->first_fp_reg_save));
5989 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
5990 fprintf (file, "%d,", (32 - first_reg_to_save ()));
5993 /* Compute the parameter info from the function decl argument
5994 list. */
5995 tree decl;
5996 int next_parm_info_bit;
5998 next_parm_info_bit = 31;
5999 parm_info = 0;
6000 fixed_parms = 0;
6001 float_parms = 0;
6003 for (decl = DECL_ARGUMENTS (current_function_decl);
6004 decl; decl = TREE_CHAIN (decl))
6006 rtx parameter = DECL_INCOMING_RTL (decl);
6007 enum machine_mode mode = GET_MODE (parameter);
6009 if (GET_CODE (parameter) == REG)
6011 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6013 int bits;
6015 float_parms++;
6017 if (mode == SFmode)
6018 bits = 0x2;
6019 else if (mode == DFmode)
6020 bits = 0x3;
6021 else
6022 abort ();
6024 /* If only one bit will fit, don't or in this entry. */
6025 if (next_parm_info_bit > 0)
6026 parm_info |= (bits << (next_parm_info_bit - 1));
6027 next_parm_info_bit -= 2;
6029 else
6031 fixed_parms += ((GET_MODE_SIZE (mode)
6032 + (UNITS_PER_WORD - 1))
6033 / UNITS_PER_WORD);
6034 next_parm_info_bit -= 1;
6040 /* Number of fixed point parameters. */
6041 /* This is actually the number of words of fixed point parameters; thus
6042 an 8 byte struct counts as 2; and thus the maximum value is 8. */
6043 fprintf (file, "%d,", fixed_parms);
6045 /* 2 bitfields: number of floating point parameters (7 bits), parameters
6046 all on stack. */
6047 /* This is actually the number of fp registers that hold parameters;
6048 and thus the maximum value is 13. */
6049 /* Set parameters on stack bit if parameters are not in their original
6050 registers, regardless of whether they are on the stack? Xlc
6051 seems to set the bit when not optimizing. */
6052 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
6054 /* Optional fields follow. Some are variable length. */
6056 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
6057 11 double float. */
6058 /* There is an entry for each parameter in a register, in the order that
6059 they occur in the parameter list. Any intervening arguments on the
6060 stack are ignored. If the list overflows a long (max possible length
6061 34 bits) then completely leave off all elements that don't fit. */
6062 /* Only emit this long if there was at least one parameter. */
6063 if (fixed_parms || float_parms)
6064 fprintf (file, "\t.long %d\n", parm_info);
6066 /* Offset from start of code to tb table. */
6067 fputs ("\t.long ", file);
6068 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6069 #if TARGET_AIX
6070 RS6000_OUTPUT_BASENAME (file, fname);
6071 #else
6072 assemble_name (file, fname);
6073 #endif
6074 fputs ("-.", file);
6075 #if TARGET_AIX
6076 RS6000_OUTPUT_BASENAME (file, fname);
6077 #else
6078 assemble_name (file, fname);
6079 #endif
6080 putc ('\n', file);
6082 /* Interrupt handler mask. */
6083 /* Omit this long, since we never set the interrupt handler bit
6084 above. */
6086 /* Number of CTL (controlled storage) anchors. */
6087 /* Omit this long, since the has_ctl bit is never set above. */
6089 /* Displacement into stack of each CTL anchor. */
6090 /* Omit this list of longs, because there are no CTL anchors. */
6092 /* Length of function name. */
6093 fprintf (file, "\t.short %d\n", (int) strlen (fname));
6095 /* Function name. */
6096 assemble_string (fname, strlen (fname));
6098 /* Register for alloca automatic storage; this is always reg 31.
6099 Only emit this if the alloca bit was set above. */
6100 if (frame_pointer_needed)
6101 fputs ("\t.byte 31\n", file);
6105 /* A C compound statement that outputs the assembler code for a thunk function,
6106 used to implement C++ virtual function calls with multiple inheritance. The
6107 thunk acts as a wrapper around a virtual function, adjusting the implicit
6108 object parameter before handing control off to the real function.
6110 First, emit code to add the integer DELTA to the location that contains the
6111 incoming first argument. Assume that this argument contains a pointer, and
6112 is the one used to pass the `this' pointer in C++. This is the incoming
6113 argument *before* the function prologue, e.g. `%o0' on a sparc. The
6114 addition must preserve the values of all other incoming arguments.
6116 After the addition, emit code to jump to FUNCTION, which is a
6117 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
6118 the return address. Hence returning from FUNCTION will return to whoever
6119 called the current `thunk'.
6121 The effect must be as if FUNCTION had been called directly with the adjusted
6122 first argument. This macro is responsible for emitting all of the code for
6123 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
6124 invoked.
6126 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
6127 extracted from it.) It might possibly be useful on some targets, but
6128 probably not.
6130 If you do not define this macro, the target-independent code in the C++
6131 frontend will generate a less efficient heavyweight thunk that calls
6132 FUNCTION instead of jumping to it. The generic approach does not support
6133 varargs. */
6135 void
6136 output_mi_thunk (file, thunk_fndecl, delta, function)
6137 FILE *file;
6138 tree thunk_fndecl ATTRIBUTE_UNUSED;
6139 int delta;
6140 tree function;
6142 const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
6143 const char *prefix;
6144 const char *fname;
6145 const char *r0 = reg_names[0];
6146 const char *toc = reg_names[2];
6147 const char *schain = reg_names[11];
6148 const char *r12 = reg_names[12];
6149 char buf[512];
6150 static int labelno = 0;
6152 /* Small constants that can be done by one add instruction */
6153 if (delta >= -32768 && delta <= 32767)
6155 if (! TARGET_NEW_MNEMONICS)
6156 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
6157 else
6158 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
6161 /* Large constants that can be done by one addis instruction */
6162 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
6163 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6164 delta >> 16);
6166 /* 32-bit constants that can be done by an add and addis instruction. */
6167 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
6169 /* Break into two pieces, propagating the sign bit from the low word to
6170 the upper word. */
6171 int delta_high = delta >> 16;
6172 int delta_low = delta & 0xffff;
6173 if ((delta_low & 0x8000) != 0)
6175 delta_high++;
6176 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
6179 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6180 delta_high);
6182 if (! TARGET_NEW_MNEMONICS)
6183 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
6184 else
6185 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
6188 /* 64-bit constants, fixme */
6189 else
6190 abort ();
6192 /* Get the prefix in front of the names. */
6193 switch (DEFAULT_ABI)
6195 default:
6196 abort ();
6198 case ABI_AIX:
6199 prefix = ".";
6200 break;
6202 case ABI_V4:
6203 case ABI_AIX_NODESC:
6204 case ABI_SOLARIS:
6205 prefix = "";
6206 break;
6209 /* If the function is compiled in this module, jump to it directly.
6210 Otherwise, load up its address and jump to it. */
6212 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
6214 if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode)
6215 && ! lookup_attribute ("longcall",
6216 TYPE_ATTRIBUTES (TREE_TYPE (function))))
6218 fprintf (file, "\tb %s", prefix);
6219 assemble_name (file, fname);
6220 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
6221 putc ('\n', file);
6224 else
6226 switch (DEFAULT_ABI)
6228 default:
6229 abort ();
6231 case ABI_AIX:
6232 /* Set up a TOC entry for the function. */
6233 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
6234 toc_section ();
6235 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
6236 labelno++;
6238 /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since
6239 there will be only one TOC entry for this function. */
6240 fputs ("\t.tc\t", file);
6241 assemble_name (file, buf);
6242 fputs ("[TC],", file);
6243 assemble_name (file, buf);
6244 putc ('\n', file);
6245 text_section ();
6246 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12);
6247 assemble_name (file, buf);
6248 asm_fprintf (file, "(%s)\n", reg_names[2]);
6249 asm_fprintf (file,
6250 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
6251 r0, r12);
6253 asm_fprintf (file,
6254 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
6255 toc, r12);
6257 asm_fprintf (file, "\tmtctr %s\n", r0);
6258 asm_fprintf (file,
6259 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
6260 schain, r12);
6262 asm_fprintf (file, "\tbctr\n");
6263 break;
6265 case ABI_AIX_NODESC:
6266 case ABI_SOLARIS:
6267 case ABI_V4:
6268 fprintf (file, "\tb %s", prefix);
6269 assemble_name (file, fname);
6270 if (flag_pic) fputs ("@plt", file);
6271 putc ('\n', file);
6272 break;
6278 /* A quick summary of the various types of 'constant-pool tables'
6279 under PowerPC:
6281 Target Flags Name One table per
6282 AIX (none) AIX TOC object file
6283 AIX -mfull-toc AIX TOC object file
6284 AIX -mminimal-toc AIX minimal TOC translation unit
6285 SVR4/EABI (none) SVR4 SDATA object file
6286 SVR4/EABI -fpic SVR4 pic object file
6287 SVR4/EABI -fPIC SVR4 PIC translation unit
6288 SVR4/EABI -mrelocatable EABI TOC function
6289 SVR4/EABI -maix AIX TOC object file
6290 SVR4/EABI -maix -mminimal-toc
6291 AIX minimal TOC translation unit
6293 Name Reg. Set by entries contains:
6294 made by addrs? fp? sum?
6296 AIX TOC 2 crt0 as Y option option
6297 AIX minimal TOC 30 prolog gcc Y Y option
6298 SVR4 SDATA 13 crt0 gcc N Y N
6299 SVR4 pic 30 prolog ld Y not yet N
6300 SVR4 PIC 30 prolog gcc Y option option
6301 EABI TOC 30 prolog gcc Y option option
6305 /* Hash table stuff for keeping track of TOC entries. */
6307 struct toc_hash_struct
6309 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
6310 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
6311 rtx key;
6312 int labelno;
6315 static htab_t toc_hash_table;
6317 /* Hash functions for the hash table. */
6319 static unsigned
6320 rs6000_hash_constant (k)
6321 rtx k;
6323 unsigned result = GET_CODE (k);
6324 const char *format = GET_RTX_FORMAT (GET_CODE (k));
6325 int flen = strlen (format);
6326 int fidx;
6328 if (GET_CODE (k) == LABEL_REF)
6329 return result * 1231 + XINT (XEXP (k, 0), 3);
6331 if (GET_CODE (k) == CONST_DOUBLE)
6332 fidx = 2;
6333 else if (GET_CODE (k) == CODE_LABEL)
6334 fidx = 3;
6335 else
6336 fidx = 0;
6338 for (; fidx < flen; fidx++)
6339 switch (format[fidx])
6341 case 's':
6343 unsigned i, len;
6344 const char *str = XSTR (k, fidx);
6345 len = strlen (str);
6346 result = result * 613 + len;
6347 for (i = 0; i < len; i++)
6348 result = result * 613 + (unsigned) str[i];
6349 break;
6351 case 'u':
6352 case 'e':
6353 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
6354 break;
6355 case 'i':
6356 case 'n':
6357 result = result * 613 + (unsigned) XINT (k, fidx);
6358 break;
6359 case 'w':
6360 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
6361 result = result * 613 + (unsigned) XWINT (k, fidx);
6362 else
6364 size_t i;
6365 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
6366 result = result * 613 + (unsigned) (XWINT (k, fidx)
6367 >> CHAR_BIT * i);
6369 break;
6370 default:
6371 abort();
6373 return result;
6376 static unsigned
6377 toc_hash_function (hash_entry)
6378 const void * hash_entry;
6380 return rs6000_hash_constant (((const struct toc_hash_struct *)
6381 hash_entry)->key);
6384 /* Compare H1 and H2 for equivalence. */
6386 static int
6387 toc_hash_eq (h1, h2)
6388 const void * h1;
6389 const void * h2;
6391 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
6392 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
6394 /* Gotcha: One of these const_doubles will be in memory.
6395 The other may be on the constant-pool chain.
6396 So rtx_equal_p will think they are different... */
6397 if (r1 == r2)
6398 return 1;
6399 if (GET_CODE (r1) != GET_CODE (r2)
6400 || GET_MODE (r1) != GET_MODE (r2))
6401 return 0;
6402 if (GET_CODE (r1) == CONST_DOUBLE)
6404 int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE));
6405 int i;
6406 for (i = 2; i < format_len; i++)
6407 if (XWINT (r1, i) != XWINT (r2, i))
6408 return 0;
6410 return 1;
6412 else if (GET_CODE (r1) == LABEL_REF)
6413 return (CODE_LABEL_NUMBER (XEXP (r1, 0))
6414 == CODE_LABEL_NUMBER (XEXP (r2, 0)));
6415 else
6416 return rtx_equal_p (r1, r2);
6419 /* Mark the hash table-entry HASH_ENTRY. */
6421 static int
6422 toc_hash_mark_entry (hash_slot, unused)
6423 void ** hash_slot;
6424 void * unused ATTRIBUTE_UNUSED;
6426 const struct toc_hash_struct * hash_entry =
6427 *(const struct toc_hash_struct **) hash_slot;
6428 rtx r = hash_entry->key;
6429 ggc_set_mark (hash_entry);
6430 /* For CODE_LABELS, we don't want to drag in the whole insn chain... */
6431 if (GET_CODE (r) == LABEL_REF)
6433 ggc_set_mark (r);
6434 ggc_set_mark (XEXP (r, 0));
6436 else
6437 ggc_mark_rtx (r);
6438 return 1;
6441 /* Mark all the elements of the TOC hash-table *HT. */
6443 static void
6444 toc_hash_mark_table (vht)
6445 void *vht;
6447 htab_t *ht = vht;
6449 htab_traverse (*ht, toc_hash_mark_entry, (void *)0);
6452 /* Output a TOC entry. We derive the entry name from what is
6453 being written. */
6455 void
6456 output_toc (file, x, labelno)
6457 FILE *file;
6458 rtx x;
6459 int labelno;
6461 char buf[256];
6462 const char *name = buf;
6463 const char *real_name;
6464 rtx base = x;
6465 int offset = 0;
6467 if (TARGET_NO_TOC)
6468 abort ();
6470 /* When the linker won't eliminate them, don't output duplicate
6471 TOC entries (this happens on AIX if there is any kind of TOC,
6472 and on SVR4 under -fPIC or -mrelocatable).
6473 This won't work if we are not garbage collecting, so
6474 we don't do it, sorry. */
6475 if (TARGET_TOC && ggc_p)
6477 struct toc_hash_struct *h;
6478 void * * found;
6480 h = ggc_alloc (sizeof (*h));
6481 h->key = x;
6482 h->labelno = labelno;
6484 found = htab_find_slot (toc_hash_table, h, 1);
6485 if (*found == NULL)
6486 *found = h;
6487 else /* This is indeed a duplicate.
6488 Set this label equal to that label. */
6490 fputs ("\t.set ", file);
6491 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6492 fprintf (file, "%d,", labelno);
6493 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6494 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
6495 found)->labelno));
6496 return;
6500 /* If we're going to put a double constant in the TOC, make sure it's
6501 aligned properly when strict alignment is on. */
6502 if (GET_CODE (x) == CONST_DOUBLE
6503 && STRICT_ALIGNMENT
6504 && GET_MODE (x) == DFmode
6505 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
6506 ASM_OUTPUT_ALIGN (file, 3);
6509 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
6511 /* Handle FP constants specially. Note that if we have a minimal
6512 TOC, things we put here aren't actually in the TOC, so we can allow
6513 FP constants. */
6514 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode
6515 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
6517 REAL_VALUE_TYPE rv;
6518 long k[2];
6520 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
6521 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
6523 if (TARGET_64BIT)
6525 if (TARGET_MINIMAL_TOC)
6526 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
6527 else
6528 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
6529 k[0], k[1], k[0] & 0xffffffffu, k[1] & 0xffffffffu);
6530 return;
6532 else
6534 if (TARGET_MINIMAL_TOC)
6535 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]);
6536 else
6537 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n",
6538 k[0], k[1], k[0], k[1]);
6539 return;
6542 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
6543 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
6545 REAL_VALUE_TYPE rv;
6546 long l;
6548 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
6549 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
6551 if (TARGET_64BIT)
6553 if (TARGET_MINIMAL_TOC)
6554 fprintf (file, "\t.llong 0x%lx00000000\n", l);
6555 else
6556 fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l);
6557 return;
6559 else
6561 if (TARGET_MINIMAL_TOC)
6562 fprintf (file, "\t.long 0x%lx\n", l);
6563 else
6564 fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l);
6565 return;
6568 else if (GET_MODE (x) == VOIDmode
6569 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
6570 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
6572 HOST_WIDE_INT low;
6573 HOST_WIDE_INT high;
6575 if (GET_CODE (x) == CONST_DOUBLE)
6577 low = CONST_DOUBLE_LOW (x);
6578 high = CONST_DOUBLE_HIGH (x);
6580 else
6581 #if HOST_BITS_PER_WIDE_INT == 32
6583 low = INTVAL (x);
6584 high = (low < 0) ? ~0 : 0;
6586 #else
6588 low = INTVAL (x) & 0xffffffff;
6589 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
6591 #endif
6593 if (TARGET_64BIT)
6595 if (TARGET_MINIMAL_TOC)
6596 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
6597 else
6598 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
6599 (long)high, (long)low, (long)high, (long)low);
6600 return;
6602 else
6604 if (TARGET_MINIMAL_TOC)
6605 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n",
6606 (long)high, (long)low);
6607 else
6608 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n",
6609 (long)high, (long)low, (long)high, (long)low);
6610 return;
6614 if (GET_CODE (x) == CONST)
6616 base = XEXP (XEXP (x, 0), 0);
6617 offset = INTVAL (XEXP (XEXP (x, 0), 1));
6620 if (GET_CODE (base) == SYMBOL_REF)
6621 name = XSTR (base, 0);
6622 else if (GET_CODE (base) == LABEL_REF)
6623 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
6624 else if (GET_CODE (base) == CODE_LABEL)
6625 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
6626 else
6627 abort ();
6629 STRIP_NAME_ENCODING (real_name, name);
6630 if (TARGET_MINIMAL_TOC)
6631 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
6632 else
6634 fprintf (file, "\t.tc %s", real_name);
6636 if (offset < 0)
6637 fprintf (file, ".N%d", - offset);
6638 else if (offset)
6639 fprintf (file, ".P%d", offset);
6641 fputs ("[TC],", file);
6644 /* Currently C++ toc references to vtables can be emitted before it
6645 is decided whether the vtable is public or private. If this is
6646 the case, then the linker will eventually complain that there is
6647 a TOC reference to an unknown section. Thus, for vtables only,
6648 we emit the TOC reference to reference the symbol and not the
6649 section. */
6650 if (! strncmp ("_vt.", name, 4))
6652 assemble_name (file, name);
6653 if (offset < 0)
6654 fprintf (file, "%d", offset);
6655 else if (offset > 0)
6656 fprintf (file, "+%d", offset);
6658 else
6659 output_addr_const (file, x);
6660 putc ('\n', file);
6663 /* Output an assembler pseudo-op to write an ASCII string of N characters
6664 starting at P to FILE.
6666 On the RS/6000, we have to do this using the .byte operation and
6667 write out special characters outside the quoted string.
6668 Also, the assembler is broken; very long strings are truncated,
6669 so we must artificially break them up early. */
6671 void
6672 output_ascii (file, p, n)
6673 FILE *file;
6674 const char *p;
6675 int n;
6677 char c;
6678 int i, count_string;
6679 const char *for_string = "\t.byte \"";
6680 const char *for_decimal = "\t.byte ";
6681 const char *to_close = NULL;
6683 count_string = 0;
6684 for (i = 0; i < n; i++)
6686 c = *p++;
6687 if (c >= ' ' && c < 0177)
6689 if (for_string)
6690 fputs (for_string, file);
6691 putc (c, file);
6693 /* Write two quotes to get one. */
6694 if (c == '"')
6696 putc (c, file);
6697 ++count_string;
6700 for_string = NULL;
6701 for_decimal = "\"\n\t.byte ";
6702 to_close = "\"\n";
6703 ++count_string;
6705 if (count_string >= 512)
6707 fputs (to_close, file);
6709 for_string = "\t.byte \"";
6710 for_decimal = "\t.byte ";
6711 to_close = NULL;
6712 count_string = 0;
6715 else
6717 if (for_decimal)
6718 fputs (for_decimal, file);
6719 fprintf (file, "%d", c);
6721 for_string = "\n\t.byte \"";
6722 for_decimal = ", ";
6723 to_close = "\n";
6724 count_string = 0;
6728 /* Now close the string if we have written one. Then end the line. */
6729 if (to_close)
6730 fputs (to_close, file);
6733 /* Generate a unique section name for FILENAME for a section type
6734 represented by SECTION_DESC. Output goes into BUF.
6736 SECTION_DESC can be any string, as long as it is different for each
6737 possible section type.
6739 We name the section in the same manner as xlc. The name begins with an
6740 underscore followed by the filename (after stripping any leading directory
6741 names) with the last period replaced by the string SECTION_DESC. If
6742 FILENAME does not contain a period, SECTION_DESC is appended to the end of
6743 the name. */
6745 void
6746 rs6000_gen_section_name (buf, filename, section_desc)
6747 char **buf;
6748 const char *filename;
6749 const char *section_desc;
6751 const char *q, *after_last_slash, *last_period = 0;
6752 char *p;
6753 int len;
6755 after_last_slash = filename;
6756 for (q = filename; *q; q++)
6758 if (*q == '/')
6759 after_last_slash = q + 1;
6760 else if (*q == '.')
6761 last_period = q;
6764 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6765 *buf = (char *) permalloc (len);
6767 p = *buf;
6768 *p++ = '_';
6770 for (q = after_last_slash; *q; q++)
6772 if (q == last_period)
6774 strcpy (p, section_desc);
6775 p += strlen (section_desc);
6778 else if (ISALNUM (*q))
6779 *p++ = *q;
6782 if (last_period == 0)
6783 strcpy (p, section_desc);
6784 else
6785 *p = '\0';
6788 /* Write function profiler code. */
6790 void
6791 output_function_profiler (file, labelno)
6792 FILE *file;
6793 int labelno;
6795 /* The last used parameter register. */
6796 int last_parm_reg;
6797 int i, j;
6798 char buf[100];
6800 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
6801 switch (DEFAULT_ABI)
6803 default:
6804 abort ();
6806 case ABI_V4:
6807 case ABI_SOLARIS:
6808 case ABI_AIX_NODESC:
6809 fprintf (file, "\tmflr %s\n", reg_names[0]);
6810 if (flag_pic == 1)
6812 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
6813 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
6814 reg_names[0], reg_names[1]);
6815 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
6816 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
6817 assemble_name (file, buf);
6818 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
6820 else if (flag_pic > 1)
6822 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
6823 reg_names[0], reg_names[1]);
6824 /* Now, we need to get the address of the label. */
6825 fputs ("\tbl 1f\n\t.long ", file);
6826 assemble_name (file, buf);
6827 fputs ("-.\n1:", file);
6828 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
6829 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
6830 reg_names[0], reg_names[11]);
6831 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
6832 reg_names[0], reg_names[0], reg_names[11]);
6834 else
6836 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
6837 assemble_name (file, buf);
6838 fputs ("@ha\n", file);
6839 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
6840 reg_names[0], reg_names[1]);
6841 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
6842 assemble_name (file, buf);
6843 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
6846 if (current_function_needs_context)
6847 asm_fprintf (file, "\tmr %s,%s\n",
6848 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
6849 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
6850 if (current_function_needs_context)
6851 asm_fprintf (file, "\tmr %s,%s\n",
6852 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
6853 break;
6855 case ABI_AIX:
6856 /* Set up a TOC entry for the profiler label. */
6857 toc_section ();
6858 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
6859 if (TARGET_MINIMAL_TOC)
6861 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
6862 assemble_name (file, buf);
6863 putc ('\n', file);
6865 else
6867 fputs ("\t.tc\t", file);
6868 assemble_name (file, buf);
6869 fputs ("[TC],", file);
6870 assemble_name (file, buf);
6871 putc ('\n', file);
6873 text_section ();
6875 /* Figure out last used parameter register. The proper thing to do is
6876 to walk incoming args of the function. A function might have live
6877 parameter registers even if it has no incoming args. */
6879 for (last_parm_reg = 10;
6880 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
6881 last_parm_reg--)
6884 /* Save parameter registers in regs 23-30 and static chain in r22.
6885 Don't overwrite reg 31, since it might be set up as the frame pointer. */
6887 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
6888 asm_fprintf (file, "\tmr %d,%d\n", j, i);
6889 if (current_function_needs_context)
6890 asm_fprintf (file, "\tmr %d,%d\n", j, STATIC_CHAIN_REGNUM);
6892 /* Load location address into r3, and call mcount. */
6894 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
6895 asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,",
6896 reg_names[3]);
6897 assemble_name (file, buf);
6898 asm_fprintf (file, "(%s)\n\tbl %s\n\t", reg_names[2], RS6000_MCOUNT);
6899 asm_fprintf (file, RS6000_CALL_GLUE);
6900 putc('\n', file);
6902 /* Restore parameter registers and static chain. */
6904 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
6905 asm_fprintf (file, "\tmr %d,%d\n", i, j);
6906 if (current_function_needs_context)
6907 asm_fprintf (file, "\tmr %d,%d\n", STATIC_CHAIN_REGNUM, j);
6909 break;
6913 /* Adjust the cost of a scheduling dependency. Return the new cost of
6914 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
6917 rs6000_adjust_cost (insn, link, dep_insn, cost)
6918 rtx insn;
6919 rtx link;
6920 rtx dep_insn ATTRIBUTE_UNUSED;
6921 int cost;
6923 if (! recog_memoized (insn))
6924 return 0;
6926 if (REG_NOTE_KIND (link) != 0)
6927 return 0;
6929 if (REG_NOTE_KIND (link) == 0)
6931 /* Data dependency; DEP_INSN writes a register that INSN reads some
6932 cycles later. */
6934 /* Tell the first scheduling pass about the latency between a mtctr
6935 and bctr (and mtlr and br/blr). The first scheduling pass will not
6936 know about this latency since the mtctr instruction, which has the
6937 latency associated to it, will be generated by reload. */
6938 if (get_attr_type (insn) == TYPE_JMPREG)
6939 return TARGET_POWER ? 5 : 4;
6941 /* Fall out to return default cost. */
6944 return cost;
6947 /* A C statement (sans semicolon) to update the integer scheduling priority
6948 INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier,
6949 increase the priority to execute INSN later. Do not define this macro if
6950 you do not need to adjust the scheduling priorities of insns. */
6953 rs6000_adjust_priority (insn, priority)
6954 rtx insn ATTRIBUTE_UNUSED;
6955 int priority;
6957 /* On machines (like the 750) which have asymetric integer units, where one
6958 integer unit can do multiply and divides and the other can't, reduce the
6959 priority of multiply/divide so it is scheduled before other integer
6960 operationss. */
6962 #if 0
6963 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
6964 return priority;
6966 if (GET_CODE (PATTERN (insn)) == USE)
6967 return priority;
6969 switch (rs6000_cpu_attr) {
6970 case CPU_PPC750:
6971 switch (get_attr_type (insn))
6973 default:
6974 break;
6976 case TYPE_IMUL:
6977 case TYPE_IDIV:
6978 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
6979 priority, priority);
6980 if (priority >= 0 && priority < 0x01000000)
6981 priority >>= 3;
6982 break;
6985 #endif
6987 return priority;
6990 /* Return how many instructions the machine can issue per cycle */
6991 int get_issue_rate()
6993 switch (rs6000_cpu_attr) {
6994 case CPU_RIOS1: /* ? */
6995 case CPU_RS64A:
6996 case CPU_PPC601: /* ? */
6997 return 3;
6998 case CPU_PPC603:
6999 case CPU_PPC750:
7000 return 2;
7001 case CPU_RIOS2:
7002 case CPU_PPC604:
7003 case CPU_PPC604E:
7004 case CPU_PPC620:
7005 case CPU_PPC630:
7006 return 4;
7007 default:
7008 return 1;
7013 /* Length in units of the trampoline for entering a nested function. */
7016 rs6000_trampoline_size ()
7018 int ret = 0;
7020 switch (DEFAULT_ABI)
7022 default:
7023 abort ();
7025 case ABI_AIX:
7026 ret = (TARGET_32BIT) ? 12 : 24;
7027 break;
7029 case ABI_V4:
7030 case ABI_SOLARIS:
7031 case ABI_AIX_NODESC:
7032 ret = (TARGET_32BIT) ? 40 : 48;
7033 break;
7036 return ret;
7039 /* Emit RTL insns to initialize the variable parts of a trampoline.
7040 FNADDR is an RTX for the address of the function's pure code.
7041 CXT is an RTX for the static chain value for the function. */
7043 void
7044 rs6000_initialize_trampoline (addr, fnaddr, cxt)
7045 rtx addr;
7046 rtx fnaddr;
7047 rtx cxt;
7049 enum machine_mode pmode = Pmode;
7050 int regsize = (TARGET_32BIT) ? 4 : 8;
7051 rtx ctx_reg = force_reg (pmode, cxt);
7053 switch (DEFAULT_ABI)
7055 default:
7056 abort ();
7058 /* Macros to shorten the code expansions below. */
7059 #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
7060 #define MEM_PLUS(addr,offset) \
7061 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7063 /* Under AIX, just build the 3 word function descriptor */
7064 case ABI_AIX:
7066 rtx fn_reg = gen_reg_rtx (pmode);
7067 rtx toc_reg = gen_reg_rtx (pmode);
7068 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
7069 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
7070 emit_move_insn (MEM_DEREF (addr), fn_reg);
7071 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
7072 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
7074 break;
7076 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
7077 case ABI_V4:
7078 case ABI_SOLARIS:
7079 case ABI_AIX_NODESC:
7080 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7081 FALSE, VOIDmode, 4,
7082 addr, pmode,
7083 GEN_INT (rs6000_trampoline_size ()), SImode,
7084 fnaddr, pmode,
7085 ctx_reg, pmode);
7086 break;
7089 return;
7093 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7094 with arguments ARGS is a valid machine specific attribute for DECL.
7095 The attributes in ATTRIBUTES have previously been assigned to DECL. */
7098 rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
7099 tree decl ATTRIBUTE_UNUSED;
7100 tree attributes ATTRIBUTE_UNUSED;
7101 tree identifier ATTRIBUTE_UNUSED;
7102 tree args ATTRIBUTE_UNUSED;
7104 return 0;
7107 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7108 with arguments ARGS is a valid machine specific attribute for TYPE.
7109 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
7112 rs6000_valid_type_attribute_p (type, attributes, identifier, args)
7113 tree type;
7114 tree attributes ATTRIBUTE_UNUSED;
7115 tree identifier;
7116 tree args;
7118 if (TREE_CODE (type) != FUNCTION_TYPE
7119 && TREE_CODE (type) != FIELD_DECL
7120 && TREE_CODE (type) != TYPE_DECL)
7121 return 0;
7123 /* Longcall attribute says that the function is not within 2**26 bytes
7124 of the current function, and to do an indirect call. */
7125 if (is_attribute_p ("longcall", identifier))
7126 return (args == NULL_TREE);
7128 return 0;
7131 /* If defined, a C expression whose value is zero if the attributes on
7132 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
7133 two if they are nearly compatible (which causes a warning to be
7134 generated). */
7137 rs6000_comp_type_attributes (type1, type2)
7138 tree type1 ATTRIBUTE_UNUSED;
7139 tree type2 ATTRIBUTE_UNUSED;
7141 return 1;
7144 /* If defined, a C statement that assigns default attributes to newly
7145 defined TYPE. */
7147 void
7148 rs6000_set_default_type_attributes (type)
7149 tree type ATTRIBUTE_UNUSED;
7151 return;
7154 /* Return a reference suitable for calling a function with the
7155 longcall attribute. */
7156 struct rtx_def *
7157 rs6000_longcall_ref (call_ref)
7158 rtx call_ref;
7160 const char *call_name;
7161 tree node;
7163 if (GET_CODE (call_ref) != SYMBOL_REF)
7164 return call_ref;
7166 /* System V adds '.' to the internal name, so skip them. */
7167 call_name = XSTR (call_ref, 0);
7168 if (*call_name == '.')
7170 while (*call_name == '.')
7171 call_name++;
7173 node = get_identifier (call_name);
7174 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
7177 return force_reg (Pmode, call_ref);
7181 /* A C statement or statements to switch to the appropriate section
7182 for output of RTX in mode MODE. You can assume that RTX is some
7183 kind of constant in RTL. The argument MODE is redundant except in
7184 the case of a `const_int' rtx. Select the section by calling
7185 `text_section' or one of the alternatives for other sections.
7187 Do not define this macro if you put all constants in the read-only
7188 data section. */
7190 #ifdef USING_SVR4_H
7192 void
7193 rs6000_select_rtx_section (mode, x)
7194 enum machine_mode mode ATTRIBUTE_UNUSED;
7195 rtx x;
7197 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x))
7198 toc_section ();
7199 else
7200 const_section ();
7203 /* A C statement or statements to switch to the appropriate
7204 section for output of DECL. DECL is either a `VAR_DECL' node
7205 or a constant of some sort. RELOC indicates whether forming
7206 the initial value of DECL requires link-time relocations. */
7208 void
7209 rs6000_select_section (decl, reloc)
7210 tree decl;
7211 int reloc;
7213 int size = int_size_in_bytes (TREE_TYPE (decl));
7215 if (TREE_CODE (decl) == STRING_CST)
7217 if (! flag_writable_strings)
7218 const_section ();
7219 else
7220 data_section ();
7222 else if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONSTRUCTOR)
7224 if ((flag_pic && reloc)
7225 || ! TREE_READONLY (decl)
7226 || TREE_SIDE_EFFECTS (decl)
7227 || ! DECL_INITIAL (decl)
7228 || (DECL_INITIAL (decl) != error_mark_node
7229 && ! TREE_CONSTANT (DECL_INITIAL (decl))))
7231 if (rs6000_sdata != SDATA_NONE && (size > 0)
7232 && (size <= g_switch_value))
7233 sdata_section ();
7234 else
7235 data_section ();
7237 else
7239 if (rs6000_sdata != SDATA_NONE && (size > 0)
7240 && (size <= g_switch_value))
7242 if (rs6000_sdata == SDATA_EABI)
7243 sdata2_section ();
7244 else
7245 sdata_section (); /* System V doesn't have .sdata2/.sbss2 */
7247 else
7248 const_section ();
7251 else
7252 const_section ();
7256 /* If we are referencing a function that is static or is known to be
7257 in this file, make the SYMBOL_REF special. We can use this to indicate
7258 that we can branch to this function without emitting a no-op after the
7259 call. For real AIX calling sequences, we also replace the
7260 function name with the real name (1 or 2 leading .'s), rather than
7261 the function descriptor name. This saves a lot of overriding code
7262 to read the prefixes. */
7264 void
7265 rs6000_encode_section_info (decl)
7266 tree decl;
7268 if (TREE_CODE (decl) == FUNCTION_DECL)
7270 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7271 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
7272 && ! DECL_WEAK (decl))
7273 SYMBOL_REF_FLAG (sym_ref) = 1;
7275 if (DEFAULT_ABI == ABI_AIX)
7277 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
7278 size_t len2 = strlen (XSTR (sym_ref, 0));
7279 char *str;
7281 if (ggc_p)
7282 str = ggc_alloc_string (NULL, len1 + len2);
7283 else
7284 str = permalloc (len1 + len2 + 1);
7286 str[0] = '.';
7287 str[1] = '.';
7288 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
7290 XSTR (sym_ref, 0) = str;
7293 else if (rs6000_sdata != SDATA_NONE
7294 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7295 && TREE_CODE (decl) == VAR_DECL)
7297 int size = int_size_in_bytes (TREE_TYPE (decl));
7298 tree section_name = DECL_SECTION_NAME (decl);
7299 const char *name = (char *)0;
7300 int len = 0;
7302 if (section_name)
7304 if (TREE_CODE (section_name) == STRING_CST)
7306 name = TREE_STRING_POINTER (section_name);
7307 len = TREE_STRING_LENGTH (section_name);
7309 else
7310 abort ();
7313 if ((size > 0 && size <= g_switch_value)
7314 || (name
7315 && ((len == sizeof (".sdata") - 1
7316 && strcmp (name, ".sdata") == 0)
7317 || (len == sizeof (".sdata2") - 1
7318 && strcmp (name, ".sdata2") == 0)
7319 || (len == sizeof (".sbss") - 1
7320 && strcmp (name, ".sbss") == 0)
7321 || (len == sizeof (".sbss2") - 1
7322 && strcmp (name, ".sbss2") == 0)
7323 || (len == sizeof (".PPC.EMB.sdata0") - 1
7324 && strcmp (name, ".PPC.EMB.sdata0") == 0)
7325 || (len == sizeof (".PPC.EMB.sbss0") - 1
7326 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
7328 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7329 size_t len = strlen (XSTR (sym_ref, 0));
7330 char *str;
7332 if (ggc_p)
7333 str = ggc_alloc_string (NULL, len + 1);
7334 else
7335 str = permalloc (len + 2);
7336 str[0] = '@';
7337 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
7339 XSTR (sym_ref, 0) = str;
7344 #endif /* USING_SVR4_H */
7347 /* Return a REG that occurs in ADDR with coefficient 1.
7348 ADDR can be effectively incremented by incrementing REG.
7350 r0 is special and we must not select it as an address
7351 register by this routine since our caller will try to
7352 increment the returned register via an "la" instruction. */
7354 struct rtx_def *
7355 find_addr_reg (addr)
7356 rtx addr;
7358 while (GET_CODE (addr) == PLUS)
7360 if (GET_CODE (XEXP (addr, 0)) == REG
7361 && REGNO (XEXP (addr, 0)) != 0)
7362 addr = XEXP (addr, 0);
7363 else if (GET_CODE (XEXP (addr, 1)) == REG
7364 && REGNO (XEXP (addr, 1)) != 0)
7365 addr = XEXP (addr, 1);
7366 else if (CONSTANT_P (XEXP (addr, 0)))
7367 addr = XEXP (addr, 1);
7368 else if (CONSTANT_P (XEXP (addr, 1)))
7369 addr = XEXP (addr, 0);
7370 else
7371 abort ();
7373 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
7374 return addr;
7375 abort ();
7378 void
7379 rs6000_fatal_bad_address (op)
7380 rtx op;
7382 fatal_insn ("bad address", op);
7385 /* Called to register all of our global variables with the garbage
7386 collector. */
7388 static void
7389 rs6000_add_gc_roots ()
7391 ggc_add_rtx_root (&rs6000_compare_op0, 1);
7392 ggc_add_rtx_root (&rs6000_compare_op1, 1);
7394 toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL);
7395 ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table),
7396 toc_hash_mark_table);