2001-05-02 Dale Johannesen <dalej@apple.com>
[official-gcc.git] / gcc / config / rs6000 / rs6000.c
blob99186c160b52b4c60ab47a7def57c5df81b3c9d5
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001 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 once AIX common-mode calls have been defined. */
67 static int common_mode_defined;
69 /* Save information from a "cmpxx" operation until the branch or scc is
70 emitted. */
71 rtx rs6000_compare_op0, rs6000_compare_op1;
72 int rs6000_compare_fp_p;
74 /* Label number of label created for -mrelocatable, to call to so we can
75 get the address of the GOT section */
76 int rs6000_pic_labelno;
78 #ifdef USING_SVR4_H
79 /* Which abi to adhere to */
80 const char *rs6000_abi_name = RS6000_ABI_NAME;
82 /* Semantics of the small data area */
83 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
85 /* Which small data model to use */
86 const char *rs6000_sdata_name = (char *)0;
88 /* Counter for labels which are to be placed in .fixup. */
89 int fixuplabelno = 0;
90 #endif
92 /* ABI enumeration available for subtarget to use. */
93 enum rs6000_abi rs6000_current_abi;
95 /* Debug flags */
96 const char *rs6000_debug_name;
97 int rs6000_debug_stack; /* debug stack applications */
98 int rs6000_debug_arg; /* debug argument handling */
100 /* Flag to say the TOC is initialized */
101 int toc_initialized;
102 char toc_label_name[10];
104 /* Alias set for saves and restores from the rs6000 stack. */
105 static int rs6000_sr_alias_set;
107 static void rs6000_add_gc_roots PARAMS ((void));
108 static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
109 static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx));
110 static void validate_condition_mode
111 PARAMS ((enum rtx_code, enum machine_mode));
112 static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
113 static void rs6000_maybe_dead PARAMS ((rtx));
114 static void rs6000_emit_stack_tie PARAMS ((void));
115 static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
116 static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
117 static unsigned rs6000_hash_constant PARAMS ((rtx));
118 static unsigned toc_hash_function PARAMS ((const void *));
119 static int toc_hash_eq PARAMS ((const void *, const void *));
120 static int toc_hash_mark_entry PARAMS ((void **, void *));
121 static void toc_hash_mark_table PARAMS ((void *));
122 static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
123 static void rs6000_free_machine_status PARAMS ((struct function *));
124 static void rs6000_init_machine_status PARAMS ((struct function *));
125 static void rs6000_mark_machine_status PARAMS ((struct function *));
126 static int rs6000_ra_ever_killed PARAMS ((void));
128 /* Default register names. */
129 char rs6000_reg_names[][8] =
131 "0", "1", "2", "3", "4", "5", "6", "7",
132 "8", "9", "10", "11", "12", "13", "14", "15",
133 "16", "17", "18", "19", "20", "21", "22", "23",
134 "24", "25", "26", "27", "28", "29", "30", "31",
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 "mq", "lr", "ctr","ap",
140 "0", "1", "2", "3", "4", "5", "6", "7",
141 "xer"
144 #ifdef TARGET_REGNAMES
145 static char alt_reg_names[][8] =
147 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
148 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
149 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
150 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
151 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
152 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
153 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
154 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
155 "mq", "lr", "ctr", "ap",
156 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
157 "xer"
159 #endif
161 #ifndef MASK_STRICT_ALIGN
162 #define MASK_STRICT_ALIGN 0
163 #endif
165 /* Override command line options. Mostly we process the processor
166 type and sometimes adjust other TARGET_ options. */
168 void
169 rs6000_override_options (default_cpu)
170 const char *default_cpu;
172 size_t i, j;
173 struct rs6000_cpu_select *ptr;
175 /* Simplify the entries below by making a mask for any POWER
176 variant and any PowerPC variant. */
178 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
179 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
180 | MASK_PPC_GFXOPT | MASK_POWERPC64)
181 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
183 static struct ptt
185 const char *name; /* Canonical processor name. */
186 enum processor_type processor; /* Processor type enum value. */
187 int target_enable; /* Target flags to enable. */
188 int target_disable; /* Target flags to disable. */
189 } processor_target_table[]
190 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
191 POWER_MASKS | POWERPC_MASKS},
192 {"power", PROCESSOR_POWER,
193 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
194 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
195 {"power2", PROCESSOR_POWER,
196 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
197 POWERPC_MASKS | MASK_NEW_MNEMONICS},
198 {"power3", PROCESSOR_PPC630,
199 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
200 POWER_MASKS | MASK_PPC_GPOPT},
201 {"powerpc", PROCESSOR_POWERPC,
202 MASK_POWERPC | MASK_NEW_MNEMONICS,
203 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
204 {"powerpc64", PROCESSOR_POWERPC64,
205 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
206 POWER_MASKS | POWERPC_OPT_MASKS},
207 {"rios", PROCESSOR_RIOS1,
208 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
209 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
210 {"rios1", PROCESSOR_RIOS1,
211 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
212 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
213 {"rsc", PROCESSOR_PPC601,
214 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
215 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
216 {"rsc1", PROCESSOR_PPC601,
217 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
218 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
219 {"rios2", PROCESSOR_RIOS2,
220 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
221 POWERPC_MASKS | MASK_NEW_MNEMONICS},
222 {"rs64a", PROCESSOR_RS64A,
223 MASK_POWERPC | MASK_NEW_MNEMONICS,
224 POWER_MASKS | POWERPC_OPT_MASKS},
225 {"401", PROCESSOR_PPC403,
226 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
227 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
228 {"403", PROCESSOR_PPC403,
229 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
230 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
231 {"505", PROCESSOR_MPCCORE,
232 MASK_POWERPC | MASK_NEW_MNEMONICS,
233 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
234 {"601", PROCESSOR_PPC601,
235 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
236 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
237 {"602", PROCESSOR_PPC603,
238 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
239 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
240 {"603", PROCESSOR_PPC603,
241 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
242 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
243 {"603e", PROCESSOR_PPC603,
244 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
245 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
246 {"ec603e", PROCESSOR_PPC603,
247 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
248 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
249 {"604", PROCESSOR_PPC604,
250 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
251 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
252 {"604e", PROCESSOR_PPC604e,
253 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
254 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
255 {"620", PROCESSOR_PPC620,
256 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
257 POWER_MASKS | MASK_PPC_GPOPT},
258 {"630", PROCESSOR_PPC630,
259 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
260 POWER_MASKS | MASK_PPC_GPOPT},
261 {"740", PROCESSOR_PPC750,
262 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
263 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
264 {"750", PROCESSOR_PPC750,
265 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
266 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
267 {"801", PROCESSOR_MPCCORE,
268 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
269 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
270 {"821", PROCESSOR_MPCCORE,
271 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
272 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
273 {"823", PROCESSOR_MPCCORE,
274 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
275 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
276 {"860", PROCESSOR_MPCCORE,
277 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
278 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
280 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
282 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
283 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
285 profile_block_flag = 0;
287 /* Identify the processor type */
288 rs6000_select[0].string = default_cpu;
289 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
291 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
293 ptr = &rs6000_select[i];
294 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
296 for (j = 0; j < ptt_size; j++)
297 if (! strcmp (ptr->string, processor_target_table[j].name))
299 if (ptr->set_tune_p)
300 rs6000_cpu = processor_target_table[j].processor;
302 if (ptr->set_arch_p)
304 target_flags |= processor_target_table[j].target_enable;
305 target_flags &= ~processor_target_table[j].target_disable;
307 break;
310 if (j == ptt_size)
311 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
315 /* If we are optimizing big endian systems for space, use the
316 store multiple instructions. */
317 if (BYTES_BIG_ENDIAN && optimize_size)
318 target_flags |= MASK_MULTIPLE;
320 /* If -mmultiple or -mno-multiple was explicitly used, don't
321 override with the processor default */
322 if (TARGET_MULTIPLE_SET)
323 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
325 /* If -mstring or -mno-string was explicitly used, don't
326 override with the processor default */
327 if (TARGET_STRING_SET)
328 target_flags = (target_flags & ~MASK_STRING) | string;
330 /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu
331 is a 750, because the hardware doesn't support the instructions used in
332 little endian mode, and causes an alignment trap. The 750 does not cause
333 an alignment trap (except when the target is unaligned). */
335 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
337 if (TARGET_MULTIPLE)
339 target_flags &= ~MASK_MULTIPLE;
340 if (TARGET_MULTIPLE_SET)
341 warning ("-mmultiple is not supported on little endian systems");
344 if (TARGET_STRING)
346 target_flags &= ~MASK_STRING;
347 if (TARGET_STRING_SET)
348 warning ("-mstring is not supported on little endian systems");
352 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
354 warning ("-f%s ignored for AIX (all code is position independent)",
355 (flag_pic > 1) ? "PIC" : "pic");
356 flag_pic = 0;
359 if (flag_function_sections && (write_symbols != NO_DEBUG)
360 && (DEFAULT_ABI == ABI_AIX))
362 warning ("-ffunction-sections disabled on AIX when debugging");
363 flag_function_sections = 0;
366 if (flag_data_sections && (DEFAULT_ABI == ABI_AIX))
368 warning ("-fdata-sections not supported on AIX");
369 flag_data_sections = 0;
372 /* Set debug flags */
373 if (rs6000_debug_name)
375 if (! strcmp (rs6000_debug_name, "all"))
376 rs6000_debug_stack = rs6000_debug_arg = 1;
377 else if (! strcmp (rs6000_debug_name, "stack"))
378 rs6000_debug_stack = 1;
379 else if (! strcmp (rs6000_debug_name, "arg"))
380 rs6000_debug_arg = 1;
381 else
382 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
385 #ifdef TARGET_REGNAMES
386 /* If the user desires alternate register names, copy in the alternate names
387 now. */
388 if (TARGET_REGNAMES)
389 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
390 #endif
392 #ifdef SUBTARGET_OVERRIDE_OPTIONS
393 SUBTARGET_OVERRIDE_OPTIONS;
394 #endif
396 /* Register global variables with the garbage collector. */
397 rs6000_add_gc_roots ();
399 /* Allocate an alias set for register saves & restores from stack. */
400 rs6000_sr_alias_set = new_alias_set ();
402 if (TARGET_TOC)
403 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
405 /* Arrange to save and restore machine status around nested functions. */
406 init_machine_status = rs6000_init_machine_status;
407 mark_machine_status = rs6000_mark_machine_status;
408 free_machine_status = rs6000_free_machine_status;
411 void
412 optimization_options (level, size)
413 int level ATTRIBUTE_UNUSED;
414 int size ATTRIBUTE_UNUSED;
418 /* Do anything needed at the start of the asm file. */
420 void
421 rs6000_file_start (file, default_cpu)
422 FILE *file;
423 const char *default_cpu;
425 size_t i;
426 char buffer[80];
427 const char *start = buffer;
428 struct rs6000_cpu_select *ptr;
430 if (flag_verbose_asm)
432 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
433 rs6000_select[0].string = default_cpu;
435 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
437 ptr = &rs6000_select[i];
438 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
440 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
441 start = "";
445 #ifdef USING_SVR4_H
446 switch (rs6000_sdata)
448 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
449 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
450 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
451 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
454 if (rs6000_sdata && g_switch_value)
456 fprintf (file, "%s -G %d", start, g_switch_value);
457 start = "";
459 #endif
461 if (*start == '\0')
462 putc ('\n', file);
467 /* Create a CONST_DOUBLE from a string. */
469 struct rtx_def *
470 rs6000_float_const (string, mode)
471 const char *string;
472 enum machine_mode mode;
474 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
475 return immed_real_const_1 (value, mode);
478 /* Return non-zero if this function is known to have a null epilogue. */
481 direct_return ()
483 if (reload_completed)
485 rs6000_stack_t *info = rs6000_stack_info ();
487 if (info->first_gp_reg_save == 32
488 && info->first_fp_reg_save == 64
489 && ! info->lr_save_p
490 && ! info->cr_save_p
491 && ! info->push_p)
492 return 1;
495 return 0;
498 /* Returns 1 always. */
501 any_operand (op, mode)
502 register rtx op ATTRIBUTE_UNUSED;
503 enum machine_mode mode ATTRIBUTE_UNUSED;
505 return 1;
508 /* Returns 1 if op is the count register */
510 count_register_operand(op, mode)
511 register rtx op;
512 enum machine_mode mode ATTRIBUTE_UNUSED;
514 if (GET_CODE (op) != REG)
515 return 0;
517 if (REGNO (op) == COUNT_REGISTER_REGNUM)
518 return 1;
520 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
521 return 1;
523 return 0;
527 xer_operand(op, mode)
528 register rtx op;
529 enum machine_mode mode ATTRIBUTE_UNUSED;
531 if (GET_CODE (op) != REG)
532 return 0;
534 if (XER_REGNO_P (REGNO (op)))
535 return 1;
537 return 0;
540 /* Return 1 if OP is a constant that can fit in a D field. */
543 short_cint_operand (op, mode)
544 register rtx op;
545 enum machine_mode mode ATTRIBUTE_UNUSED;
547 return (GET_CODE (op) == CONST_INT
548 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
551 /* Similar for a unsigned D field. */
554 u_short_cint_operand (op, mode)
555 register rtx op;
556 enum machine_mode mode ATTRIBUTE_UNUSED;
558 return (GET_CODE (op) == CONST_INT
559 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
562 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
565 non_short_cint_operand (op, mode)
566 register rtx op;
567 enum machine_mode mode ATTRIBUTE_UNUSED;
569 return (GET_CODE (op) == CONST_INT
570 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
573 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
574 ctr, or lr). */
577 gpc_reg_operand (op, mode)
578 register rtx op;
579 enum machine_mode mode;
581 return (register_operand (op, mode)
582 && (GET_CODE (op) != REG
583 || (REGNO (op) >= ARG_POINTER_REGNUM
584 && !XER_REGNO_P (REGNO (op)))
585 || REGNO (op) < MQ_REGNO));
588 /* Returns 1 if OP is either a pseudo-register or a register denoting a
589 CR field. */
592 cc_reg_operand (op, mode)
593 register rtx op;
594 enum machine_mode mode;
596 return (register_operand (op, mode)
597 && (GET_CODE (op) != REG
598 || REGNO (op) >= FIRST_PSEUDO_REGISTER
599 || CR_REGNO_P (REGNO (op))));
602 /* Returns 1 if OP is either a pseudo-register or a register denoting a
603 CR field that isn't CR0. */
606 cc_reg_not_cr0_operand (op, mode)
607 register rtx op;
608 enum machine_mode mode;
610 return (register_operand (op, mode)
611 && (GET_CODE (op) != REG
612 || REGNO (op) >= FIRST_PSEUDO_REGISTER
613 || CR_REGNO_NOT_CR0_P (REGNO (op))));
616 /* Returns 1 if OP is either a constant integer valid for a D-field or a
617 non-special register. If a register, it must be in the proper mode unless
618 MODE is VOIDmode. */
621 reg_or_short_operand (op, mode)
622 register rtx op;
623 enum machine_mode mode;
625 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
628 /* Similar, except check if the negation of the constant would be valid for
629 a D-field. */
632 reg_or_neg_short_operand (op, mode)
633 register rtx op;
634 enum machine_mode mode;
636 if (GET_CODE (op) == CONST_INT)
637 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
639 return gpc_reg_operand (op, mode);
642 /* Return 1 if the operand is either a register or an integer whose high-order
643 16 bits are zero. */
646 reg_or_u_short_operand (op, mode)
647 register rtx op;
648 enum machine_mode mode;
650 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
653 /* Return 1 is the operand is either a non-special register or ANY
654 constant integer. */
657 reg_or_cint_operand (op, mode)
658 register rtx op;
659 enum machine_mode mode;
661 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
664 /* Return 1 is the operand is either a non-special register or ANY
665 32-bit signed constant integer. */
668 reg_or_arith_cint_operand (op, mode)
669 register rtx op;
670 enum machine_mode mode;
672 return (gpc_reg_operand (op, mode)
673 || (GET_CODE (op) == CONST_INT
674 #if HOST_BITS_PER_WIDE_INT != 32
675 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
676 < 0x100000000u)
677 #endif
681 /* Return 1 is the operand is either a non-special register or ANY
682 32-bit unsigned constant integer. */
685 reg_or_logical_cint_operand (op, mode)
686 register rtx op;
687 enum machine_mode mode;
689 if (GET_CODE (op) == CONST_INT)
691 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
693 if (GET_MODE_BITSIZE (mode) <= 32)
694 abort();
696 if (INTVAL (op) < 0)
697 return 0;
700 return ((INTVAL (op) & GET_MODE_MASK (mode)
701 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
703 else if (GET_CODE (op) == CONST_DOUBLE)
705 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
706 || mode != DImode)
707 abort();
709 return CONST_DOUBLE_HIGH (op) == 0;
711 else
712 return gpc_reg_operand (op, mode);
715 /* Return 1 if the operand is an operand that can be loaded via the GOT */
718 got_operand (op, mode)
719 register rtx op;
720 enum machine_mode mode ATTRIBUTE_UNUSED;
722 return (GET_CODE (op) == SYMBOL_REF
723 || GET_CODE (op) == CONST
724 || GET_CODE (op) == LABEL_REF);
727 /* Return 1 if the operand is a simple references that can be loaded via
728 the GOT (labels involving addition aren't allowed). */
731 got_no_const_operand (op, mode)
732 register rtx op;
733 enum machine_mode mode ATTRIBUTE_UNUSED;
735 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
738 /* Return the number of instructions it takes to form a constant in an
739 integer register. */
741 static int
742 num_insns_constant_wide (value)
743 HOST_WIDE_INT value;
745 /* signed constant loadable with {cal|addi} */
746 if (CONST_OK_FOR_LETTER_P (value, 'I'))
747 return 1;
749 /* constant loadable with {cau|addis} */
750 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
751 return 1;
753 #if HOST_BITS_PER_WIDE_INT == 64
754 else if (TARGET_POWERPC64)
756 unsigned HOST_WIDE_INT low = value & 0xffffffff;
757 HOST_WIDE_INT high = value >> 32;
759 if (high == 0 && (low & 0x80000000) == 0)
760 return 2;
762 else if (high == -1 && (low & 0x80000000) != 0)
763 return 2;
765 else if (! low)
766 return num_insns_constant_wide (high) + 1;
768 else
769 return (num_insns_constant_wide (high)
770 + num_insns_constant_wide (low) + 1);
772 #endif
774 else
775 return 2;
779 num_insns_constant (op, mode)
780 rtx op;
781 enum machine_mode mode;
783 if (GET_CODE (op) == CONST_INT)
784 return num_insns_constant_wide (INTVAL (op));
786 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
788 long l;
789 REAL_VALUE_TYPE rv;
791 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
792 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
793 return num_insns_constant_wide ((HOST_WIDE_INT)l);
796 else if (GET_CODE (op) == CONST_DOUBLE)
798 HOST_WIDE_INT low;
799 HOST_WIDE_INT high;
800 long l[2];
801 REAL_VALUE_TYPE rv;
802 int endian = (WORDS_BIG_ENDIAN == 0);
804 if (mode == VOIDmode || mode == DImode)
806 high = CONST_DOUBLE_HIGH (op);
807 low = CONST_DOUBLE_LOW (op);
809 else
811 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
812 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
813 high = l[endian];
814 low = l[1 - endian];
817 if (TARGET_32BIT)
818 return (num_insns_constant_wide (low)
819 + num_insns_constant_wide (high));
821 else
823 if (high == 0 && (low & 0x80000000) == 0)
824 return num_insns_constant_wide (low);
826 else if (high == -1 && (low & 0x80000000) != 0)
827 return num_insns_constant_wide (low);
829 else if (mask64_operand (op, mode))
830 return 2;
832 else if (low == 0)
833 return num_insns_constant_wide (high) + 1;
835 else
836 return (num_insns_constant_wide (high)
837 + num_insns_constant_wide (low) + 1);
841 else
842 abort ();
845 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
846 with one instruction per word. We only do this if we can safely read
847 CONST_DOUBLE_{LOW,HIGH}. */
850 easy_fp_constant (op, mode)
851 register rtx op;
852 register enum machine_mode mode;
854 if (GET_CODE (op) != CONST_DOUBLE
855 || GET_MODE (op) != mode
856 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
857 return 0;
859 /* Consider all constants with -msoft-float to be easy */
860 if (TARGET_SOFT_FLOAT && mode != DImode)
861 return 1;
863 /* If we are using V.4 style PIC, consider all constants to be hard */
864 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
865 return 0;
867 #ifdef TARGET_RELOCATABLE
868 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
869 if (TARGET_RELOCATABLE)
870 return 0;
871 #endif
873 if (mode == DFmode)
875 long k[2];
876 REAL_VALUE_TYPE rv;
878 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
879 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
881 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
882 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
885 else if (mode == SFmode)
887 long l;
888 REAL_VALUE_TYPE rv;
890 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
891 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
893 return num_insns_constant_wide (l) == 1;
896 else if (mode == DImode)
897 return ((TARGET_POWERPC64
898 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
899 || (num_insns_constant (op, DImode) <= 2));
901 else if (mode == SImode)
902 return 1;
903 else
904 abort ();
907 /* Return 1 if the operand is in volatile memory. Note that during the
908 RTL generation phase, memory_operand does not return TRUE for
909 volatile memory references. So this function allows us to
910 recognize volatile references where its safe. */
913 volatile_mem_operand (op, mode)
914 register rtx op;
915 enum machine_mode mode;
917 if (GET_CODE (op) != MEM)
918 return 0;
920 if (!MEM_VOLATILE_P (op))
921 return 0;
923 if (mode != GET_MODE (op))
924 return 0;
926 if (reload_completed)
927 return memory_operand (op, mode);
929 if (reload_in_progress)
930 return strict_memory_address_p (mode, XEXP (op, 0));
932 return memory_address_p (mode, XEXP (op, 0));
935 /* Return 1 if the operand is an offsettable memory operand. */
938 offsettable_mem_operand (op, mode)
939 register rtx op;
940 enum machine_mode mode;
942 return ((GET_CODE (op) == MEM)
943 && offsettable_address_p (reload_completed || reload_in_progress,
944 mode, XEXP (op, 0)));
947 /* Return 1 if the operand is either an easy FP constant (see above) or
948 memory. */
951 mem_or_easy_const_operand (op, mode)
952 register rtx op;
953 enum machine_mode mode;
955 return memory_operand (op, mode) || easy_fp_constant (op, mode);
958 /* Return 1 if the operand is either a non-special register or an item
959 that can be used as the operand of a `mode' add insn. */
962 add_operand (op, mode)
963 register rtx op;
964 enum machine_mode mode;
966 return (reg_or_short_operand (op, mode)
967 || (GET_CODE (op) == CONST_INT
968 && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')));
971 /* Return 1 if OP is a constant but not a valid add_operand. */
974 non_add_cint_operand (op, mode)
975 register rtx op;
976 enum machine_mode mode ATTRIBUTE_UNUSED;
978 return (GET_CODE (op) == CONST_INT
979 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
980 && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'));
983 /* Return 1 if the operand is a non-special register or a constant that
984 can be used as the operand of an OR or XOR insn on the RS/6000. */
987 logical_operand (op, mode)
988 register rtx op;
989 enum machine_mode mode;
991 /* an unsigned representation of 'op'. */
992 unsigned HOST_WIDE_INT opl, oph;
994 if (gpc_reg_operand (op, mode))
995 return 1;
997 if (GET_CODE (op) == CONST_INT)
999 opl = INTVAL (op) & GET_MODE_MASK (mode);
1000 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1001 oph = 0;
1002 else
1003 oph = INTVAL (op) >> (HOST_BITS_PER_WIDE_INT - 1);
1005 else if (GET_CODE (op) == CONST_DOUBLE)
1007 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1008 abort();
1010 opl = CONST_DOUBLE_LOW (op);
1011 oph = CONST_DOUBLE_HIGH (op);
1013 else
1014 return 0;
1016 return (oph == 0
1017 && ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1018 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0));
1021 /* Return 1 if C is a constant that is not a logical operand (as
1022 above), but could be split into one. */
1025 non_logical_cint_operand (op, mode)
1026 register rtx op;
1027 enum machine_mode mode;
1029 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1030 && ! logical_operand (op, mode)
1031 && reg_or_logical_cint_operand (op, mode));
1034 /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
1035 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1036 Reject all ones and all zeros, since these should have been optimized
1037 away and confuse the making of MB and ME. */
1040 mask_operand (op, mode)
1041 register rtx op;
1042 enum machine_mode mode ATTRIBUTE_UNUSED;
1044 HOST_WIDE_INT c;
1045 int i;
1046 int last_bit_value;
1047 int transitions = 0;
1049 if (GET_CODE (op) != CONST_INT)
1050 return 0;
1052 c = INTVAL (op);
1054 if (c == 0 || c == ~0)
1055 return 0;
1057 last_bit_value = c & 1;
1059 for (i = 1; i < 32; i++)
1060 if (((c >>= 1) & 1) != last_bit_value)
1061 last_bit_value ^= 1, transitions++;
1063 return transitions <= 2;
1066 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1067 It is if there are no more than one 1->0 or 0->1 transitions.
1068 Reject all ones and all zeros, since these should have been optimized
1069 away and confuse the making of MB and ME. */
1072 mask64_operand (op, mode)
1073 register rtx op;
1074 enum machine_mode mode;
1076 if (GET_CODE (op) == CONST_INT)
1078 HOST_WIDE_INT c = INTVAL (op);
1079 int i;
1080 int last_bit_value;
1081 int transitions = 0;
1083 if (c == 0 || c == ~0)
1084 return 0;
1086 last_bit_value = c & 1;
1088 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1089 if (((c >>= 1) & 1) != last_bit_value)
1090 last_bit_value ^= 1, transitions++;
1092 return transitions <= 1;
1094 else if (GET_CODE (op) == CONST_DOUBLE
1095 && (mode == VOIDmode || mode == DImode))
1097 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1098 #if HOST_BITS_PER_WIDE_INT == 32
1099 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1100 #endif
1101 int i;
1102 int last_bit_value;
1103 int transitions = 0;
1105 if ((low == 0
1106 #if HOST_BITS_PER_WIDE_INT == 32
1107 && high == 0
1108 #endif
1110 || (low == ~0
1111 #if HOST_BITS_PER_WIDE_INT == 32
1112 && high == ~0
1113 #endif
1115 return 0;
1117 last_bit_value = low & 1;
1119 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1120 if (((low >>= 1) & 1) != last_bit_value)
1121 last_bit_value ^= 1, transitions++;
1123 #if HOST_BITS_PER_WIDE_INT == 32
1124 if ((high & 1) != last_bit_value)
1125 last_bit_value ^= 1, transitions++;
1127 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1128 if (((high >>= 1) & 1) != last_bit_value)
1129 last_bit_value ^= 1, transitions++;
1130 #endif
1132 return transitions <= 1;
1134 else
1135 return 0;
1138 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1139 It is if there are no more than two 1->0 or 0->1 transitions.
1140 Reject all ones and all zeros, since these should have been optimized
1141 away and confuse the making of MB and ME. */
1144 rldic_operand (op, mode)
1145 register rtx op;
1146 enum machine_mode mode;
1148 if (GET_CODE (op) == CONST_INT)
1150 HOST_WIDE_INT c = INTVAL (op);
1151 int i;
1152 int last_bit_value;
1153 int transitions = 0;
1155 if (c == 0 || c == ~0)
1156 return 0;
1158 last_bit_value = c & 1;
1160 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1161 if (((c >>= 1) & 1) != last_bit_value)
1162 last_bit_value ^= 1, transitions++;
1164 return transitions <= 2;
1166 else if (GET_CODE (op) == CONST_DOUBLE
1167 && (mode == VOIDmode || mode == DImode))
1169 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1170 #if HOST_BITS_PER_WIDE_INT == 32
1171 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1172 #endif
1173 int i;
1174 int last_bit_value;
1175 int transitions = 0;
1177 if ((low == 0
1178 #if HOST_BITS_PER_WIDE_INT == 32
1179 && high == 0
1180 #endif
1182 || (low == ~0
1183 #if HOST_BITS_PER_WIDE_INT == 32
1184 && high == ~0
1185 #endif
1187 return 0;
1189 last_bit_value = low & 1;
1191 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1192 if (((low >>= 1) & 1) != last_bit_value)
1193 last_bit_value ^= 1, transitions++;
1195 #if HOST_BITS_PER_WIDE_INT == 32
1196 if ((high & 1) != last_bit_value)
1197 last_bit_value ^= 1, transitions++;
1199 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1200 if (((high >>= 1) & 1) != last_bit_value)
1201 last_bit_value ^= 1, transitions++;
1202 #endif
1204 return transitions <= 2;
1206 else
1207 return 0;
1210 /* Return 1 if the operand is either a non-special register or a constant
1211 that can be used as the operand of a PowerPC64 logical AND insn. */
1214 and64_operand (op, mode)
1215 register rtx op;
1216 enum machine_mode mode;
1218 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1219 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1221 return (logical_operand (op, mode) || mask64_operand (op, mode));
1224 /* Return 1 if the operand is either a non-special register or a
1225 constant that can be used as the operand of an RS/6000 logical AND insn. */
1228 and_operand (op, mode)
1229 register rtx op;
1230 enum machine_mode mode;
1232 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1233 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1235 return (logical_operand (op, mode) || mask_operand (op, mode));
1238 /* Return 1 if the operand is a general register or memory operand. */
1241 reg_or_mem_operand (op, mode)
1242 register rtx op;
1243 register enum machine_mode mode;
1245 return (gpc_reg_operand (op, mode)
1246 || memory_operand (op, mode)
1247 || volatile_mem_operand (op, mode));
1250 /* Return 1 if the operand is a general register or memory operand without
1251 pre_inc or pre_dec which produces invalid form of PowerPC lwa
1252 instruction. */
1255 lwa_operand (op, mode)
1256 register rtx op;
1257 register enum machine_mode mode;
1259 rtx inner = op;
1261 if (reload_completed && GET_CODE (inner) == SUBREG)
1262 inner = SUBREG_REG (inner);
1264 return gpc_reg_operand (inner, mode)
1265 || (memory_operand (inner, mode)
1266 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1267 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1270 /* Return 1 if the operand, used inside a MEM, is a valid first argument
1271 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1272 forced to lr. */
1275 call_operand (op, mode)
1276 register rtx op;
1277 enum machine_mode mode;
1279 if (mode != VOIDmode && GET_MODE (op) != mode)
1280 return 0;
1282 return (GET_CODE (op) == SYMBOL_REF
1283 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1287 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
1288 this file and the function is not weakly defined. */
1291 current_file_function_operand (op, mode)
1292 register rtx op;
1293 enum machine_mode mode ATTRIBUTE_UNUSED;
1295 return (GET_CODE (op) == SYMBOL_REF
1296 && (SYMBOL_REF_FLAG (op)
1297 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1298 && ! DECL_WEAK (current_function_decl))));
1302 /* Return 1 if this operand is a valid input for a move insn. */
1305 input_operand (op, mode)
1306 register rtx op;
1307 enum machine_mode mode;
1309 /* Memory is always valid. */
1310 if (memory_operand (op, mode))
1311 return 1;
1313 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1314 if (GET_CODE (op) == CONSTANT_P_RTX)
1315 return 1;
1317 /* For floating-point, easy constants are valid. */
1318 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1319 && CONSTANT_P (op)
1320 && easy_fp_constant (op, mode))
1321 return 1;
1323 /* Allow any integer constant. */
1324 if (GET_MODE_CLASS (mode) == MODE_INT
1325 && (GET_CODE (op) == CONST_INT
1326 || GET_CODE (op) == CONST_DOUBLE))
1327 return 1;
1329 /* For floating-point or multi-word mode, the only remaining valid type
1330 is a register. */
1331 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1332 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1333 return register_operand (op, mode);
1335 /* The only cases left are integral modes one word or smaller (we
1336 do not get called for MODE_CC values). These can be in any
1337 register. */
1338 if (register_operand (op, mode))
1339 return 1;
1341 /* A SYMBOL_REF referring to the TOC is valid. */
1342 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
1343 return 1;
1345 /* A constant pool expression (relative to the TOC) is valid */
1346 if (TOC_RELATIVE_EXPR_P (op))
1347 return 1;
1349 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1350 to be valid. */
1351 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1352 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1353 && small_data_operand (op, Pmode))
1354 return 1;
1356 return 0;
1359 /* Return 1 for an operand in small memory on V.4/eabi */
1362 small_data_operand (op, mode)
1363 rtx op ATTRIBUTE_UNUSED;
1364 enum machine_mode mode ATTRIBUTE_UNUSED;
1366 #if TARGET_ELF
1367 rtx sym_ref;
1369 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
1370 return 0;
1372 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1373 return 0;
1375 if (GET_CODE (op) == SYMBOL_REF)
1376 sym_ref = op;
1378 else if (GET_CODE (op) != CONST
1379 || GET_CODE (XEXP (op, 0)) != PLUS
1380 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1381 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
1382 return 0;
1384 else
1386 rtx sum = XEXP (op, 0);
1387 HOST_WIDE_INT summand;
1389 /* We have to be careful here, because it is the referenced address
1390 that must be 32k from _SDA_BASE_, not just the symbol. */
1391 summand = INTVAL (XEXP (sum, 1));
1392 if (summand < 0 || summand > g_switch_value)
1393 return 0;
1395 sym_ref = XEXP (sum, 0);
1398 if (*XSTR (sym_ref, 0) != '@')
1399 return 0;
1401 return 1;
1403 #else
1404 return 0;
1405 #endif
1408 static int
1409 constant_pool_expr_1 (op, have_sym, have_toc)
1410 rtx op;
1411 int *have_sym;
1412 int *have_toc;
1414 switch (GET_CODE(op))
1416 case SYMBOL_REF:
1417 if (CONSTANT_POOL_ADDRESS_P (op))
1419 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
1421 *have_sym = 1;
1422 return 1;
1424 else
1425 return 0;
1427 else if (! strcmp (XSTR (op, 0), toc_label_name))
1429 *have_toc = 1;
1430 return 1;
1432 else
1433 return 0;
1434 case PLUS:
1435 case MINUS:
1436 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) &&
1437 constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc);
1438 case CONST:
1439 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
1440 case CONST_INT:
1441 return 1;
1442 default:
1443 return 0;
1448 constant_pool_expr_p (op)
1449 rtx op;
1451 int have_sym = 0;
1452 int have_toc = 0;
1453 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
1457 toc_relative_expr_p (op)
1458 rtx op;
1460 int have_sym = 0;
1461 int have_toc = 0;
1462 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
1465 /* Try machine-dependent ways of modifying an illegitimate address
1466 to be legitimate. If we find one, return the new, valid address.
1467 This is used from only one place: `memory_address' in explow.c.
1469 OLDX is the address as it was before break_out_memory_refs was called.
1470 In some cases it is useful to look at this to decide what needs to be done.
1472 MODE is passed so that this macro can use GO_IF_LEGITIMATE_ADDRESS.
1474 It is always safe for this macro to do nothing. It exists to recognize
1475 opportunities to optimize the output.
1477 On RS/6000, first check for the sum of a register with a constant
1478 integer that is out of range. If so, generate code to add the
1479 constant with the low-order 16 bits masked to the register and force
1480 this result into another register (this can be done with `cau').
1481 Then generate an address of REG+(CONST&0xffff), allowing for the
1482 possibility of bit 16 being a one.
1484 Then check for the sum of a register and something not constant, try to
1485 load the other things into a register and return the sum. */
1487 rs6000_legitimize_address (x, oldx, mode)
1488 rtx x;
1489 rtx oldx ATTRIBUTE_UNUSED;
1490 enum machine_mode mode;
1492 if (GET_CODE (x) == PLUS
1493 && GET_CODE (XEXP (x, 0)) == REG
1494 && GET_CODE (XEXP (x, 1)) == CONST_INT
1495 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
1497 HOST_WIDE_INT high_int, low_int;
1498 rtx sum;
1499 high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff);
1500 low_int = INTVAL (XEXP (x, 1)) & 0xffff;
1501 if (low_int & 0x8000)
1502 high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
1503 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
1504 GEN_INT (high_int)), 0);
1505 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
1507 else if (GET_CODE (x) == PLUS
1508 && GET_CODE (XEXP (x, 0)) == REG
1509 && GET_CODE (XEXP (x, 1)) != CONST_INT
1510 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1511 && (TARGET_POWERPC64 || mode != DImode)
1512 && mode != TImode)
1514 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
1515 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
1517 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
1518 && GET_CODE (x) != CONST_INT
1519 && GET_CODE (x) != CONST_DOUBLE
1520 && CONSTANT_P (x)
1521 && (TARGET_HARD_FLOAT || mode != DFmode)
1522 && mode != DImode
1523 && mode != TImode)
1525 rtx reg = gen_reg_rtx (Pmode);
1526 emit_insn (gen_elf_high (reg, (x)));
1527 return gen_rtx_LO_SUM (Pmode, reg, (x));
1529 else if (TARGET_TOC
1530 && CONSTANT_POOL_EXPR_P (x)
1531 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
1533 return create_TOC_reference (x);
1535 else
1536 return NULL_RTX;
1539 /* Emit a move from SOURCE to DEST in mode MODE. */
1540 void
1541 rs6000_emit_move (dest, source, mode)
1542 rtx dest;
1543 rtx source;
1544 enum machine_mode mode;
1546 rtx operands[2];
1547 operands[0] = dest;
1548 operands[1] = source;
1550 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
1551 if (GET_CODE (operands[1]) == CONST_DOUBLE
1552 && ! FLOAT_MODE_P (mode)
1553 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1555 /* FIXME. This should never happen. */
1556 /* Since it seems that it does, do the safe thing and convert
1557 to a CONST_INT. */
1558 operands[1] =
1559 GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode));
1561 if (GET_CODE (operands[1]) == CONST_DOUBLE
1562 && ! FLOAT_MODE_P (mode)
1563 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
1564 && CONST_DOUBLE_LOW (operands[1]) >= 0)
1565 || (CONST_DOUBLE_HIGH (operands[1]) == -1
1566 && CONST_DOUBLE_LOW (operands[1]) < 0)))
1567 abort ();
1569 if (! no_new_pseudos && GET_CODE (operands[0]) != REG)
1570 operands[1] = force_reg (mode, operands[1]);
1572 if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT
1573 && GET_CODE (operands[0]) == MEM)
1575 int regnum;
1577 if (reload_in_progress || reload_completed)
1578 regnum = true_regnum (operands[1]);
1579 else if (GET_CODE (operands[1]) == REG)
1580 regnum = REGNO (operands[1]);
1581 else
1582 regnum = -1;
1584 /* If operands[1] is a register, on POWER it may have
1585 double-precision data in it, so truncate it to single
1586 precision. */
1587 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
1589 rtx newreg;
1590 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
1591 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
1592 operands[1] = newreg;
1596 /* Handle the case where reload calls us with an invalid address;
1597 and the case of CONSTANT_P_RTX. */
1598 if (! general_operand (operands[1], mode)
1599 || ! nonimmediate_operand (operands[0], mode)
1600 || GET_CODE (operands[1]) == CONSTANT_P_RTX)
1602 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1603 return;
1606 /* FIXME: In the long term, this switch statement should go away
1607 and be replaced by a sequence of tests based on things like
1608 mode == Pmode. */
1609 switch (mode)
1611 case HImode:
1612 case QImode:
1613 if (CONSTANT_P (operands[1])
1614 && GET_CODE (operands[1]) != CONST_INT)
1615 operands[1] = force_const_mem (mode, operands[1]);
1616 break;
1618 case DFmode:
1619 case SFmode:
1620 if (CONSTANT_P (operands[1])
1621 && ! easy_fp_constant (operands[1], mode))
1622 operands[1] = force_const_mem (mode, operands[1]);
1623 break;
1625 case SImode:
1626 case DImode:
1627 /* Use default pattern for address of ELF small data */
1628 if (TARGET_ELF
1629 && mode == Pmode
1630 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1631 && (GET_CODE (operands[1]) == SYMBOL_REF
1632 || GET_CODE (operands[1]) == CONST)
1633 && small_data_operand (operands[1], mode))
1635 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1636 return;
1639 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1640 && mode == Pmode && mode == SImode
1641 && flag_pic == 1 && got_operand (operands[1], mode))
1643 emit_insn (gen_movsi_got (operands[0], operands[1]));
1644 return;
1647 if (TARGET_ELF && TARGET_NO_TOC && ! flag_pic
1648 && mode == Pmode
1649 && CONSTANT_P (operands[1])
1650 && GET_CODE (operands[1]) != HIGH
1651 && GET_CODE (operands[1]) != CONST_INT)
1653 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
1655 /* If this is a function address on -mcall-aixdesc,
1656 convert it to the address of the descriptor. */
1657 if (DEFAULT_ABI == ABI_AIX
1658 && GET_CODE (operands[1]) == SYMBOL_REF
1659 && XSTR (operands[1], 0)[0] == '.')
1661 const char *name = XSTR (operands[1], 0);
1662 rtx new_ref;
1663 while (*name == '.')
1664 name++;
1665 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
1666 CONSTANT_POOL_ADDRESS_P (new_ref)
1667 = CONSTANT_POOL_ADDRESS_P (operands[1]);
1668 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
1669 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
1670 operands[1] = new_ref;
1673 emit_insn (gen_elf_high (target, operands[1]));
1674 emit_insn (gen_elf_low (operands[0], target, operands[1]));
1675 return;
1678 /* If this is a SYMBOL_REF that refers to a constant pool entry,
1679 and we have put it in the TOC, we just need to make a TOC-relative
1680 reference to it. */
1681 if (TARGET_TOC
1682 && GET_CODE (operands[1]) == SYMBOL_REF
1683 && CONSTANT_POOL_EXPR_P (operands[1])
1684 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
1685 get_pool_mode (operands[1])))
1687 operands[1] = create_TOC_reference (operands[1]);
1689 else if (mode == Pmode
1690 && CONSTANT_P (operands[1])
1691 && (((HOST_BITS_PER_WIDE_INT != 32
1692 || GET_CODE (operands[1]) != CONST_INT)
1693 && ! easy_fp_constant (operands[1], mode))
1694 || (GET_CODE (operands[0]) == REG
1695 && FP_REGNO_P (REGNO (operands[0]))))
1696 && GET_CODE (operands[1]) != HIGH
1697 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
1698 && ! TOC_RELATIVE_EXPR_P (operands[1]))
1700 int special_constant_p = 0;
1702 /* Emit a USE operation so that the constant isn't deleted if
1703 expensive optimizations are turned on because nobody
1704 references it. This should only be done for operands that
1705 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
1706 This should not be done for operands that contain LABEL_REFs.
1707 For now, we just handle the obvious case. */
1708 if (GET_CODE (operands[1]) != LABEL_REF)
1709 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
1711 /* If we are to limit the number of things we put in the TOC and
1712 this is a symbol plus a constant we can add in one insn,
1713 just put the symbol in the TOC and add the constant. Don't do
1714 this if reload is in progress. */
1715 if (GET_CODE (operands[1]) == CONST
1716 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
1717 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1718 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
1719 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
1720 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
1721 && ! side_effects_p (operands[0]))
1723 rtx sym = force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
1724 rtx other = XEXP (XEXP (operands[1], 0), 1);
1726 sym = force_reg (mode, sym);
1727 if (mode == SImode)
1728 emit_insn (gen_addsi3 (operands[0], sym, other));
1729 else
1730 emit_insn (gen_adddi3 (operands[0], sym, other));
1731 return;
1734 operands[1] = force_const_mem (mode, operands[1]);
1736 if (TARGET_TOC
1737 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0)))
1739 rtx constant;
1740 enum machine_mode cmode;
1742 constant = get_pool_constant (XEXP (operands[1], 0));
1743 cmode = get_pool_mode (XEXP (operands[1], 0));
1744 special_constant_p =
1745 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (constant, cmode);
1748 if (special_constant_p)
1750 operands[1] = gen_rtx_MEM (mode,
1751 create_TOC_reference (XEXP (operands[1], 0)));
1752 MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set ();
1753 RTX_UNCHANGING_P (operands[1]) = 1;
1756 break;
1758 case TImode:
1759 if (GET_CODE (operands[0]) == MEM
1760 && GET_CODE (XEXP (operands[0], 0)) != REG
1761 && ! reload_in_progress)
1762 operands[0] = change_address (operands[0], TImode,
1763 copy_addr_to_reg (XEXP (operands[0], 0)));
1765 if (GET_CODE (operands[1]) == MEM
1766 && GET_CODE (XEXP (operands[1], 0)) != REG
1767 && ! reload_in_progress)
1768 operands[1] = change_address (operands[1], TImode,
1769 copy_addr_to_reg (XEXP (operands[1], 0)));
1770 break;
1772 default:
1773 abort ();
1776 /* Above, we may have called force_const_mem which may have returned
1777 an invalid address. If we can, fix this up; otherwise, reload will
1778 have to deal with it. */
1779 if (GET_CODE (operands[1]) == MEM
1780 && ! memory_address_p (mode, XEXP (operands[1], 0))
1781 && ! reload_in_progress)
1782 operands[1] = change_address (operands[1], mode,
1783 XEXP (operands[1], 0));
1785 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1786 return;
1789 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1790 for a call to a function whose data type is FNTYPE.
1791 For a library call, FNTYPE is 0.
1793 For incoming args we set the number of arguments in the prototype large
1794 so we never return a PARALLEL. */
1796 void
1797 init_cumulative_args (cum, fntype, libname, incoming)
1798 CUMULATIVE_ARGS *cum;
1799 tree fntype;
1800 rtx libname ATTRIBUTE_UNUSED;
1801 int incoming;
1803 static CUMULATIVE_ARGS zero_cumulative;
1805 *cum = zero_cumulative;
1806 cum->words = 0;
1807 cum->fregno = FP_ARG_MIN_REG;
1808 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
1809 cum->call_cookie = CALL_NORMAL;
1810 cum->sysv_gregno = GP_ARG_MIN_REG;
1812 if (incoming)
1813 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
1815 else if (cum->prototype)
1816 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1817 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1818 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1820 else
1821 cum->nargs_prototype = 0;
1823 cum->orig_nargs = cum->nargs_prototype;
1825 /* Check for longcall's */
1826 if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1827 cum->call_cookie = CALL_LONG;
1829 if (TARGET_DEBUG_ARG)
1831 fprintf (stderr, "\ninit_cumulative_args:");
1832 if (fntype)
1834 tree ret_type = TREE_TYPE (fntype);
1835 fprintf (stderr, " ret code = %s,",
1836 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1839 if (cum->call_cookie & CALL_LONG)
1840 fprintf (stderr, " longcall,");
1842 fprintf (stderr, " proto = %d, nargs = %d\n",
1843 cum->prototype, cum->nargs_prototype);
1847 /* If defined, a C expression which determines whether, and in which
1848 direction, to pad out an argument with extra space. The value
1849 should be of type `enum direction': either `upward' to pad above
1850 the argument, `downward' to pad below, or `none' to inhibit
1851 padding.
1853 For the AIX ABI structs are always stored left shifted in their
1854 argument slot. */
1856 enum direction
1857 function_arg_padding (mode, type)
1858 enum machine_mode mode;
1859 tree type;
1861 if (type != 0 && AGGREGATE_TYPE_P (type))
1862 return upward;
1864 /* This is the default definition. */
1865 return (! BYTES_BIG_ENDIAN
1866 ? upward
1867 : ((mode == BLKmode
1868 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1869 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1870 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
1871 ? downward : upward));
1874 /* If defined, a C expression that gives the alignment boundary, in bits,
1875 of an argument with the specified mode and type. If it is not defined,
1876 PARM_BOUNDARY is used for all arguments.
1878 V.4 wants long longs to be double word aligned. */
1881 function_arg_boundary (mode, type)
1882 enum machine_mode mode;
1883 tree type ATTRIBUTE_UNUSED;
1885 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1886 && (mode == DImode || mode == DFmode))
1887 return 64;
1888 else
1889 return PARM_BOUNDARY;
1892 /* Update the data in CUM to advance over an argument
1893 of mode MODE and data type TYPE.
1894 (TYPE is null for libcalls where that information may not be available.) */
1896 void
1897 function_arg_advance (cum, mode, type, named)
1898 CUMULATIVE_ARGS *cum;
1899 enum machine_mode mode;
1900 tree type;
1901 int named;
1903 cum->nargs_prototype--;
1905 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1907 if (TARGET_HARD_FLOAT
1908 && (mode == SFmode || mode == DFmode))
1910 if (cum->fregno <= FP_ARG_V4_MAX_REG)
1911 cum->fregno++;
1912 else
1914 if (mode == DFmode)
1915 cum->words += cum->words & 1;
1916 cum->words += RS6000_ARG_SIZE (mode, type);
1919 else
1921 int n_words;
1922 int gregno = cum->sysv_gregno;
1924 /* Aggregates and IEEE quad get passed by reference. */
1925 if ((type && AGGREGATE_TYPE_P (type))
1926 || mode == TFmode)
1927 n_words = 1;
1928 else
1929 n_words = RS6000_ARG_SIZE (mode, type);
1931 /* Long long is put in odd registers. */
1932 if (n_words == 2 && (gregno & 1) == 0)
1933 gregno += 1;
1935 /* Long long is not split between registers and stack. */
1936 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
1938 /* Long long is aligned on the stack. */
1939 if (n_words == 2)
1940 cum->words += cum->words & 1;
1941 cum->words += n_words;
1944 /* Note: continuing to accumulate gregno past when we've started
1945 spilling to the stack indicates the fact that we've started
1946 spilling to the stack to expand_builtin_saveregs. */
1947 cum->sysv_gregno = gregno + n_words;
1950 if (TARGET_DEBUG_ARG)
1952 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1953 cum->words, cum->fregno);
1954 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
1955 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
1956 fprintf (stderr, "mode = %4s, named = %d\n",
1957 GET_MODE_NAME (mode), named);
1960 else
1962 int align = (TARGET_32BIT && (cum->words & 1) != 0
1963 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1964 cum->words += align + RS6000_ARG_SIZE (mode, type);
1966 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
1967 cum->fregno++;
1969 if (TARGET_DEBUG_ARG)
1971 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
1972 cum->words, cum->fregno);
1973 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
1974 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
1975 fprintf (stderr, "named = %d, align = %d\n", named, align);
1980 /* Determine where to put an argument to a function.
1981 Value is zero to push the argument on the stack,
1982 or a hard register in which to store the argument.
1984 MODE is the argument's machine mode.
1985 TYPE is the data type of the argument (as a tree).
1986 This is null for libcalls where that information may
1987 not be available.
1988 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1989 the preceding args and about the function being called.
1990 NAMED is nonzero if this argument is a named parameter
1991 (otherwise it is an extra parameter matching an ellipsis).
1993 On RS/6000 the first eight words of non-FP are normally in registers
1994 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
1995 Under V.4, the first 8 FP args are in registers.
1997 If this is floating-point and no prototype is specified, we use
1998 both an FP and integer register (or possibly FP reg and stack). Library
1999 functions (when TYPE is zero) always have the proper types for args,
2000 so we can pass the FP value just in one register. emit_library_function
2001 doesn't support PARALLEL anyway. */
2003 struct rtx_def *
2004 function_arg (cum, mode, type, named)
2005 CUMULATIVE_ARGS *cum;
2006 enum machine_mode mode;
2007 tree type;
2008 int named ATTRIBUTE_UNUSED;
2010 enum rs6000_abi abi = DEFAULT_ABI;
2012 /* Return a marker to indicate whether CR1 needs to set or clear the bit
2013 that V.4 uses to say fp args were passed in registers. Assume that we
2014 don't need the marker for software floating point, or compiler generated
2015 library calls. */
2016 if (mode == VOIDmode)
2018 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
2019 && TARGET_HARD_FLOAT
2020 && cum->nargs_prototype < 0
2021 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
2023 return GEN_INT (cum->call_cookie
2024 | ((cum->fregno == FP_ARG_MIN_REG)
2025 ? CALL_V4_SET_FP_ARGS
2026 : CALL_V4_CLEAR_FP_ARGS));
2029 return GEN_INT (cum->call_cookie);
2032 if (abi == ABI_V4 || abi == ABI_SOLARIS)
2034 if (TARGET_HARD_FLOAT
2035 && (mode == SFmode || mode == DFmode))
2037 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2038 return gen_rtx_REG (mode, cum->fregno);
2039 else
2040 return NULL;
2042 else
2044 int n_words;
2045 int gregno = cum->sysv_gregno;
2047 /* Aggregates and IEEE quad get passed by reference. */
2048 if ((type && AGGREGATE_TYPE_P (type))
2049 || mode == TFmode)
2050 n_words = 1;
2051 else
2052 n_words = RS6000_ARG_SIZE (mode, type);
2054 /* Long long is put in odd registers. */
2055 if (n_words == 2 && (gregno & 1) == 0)
2056 gregno += 1;
2058 /* Long long is not split between registers and stack. */
2059 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
2060 return gen_rtx_REG (mode, gregno);
2061 else
2062 return NULL;
2065 else
2067 int align = (TARGET_32BIT && (cum->words & 1) != 0
2068 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2069 int align_words = cum->words + align;
2071 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2072 return NULL_RTX;
2074 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2076 if (! type
2077 || ((cum->nargs_prototype > 0)
2078 /* IBM AIX extended its linkage convention definition always
2079 to require FP args after register save area hole on the
2080 stack. */
2081 && (DEFAULT_ABI != ABI_AIX
2082 || ! TARGET_XL_CALL
2083 || (align_words < GP_ARG_NUM_REG))))
2084 return gen_rtx_REG (mode, cum->fregno);
2086 return gen_rtx_PARALLEL (mode,
2087 gen_rtvec (2,
2088 gen_rtx_EXPR_LIST (VOIDmode,
2089 ((align_words >= GP_ARG_NUM_REG)
2090 ? NULL_RTX
2091 : (align_words
2092 + RS6000_ARG_SIZE (mode, type)
2093 > GP_ARG_NUM_REG
2094 /* If this is partially on the stack, then
2095 we only include the portion actually
2096 in registers here. */
2097 ? gen_rtx_REG (SImode,
2098 GP_ARG_MIN_REG + align_words)
2099 : gen_rtx_REG (mode,
2100 GP_ARG_MIN_REG + align_words))),
2101 const0_rtx),
2102 gen_rtx_EXPR_LIST (VOIDmode,
2103 gen_rtx_REG (mode, cum->fregno),
2104 const0_rtx)));
2106 else if (align_words < GP_ARG_NUM_REG)
2107 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
2108 else
2109 return NULL_RTX;
2113 /* For an arg passed partly in registers and partly in memory,
2114 this is the number of registers used.
2115 For args passed entirely in registers or entirely in memory, zero. */
2118 function_arg_partial_nregs (cum, mode, type, named)
2119 CUMULATIVE_ARGS *cum;
2120 enum machine_mode mode;
2121 tree type;
2122 int named ATTRIBUTE_UNUSED;
2124 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2125 return 0;
2127 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2129 if (cum->nargs_prototype >= 0)
2130 return 0;
2133 if (cum->words < GP_ARG_NUM_REG
2134 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
2136 int ret = GP_ARG_NUM_REG - cum->words;
2137 if (ret && TARGET_DEBUG_ARG)
2138 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2140 return ret;
2143 return 0;
2146 /* A C expression that indicates when an argument must be passed by
2147 reference. If nonzero for an argument, a copy of that argument is
2148 made in memory and a pointer to the argument is passed instead of
2149 the argument itself. The pointer is passed in whatever way is
2150 appropriate for passing a pointer to that type.
2152 Under V.4, structures and unions are passed by reference. */
2155 function_arg_pass_by_reference (cum, mode, type, named)
2156 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2157 enum machine_mode mode ATTRIBUTE_UNUSED;
2158 tree type;
2159 int named ATTRIBUTE_UNUSED;
2161 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2162 && ((type && AGGREGATE_TYPE_P (type))
2163 || mode == TFmode))
2165 if (TARGET_DEBUG_ARG)
2166 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
2168 return 1;
2171 return 0;
2174 /* Perform any needed actions needed for a function that is receiving a
2175 variable number of arguments.
2177 CUM is as above.
2179 MODE and TYPE are the mode and type of the current parameter.
2181 PRETEND_SIZE is a variable that should be set to the amount of stack
2182 that must be pushed by the prolog to pretend that our caller pushed
2185 Normally, this macro will push all remaining incoming registers on the
2186 stack and set PRETEND_SIZE to the length of the registers pushed. */
2188 void
2189 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2190 CUMULATIVE_ARGS *cum;
2191 enum machine_mode mode;
2192 tree type;
2193 int *pretend_size;
2194 int no_rtl;
2197 CUMULATIVE_ARGS next_cum;
2198 int reg_size = TARGET_32BIT ? 4 : 8;
2199 rtx save_area, mem;
2200 int first_reg_offset, set;
2201 tree fntype;
2202 int stdarg_p;
2204 fntype = TREE_TYPE (current_function_decl);
2205 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
2206 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2207 != void_type_node));
2209 /* For varargs, we do not want to skip the dummy va_dcl argument.
2210 For stdargs, we do want to skip the last named argument. */
2211 next_cum = *cum;
2212 if (stdarg_p)
2213 function_arg_advance (&next_cum, mode, type, 1);
2215 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2217 /* Indicate to allocate space on the stack for varargs save area. */
2218 /* ??? Does this really have to be located at a magic spot on the
2219 stack, or can we allocate this with assign_stack_local instead. */
2220 cfun->machine->sysv_varargs_p = 1;
2221 if (! no_rtl)
2222 save_area = plus_constant (virtual_stack_vars_rtx,
2223 - RS6000_VARARGS_SIZE);
2225 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
2227 else
2229 first_reg_offset = next_cum.words;
2230 save_area = virtual_incoming_args_rtx;
2231 cfun->machine->sysv_varargs_p = 0;
2233 if (MUST_PASS_IN_STACK (mode, type))
2234 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
2237 set = get_varargs_alias_set ();
2238 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
2240 mem = gen_rtx_MEM (BLKmode,
2241 plus_constant (save_area,
2242 first_reg_offset * reg_size)),
2243 MEM_ALIAS_SET (mem) = set;
2245 move_block_from_reg
2246 (GP_ARG_MIN_REG + first_reg_offset, mem,
2247 GP_ARG_NUM_REG - first_reg_offset,
2248 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
2250 /* ??? Does ABI_V4 need this at all? */
2251 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
2254 /* Save FP registers if needed. */
2255 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2256 && TARGET_HARD_FLOAT && ! no_rtl
2257 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
2259 int fregno = next_cum.fregno;
2260 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
2261 rtx lab = gen_label_rtx ();
2262 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
2264 emit_jump_insn (gen_rtx_SET (VOIDmode,
2265 pc_rtx,
2266 gen_rtx_IF_THEN_ELSE (VOIDmode,
2267 gen_rtx_NE (VOIDmode, cr1,
2268 const0_rtx),
2269 gen_rtx_LABEL_REF (VOIDmode, lab),
2270 pc_rtx)));
2272 while (fregno <= FP_ARG_V4_MAX_REG)
2274 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
2275 MEM_ALIAS_SET (mem) = set;
2276 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
2277 fregno++;
2278 off += 8;
2281 emit_label (lab);
2285 /* Create the va_list data type. */
2287 tree
2288 rs6000_build_va_list ()
2290 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
2292 /* For AIX, prefer 'char *' because that's what the system
2293 header files like. */
2294 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2295 return build_pointer_type (char_type_node);
2297 record = make_lang_type (RECORD_TYPE);
2298 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2300 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
2301 unsigned_char_type_node);
2302 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
2303 unsigned_char_type_node);
2304 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
2305 ptr_type_node);
2306 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
2307 ptr_type_node);
2309 DECL_FIELD_CONTEXT (f_gpr) = record;
2310 DECL_FIELD_CONTEXT (f_fpr) = record;
2311 DECL_FIELD_CONTEXT (f_ovf) = record;
2312 DECL_FIELD_CONTEXT (f_sav) = record;
2314 TREE_CHAIN (record) = type_decl;
2315 TYPE_NAME (record) = type_decl;
2316 TYPE_FIELDS (record) = f_gpr;
2317 TREE_CHAIN (f_gpr) = f_fpr;
2318 TREE_CHAIN (f_fpr) = f_ovf;
2319 TREE_CHAIN (f_ovf) = f_sav;
2321 layout_type (record);
2323 /* The correct type is an array type of one element. */
2324 return build_array_type (record, build_index_type (size_zero_node));
2327 /* Implement va_start. */
2329 void
2330 rs6000_va_start (stdarg_p, valist, nextarg)
2331 int stdarg_p;
2332 tree valist;
2333 rtx nextarg;
2335 HOST_WIDE_INT words, n_gpr, n_fpr;
2336 tree f_gpr, f_fpr, f_ovf, f_sav;
2337 tree gpr, fpr, ovf, sav, t;
2339 /* Only SVR4 needs something special. */
2340 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2342 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2343 return;
2346 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2347 f_fpr = TREE_CHAIN (f_gpr);
2348 f_ovf = TREE_CHAIN (f_fpr);
2349 f_sav = TREE_CHAIN (f_ovf);
2351 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2352 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2353 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2354 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2355 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2357 /* Count number of gp and fp argument registers used. */
2358 words = current_function_args_info.words;
2359 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
2360 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
2362 if (TARGET_DEBUG_ARG)
2363 fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n",
2364 words, n_gpr, n_fpr);
2366 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
2367 TREE_SIDE_EFFECTS (t) = 1;
2368 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2370 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
2371 TREE_SIDE_EFFECTS (t) = 1;
2372 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2374 /* Find the overflow area. */
2375 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
2376 if (words != 0)
2377 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
2378 build_int_2 (words * UNITS_PER_WORD, 0));
2379 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2380 TREE_SIDE_EFFECTS (t) = 1;
2381 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2383 /* Find the register save area. */
2384 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
2385 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
2386 build_int_2 (-RS6000_VARARGS_SIZE, -1));
2387 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
2388 TREE_SIDE_EFFECTS (t) = 1;
2389 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2392 /* Implement va_arg. */
2395 rs6000_va_arg (valist, type)
2396 tree valist, type;
2398 tree f_gpr, f_fpr, f_ovf, f_sav;
2399 tree gpr, fpr, ovf, sav, reg, t, u;
2400 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
2401 rtx lab_false, lab_over, addr_rtx, r;
2403 /* For AIX, the rule is that structures are passed left-aligned in
2404 their stack slot. However, GCC does not presently do this:
2405 structures which are the same size as integer types are passed
2406 right-aligned, as if they were in fact integers. This only
2407 matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */
2408 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2410 HOST_WIDE_INT align, rounded_size;
2411 enum machine_mode mode;
2412 tree addr_tree;
2414 /* Compute the rounded size of the type. */
2415 align = PARM_BOUNDARY / BITS_PER_UNIT;
2416 rounded_size = (((int_size_in_bytes (type) + align - 1) / align)
2417 * align);
2419 addr_tree = valist;
2421 mode = TYPE_MODE (type);
2422 if (mode != BLKmode)
2424 HOST_WIDE_INT adj;
2425 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2426 if (rounded_size > align)
2427 adj = rounded_size;
2429 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2430 build_int_2 (rounded_size - adj, 0));
2433 addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2434 addr_rtx = copy_to_reg (addr_rtx);
2436 /* Compute new value for AP. */
2437 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2438 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2439 build_int_2 (rounded_size, 0)));
2440 TREE_SIDE_EFFECTS (t) = 1;
2441 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2443 return addr_rtx;
2446 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2447 f_fpr = TREE_CHAIN (f_gpr);
2448 f_ovf = TREE_CHAIN (f_fpr);
2449 f_sav = TREE_CHAIN (f_ovf);
2451 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2452 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2453 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2454 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2455 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2457 size = int_size_in_bytes (type);
2458 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2460 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
2462 /* Aggregates and long doubles are passed by reference. */
2463 indirect_p = 1;
2464 reg = gpr;
2465 n_reg = 1;
2466 sav_ofs = 0;
2467 sav_scale = 4;
2468 size = rsize = UNITS_PER_WORD;
2470 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
2472 /* FP args go in FP registers, if present. */
2473 indirect_p = 0;
2474 reg = fpr;
2475 n_reg = 1;
2476 sav_ofs = 8*4;
2477 sav_scale = 8;
2479 else
2481 /* Otherwise into GP registers. */
2482 indirect_p = 0;
2483 reg = gpr;
2484 n_reg = rsize;
2485 sav_ofs = 0;
2486 sav_scale = 4;
2490 * Pull the value out of the saved registers ...
2493 lab_false = gen_label_rtx ();
2494 lab_over = gen_label_rtx ();
2495 addr_rtx = gen_reg_rtx (Pmode);
2497 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
2498 GEN_INT (8 - n_reg + 1),
2499 GE, const1_rtx, QImode, 1, 1, lab_false);
2501 /* Long long is aligned in the registers. */
2502 if (n_reg > 1)
2504 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
2505 build_int_2 (n_reg - 1, 0));
2506 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
2507 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
2508 TREE_SIDE_EFFECTS (u) = 1;
2509 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
2512 if (sav_ofs)
2513 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2514 else
2515 t = sav;
2517 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
2518 TREE_SIDE_EFFECTS (u) = 1;
2520 u = build1 (CONVERT_EXPR, integer_type_node, u);
2521 TREE_SIDE_EFFECTS (u) = 1;
2523 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
2524 TREE_SIDE_EFFECTS (u) = 1;
2526 t = build (PLUS_EXPR, ptr_type_node, t, u);
2527 TREE_SIDE_EFFECTS (t) = 1;
2529 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2530 if (r != addr_rtx)
2531 emit_move_insn (addr_rtx, r);
2533 emit_jump_insn (gen_jump (lab_over));
2534 emit_barrier ();
2535 emit_label (lab_false);
2538 * ... otherwise out of the overflow area.
2541 /* Make sure we don't find reg 7 for the next int arg. */
2542 if (n_reg > 1)
2544 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
2545 TREE_SIDE_EFFECTS (t) = 1;
2546 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2549 /* Care for on-stack alignment if needed. */
2550 if (rsize <= 1)
2551 t = ovf;
2552 else
2554 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
2555 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
2557 t = save_expr (t);
2559 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2560 if (r != addr_rtx)
2561 emit_move_insn (addr_rtx, r);
2563 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
2564 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2565 TREE_SIDE_EFFECTS (t) = 1;
2566 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2568 emit_label (lab_over);
2570 if (indirect_p)
2572 r = gen_rtx_MEM (Pmode, addr_rtx);
2573 MEM_ALIAS_SET (r) = get_varargs_alias_set ();
2574 emit_move_insn (addr_rtx, r);
2577 return addr_rtx;
2580 /* Generate a memory reference for expand_block_move, copying volatile,
2581 and other bits from an original memory reference. */
2583 static rtx
2584 expand_block_move_mem (mode, addr, orig_mem)
2585 enum machine_mode mode;
2586 rtx addr;
2587 rtx orig_mem;
2589 rtx mem = gen_rtx_MEM (mode, addr);
2591 MEM_COPY_ATTRIBUTES (mem, orig_mem);
2592 #ifdef MEM_UNALIGNED_P
2593 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
2594 #endif
2595 return mem;
2598 /* Expand a block move operation, and return 1 if successful. Return 0
2599 if we should let the compiler generate normal code.
2601 operands[0] is the destination
2602 operands[1] is the source
2603 operands[2] is the length
2604 operands[3] is the alignment */
2606 #define MAX_MOVE_REG 4
2609 expand_block_move (operands)
2610 rtx operands[];
2612 rtx orig_dest = operands[0];
2613 rtx orig_src = operands[1];
2614 rtx bytes_rtx = operands[2];
2615 rtx align_rtx = operands[3];
2616 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2617 int align;
2618 int bytes;
2619 int offset;
2620 int num_reg;
2621 int i;
2622 rtx src_reg;
2623 rtx dest_reg;
2624 rtx src_addr;
2625 rtx dest_addr;
2626 rtx tmp_reg;
2627 rtx stores[MAX_MOVE_REG];
2628 int move_bytes;
2630 /* If this is not a fixed size move, just call memcpy */
2631 if (! constp)
2632 return 0;
2634 /* If this is not a fixed size alignment, abort */
2635 if (GET_CODE (align_rtx) != CONST_INT)
2636 abort ();
2637 align = INTVAL (align_rtx);
2639 /* Anything to move? */
2640 bytes = INTVAL (bytes_rtx);
2641 if (bytes <= 0)
2642 return 1;
2644 /* Don't support real large moves. If string instructions are not used,
2645 then don't generate more than 8 loads. */
2646 if (TARGET_STRING)
2648 if (bytes > 8*4)
2649 return 0;
2651 else if (! STRICT_ALIGNMENT)
2653 if (TARGET_POWERPC64 && align >= 4)
2655 if (bytes > 8*8)
2656 return 0;
2658 else
2659 if (bytes > 8*4)
2660 return 0;
2662 else if (bytes > 8*align)
2663 return 0;
2665 /* Move the address into scratch registers. */
2666 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2667 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2669 if (TARGET_STRING) /* string instructions are available */
2671 for ( ; bytes > 0; bytes -= move_bytes)
2673 if (bytes > 24 /* move up to 32 bytes at a time */
2674 && ! fixed_regs[5]
2675 && ! fixed_regs[6]
2676 && ! fixed_regs[7]
2677 && ! fixed_regs[8]
2678 && ! fixed_regs[9]
2679 && ! fixed_regs[10]
2680 && ! fixed_regs[11]
2681 && ! fixed_regs[12])
2683 move_bytes = (bytes > 32) ? 32 : bytes;
2684 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
2685 dest_reg,
2686 orig_dest),
2687 expand_block_move_mem (BLKmode,
2688 src_reg,
2689 orig_src),
2690 GEN_INT ((move_bytes == 32)
2691 ? 0 : move_bytes),
2692 align_rtx));
2694 else if (bytes > 16 /* move up to 24 bytes at a time */
2695 && ! fixed_regs[5]
2696 && ! fixed_regs[6]
2697 && ! fixed_regs[7]
2698 && ! fixed_regs[8]
2699 && ! fixed_regs[9]
2700 && ! fixed_regs[10])
2702 move_bytes = (bytes > 24) ? 24 : bytes;
2703 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
2704 dest_reg,
2705 orig_dest),
2706 expand_block_move_mem (BLKmode,
2707 src_reg,
2708 orig_src),
2709 GEN_INT (move_bytes),
2710 align_rtx));
2712 else if (bytes > 8 /* move up to 16 bytes at a time */
2713 && ! fixed_regs[5]
2714 && ! fixed_regs[6]
2715 && ! fixed_regs[7]
2716 && ! fixed_regs[8])
2718 move_bytes = (bytes > 16) ? 16 : bytes;
2719 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
2720 dest_reg,
2721 orig_dest),
2722 expand_block_move_mem (BLKmode,
2723 src_reg,
2724 orig_src),
2725 GEN_INT (move_bytes),
2726 align_rtx));
2728 else if (bytes >= 8 && TARGET_POWERPC64
2729 /* 64-bit loads and stores require word-aligned displacements. */
2730 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2732 move_bytes = 8;
2733 tmp_reg = gen_reg_rtx (DImode);
2734 emit_move_insn (tmp_reg,
2735 expand_block_move_mem (DImode,
2736 src_reg, orig_src));
2737 emit_move_insn (expand_block_move_mem (DImode,
2738 dest_reg, orig_dest),
2739 tmp_reg);
2741 else if (bytes > 4)
2742 { /* move up to 8 bytes at a time */
2743 move_bytes = (bytes > 8) ? 8 : bytes;
2744 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
2745 dest_reg,
2746 orig_dest),
2747 expand_block_move_mem (BLKmode,
2748 src_reg,
2749 orig_src),
2750 GEN_INT (move_bytes),
2751 align_rtx));
2753 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2754 { /* move 4 bytes */
2755 move_bytes = 4;
2756 tmp_reg = gen_reg_rtx (SImode);
2757 emit_move_insn (tmp_reg,
2758 expand_block_move_mem (SImode,
2759 src_reg, orig_src));
2760 emit_move_insn (expand_block_move_mem (SImode,
2761 dest_reg, orig_dest),
2762 tmp_reg);
2764 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2765 { /* move 2 bytes */
2766 move_bytes = 2;
2767 tmp_reg = gen_reg_rtx (HImode);
2768 emit_move_insn (tmp_reg,
2769 expand_block_move_mem (HImode,
2770 src_reg, orig_src));
2771 emit_move_insn (expand_block_move_mem (HImode,
2772 dest_reg, orig_dest),
2773 tmp_reg);
2775 else if (bytes == 1) /* move 1 byte */
2777 move_bytes = 1;
2778 tmp_reg = gen_reg_rtx (QImode);
2779 emit_move_insn (tmp_reg,
2780 expand_block_move_mem (QImode,
2781 src_reg, orig_src));
2782 emit_move_insn (expand_block_move_mem (QImode,
2783 dest_reg, orig_dest),
2784 tmp_reg);
2786 else
2787 { /* move up to 4 bytes at a time */
2788 move_bytes = (bytes > 4) ? 4 : bytes;
2789 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
2790 dest_reg,
2791 orig_dest),
2792 expand_block_move_mem (BLKmode,
2793 src_reg,
2794 orig_src),
2795 GEN_INT (move_bytes),
2796 align_rtx));
2799 if (bytes > move_bytes)
2801 if (! TARGET_POWERPC64)
2803 emit_insn (gen_addsi3 (src_reg, src_reg,
2804 GEN_INT (move_bytes)));
2805 emit_insn (gen_addsi3 (dest_reg, dest_reg,
2806 GEN_INT (move_bytes)));
2808 else
2810 emit_insn (gen_adddi3 (src_reg, src_reg,
2811 GEN_INT (move_bytes)));
2812 emit_insn (gen_adddi3 (dest_reg, dest_reg,
2813 GEN_INT (move_bytes)));
2819 else /* string instructions not available */
2821 num_reg = offset = 0;
2822 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2824 /* Calculate the correct offset for src/dest */
2825 if (offset == 0)
2827 src_addr = src_reg;
2828 dest_addr = dest_reg;
2830 else
2832 src_addr = plus_constant (src_reg, offset);
2833 dest_addr = plus_constant (dest_reg, offset);
2836 /* Generate the appropriate load and store, saving the stores
2837 for later. */
2838 if (bytes >= 8 && TARGET_POWERPC64
2839 /* 64-bit loads and stores require word-aligned displacements. */
2840 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2842 move_bytes = 8;
2843 tmp_reg = gen_reg_rtx (DImode);
2844 emit_insn (gen_movdi (tmp_reg,
2845 expand_block_move_mem (DImode,
2846 src_addr,
2847 orig_src)));
2848 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
2849 dest_addr,
2850 orig_dest),
2851 tmp_reg);
2853 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2855 move_bytes = 4;
2856 tmp_reg = gen_reg_rtx (SImode);
2857 emit_insn (gen_movsi (tmp_reg,
2858 expand_block_move_mem (SImode,
2859 src_addr,
2860 orig_src)));
2861 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
2862 dest_addr,
2863 orig_dest),
2864 tmp_reg);
2866 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2868 move_bytes = 2;
2869 tmp_reg = gen_reg_rtx (HImode);
2870 emit_insn (gen_movhi (tmp_reg,
2871 expand_block_move_mem (HImode,
2872 src_addr,
2873 orig_src)));
2874 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
2875 dest_addr,
2876 orig_dest),
2877 tmp_reg);
2879 else
2881 move_bytes = 1;
2882 tmp_reg = gen_reg_rtx (QImode);
2883 emit_insn (gen_movqi (tmp_reg,
2884 expand_block_move_mem (QImode,
2885 src_addr,
2886 orig_src)));
2887 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
2888 dest_addr,
2889 orig_dest),
2890 tmp_reg);
2893 if (num_reg >= MAX_MOVE_REG)
2895 for (i = 0; i < num_reg; i++)
2896 emit_insn (stores[i]);
2897 num_reg = 0;
2901 for (i = 0; i < num_reg; i++)
2902 emit_insn (stores[i]);
2905 return 1;
2909 /* Return 1 if OP is a load multiple operation. It is known to be a
2910 PARALLEL and the first section will be tested. */
2913 load_multiple_operation (op, mode)
2914 rtx op;
2915 enum machine_mode mode ATTRIBUTE_UNUSED;
2917 int count = XVECLEN (op, 0);
2918 unsigned int dest_regno;
2919 rtx src_addr;
2920 int i;
2922 /* Perform a quick check so we don't blow up below. */
2923 if (count <= 1
2924 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2925 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
2926 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
2927 return 0;
2929 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
2930 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
2932 for (i = 1; i < count; i++)
2934 rtx elt = XVECEXP (op, 0, i);
2936 if (GET_CODE (elt) != SET
2937 || GET_CODE (SET_DEST (elt)) != REG
2938 || GET_MODE (SET_DEST (elt)) != SImode
2939 || REGNO (SET_DEST (elt)) != dest_regno + i
2940 || GET_CODE (SET_SRC (elt)) != MEM
2941 || GET_MODE (SET_SRC (elt)) != SImode
2942 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2943 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2944 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2945 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
2946 return 0;
2949 return 1;
2952 /* Similar, but tests for store multiple. Here, the second vector element
2953 is a CLOBBER. It will be tested later. */
2956 store_multiple_operation (op, mode)
2957 rtx op;
2958 enum machine_mode mode ATTRIBUTE_UNUSED;
2960 int count = XVECLEN (op, 0) - 1;
2961 unsigned int src_regno;
2962 rtx dest_addr;
2963 int i;
2965 /* Perform a quick check so we don't blow up below. */
2966 if (count <= 1
2967 || GET_CODE (XVECEXP (op, 0, 0)) != SET
2968 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
2969 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
2970 return 0;
2972 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
2973 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
2975 for (i = 1; i < count; i++)
2977 rtx elt = XVECEXP (op, 0, i + 1);
2979 if (GET_CODE (elt) != SET
2980 || GET_CODE (SET_SRC (elt)) != REG
2981 || GET_MODE (SET_SRC (elt)) != SImode
2982 || REGNO (SET_SRC (elt)) != src_regno + i
2983 || GET_CODE (SET_DEST (elt)) != MEM
2984 || GET_MODE (SET_DEST (elt)) != SImode
2985 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2986 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2987 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2988 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
2989 return 0;
2992 return 1;
2995 /* Return 1 for an PARALLEL suitable for mtcrf. */
2998 mtcrf_operation (op, mode)
2999 rtx op;
3000 enum machine_mode mode ATTRIBUTE_UNUSED;
3002 int count = XVECLEN (op, 0);
3003 int i;
3004 rtx src_reg;
3006 /* Perform a quick check so we don't blow up below. */
3007 if (count < 1
3008 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3009 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
3010 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
3011 return 0;
3012 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
3014 if (GET_CODE (src_reg) != REG
3015 || GET_MODE (src_reg) != SImode
3016 || ! INT_REGNO_P (REGNO (src_reg)))
3017 return 0;
3019 for (i = 0; i < count; i++)
3021 rtx exp = XVECEXP (op, 0, i);
3022 rtx unspec;
3023 int maskval;
3025 if (GET_CODE (exp) != SET
3026 || GET_CODE (SET_DEST (exp)) != REG
3027 || GET_MODE (SET_DEST (exp)) != CCmode
3028 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
3029 return 0;
3030 unspec = SET_SRC (exp);
3031 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
3033 if (GET_CODE (unspec) != UNSPEC
3034 || XINT (unspec, 1) != 20
3035 || XVECLEN (unspec, 0) != 2
3036 || XVECEXP (unspec, 0, 0) != src_reg
3037 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
3038 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
3039 return 0;
3041 return 1;
3044 /* Return 1 for an PARALLEL suitable for lmw. */
3047 lmw_operation (op, mode)
3048 rtx op;
3049 enum machine_mode mode ATTRIBUTE_UNUSED;
3051 int count = XVECLEN (op, 0);
3052 unsigned int dest_regno;
3053 rtx src_addr;
3054 unsigned int base_regno;
3055 HOST_WIDE_INT offset;
3056 int i;
3058 /* Perform a quick check so we don't blow up below. */
3059 if (count <= 1
3060 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3061 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
3062 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
3063 return 0;
3065 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
3066 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
3068 if (dest_regno > 31
3069 || count != 32 - (int) dest_regno)
3070 return 0;
3072 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr))
3074 offset = 0;
3075 base_regno = REGNO (src_addr);
3076 if (base_regno == 0)
3077 return 0;
3079 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr))
3081 offset = INTVAL (XEXP (src_addr, 1));
3082 base_regno = REGNO (XEXP (src_addr, 0));
3084 else
3085 return 0;
3087 for (i = 0; i < count; i++)
3089 rtx elt = XVECEXP (op, 0, i);
3090 rtx newaddr;
3091 rtx addr_reg;
3092 HOST_WIDE_INT newoffset;
3094 if (GET_CODE (elt) != SET
3095 || GET_CODE (SET_DEST (elt)) != REG
3096 || GET_MODE (SET_DEST (elt)) != SImode
3097 || REGNO (SET_DEST (elt)) != dest_regno + i
3098 || GET_CODE (SET_SRC (elt)) != MEM
3099 || GET_MODE (SET_SRC (elt)) != SImode)
3100 return 0;
3101 newaddr = XEXP (SET_SRC (elt), 0);
3102 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3104 newoffset = 0;
3105 addr_reg = newaddr;
3107 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3109 addr_reg = XEXP (newaddr, 0);
3110 newoffset = INTVAL (XEXP (newaddr, 1));
3112 else
3113 return 0;
3114 if (REGNO (addr_reg) != base_regno
3115 || newoffset != offset + 4 * i)
3116 return 0;
3119 return 1;
3122 /* Return 1 for an PARALLEL suitable for stmw. */
3125 stmw_operation (op, mode)
3126 rtx op;
3127 enum machine_mode mode ATTRIBUTE_UNUSED;
3129 int count = XVECLEN (op, 0);
3130 unsigned int src_regno;
3131 rtx dest_addr;
3132 unsigned int base_regno;
3133 HOST_WIDE_INT offset;
3134 int i;
3136 /* Perform a quick check so we don't blow up below. */
3137 if (count <= 1
3138 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3139 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3140 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3141 return 0;
3143 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3144 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3146 if (src_regno > 31
3147 || count != 32 - (int) src_regno)
3148 return 0;
3150 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr))
3152 offset = 0;
3153 base_regno = REGNO (dest_addr);
3154 if (base_regno == 0)
3155 return 0;
3157 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr))
3159 offset = INTVAL (XEXP (dest_addr, 1));
3160 base_regno = REGNO (XEXP (dest_addr, 0));
3162 else
3163 return 0;
3165 for (i = 0; i < count; i++)
3167 rtx elt = XVECEXP (op, 0, i);
3168 rtx newaddr;
3169 rtx addr_reg;
3170 HOST_WIDE_INT newoffset;
3172 if (GET_CODE (elt) != SET
3173 || GET_CODE (SET_SRC (elt)) != REG
3174 || GET_MODE (SET_SRC (elt)) != SImode
3175 || REGNO (SET_SRC (elt)) != src_regno + i
3176 || GET_CODE (SET_DEST (elt)) != MEM
3177 || GET_MODE (SET_DEST (elt)) != SImode)
3178 return 0;
3179 newaddr = XEXP (SET_DEST (elt), 0);
3180 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr))
3182 newoffset = 0;
3183 addr_reg = newaddr;
3185 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr))
3187 addr_reg = XEXP (newaddr, 0);
3188 newoffset = INTVAL (XEXP (newaddr, 1));
3190 else
3191 return 0;
3192 if (REGNO (addr_reg) != base_regno
3193 || newoffset != offset + 4 * i)
3194 return 0;
3197 return 1;
3201 /* A validation routine: say whether CODE, a condition code,
3202 and MODE match. The other alternatives either don't make
3203 sense or should never be generated. */
3204 static void
3205 validate_condition_mode (code, mode)
3206 enum rtx_code code;
3207 enum machine_mode mode;
3209 if (GET_RTX_CLASS (code) != '<'
3210 || GET_MODE_CLASS (mode) != MODE_CC)
3211 abort ();
3213 /* These don't make sense. */
3214 if ((code == GT || code == LT || code == GE || code == LE)
3215 && mode == CCUNSmode)
3216 abort ();
3218 if ((code == GTU || code == LTU || code == GEU || code == LEU)
3219 && mode != CCUNSmode)
3220 abort ();
3222 if (mode != CCFPmode
3223 && (code == ORDERED || code == UNORDERED
3224 || code == UNEQ || code == LTGT
3225 || code == UNGT || code == UNLT
3226 || code == UNGE || code == UNLE))
3227 abort();
3229 /* These should never be generated. */
3230 if (mode == CCFPmode
3231 && (code == LE || code == GE
3232 || code == UNEQ || code == LTGT
3233 || code == UNGT || code == UNLT))
3234 abort ();
3236 /* These are invalid; the information is not there. */
3237 if (mode == CCEQmode
3238 && code != EQ && code != NE)
3239 abort ();
3242 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
3243 We only check the opcode against the mode of the CC value here. */
3246 branch_comparison_operator (op, mode)
3247 register rtx op;
3248 enum machine_mode mode ATTRIBUTE_UNUSED;
3250 enum rtx_code code = GET_CODE (op);
3251 enum machine_mode cc_mode;
3253 if (GET_RTX_CLASS (code) != '<')
3254 return 0;
3256 cc_mode = GET_MODE (XEXP (op, 0));
3257 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3258 return 0;
3260 validate_condition_mode (code, cc_mode);
3262 return 1;
3265 /* Return 1 if OP is a comparison operation that is valid for a branch
3266 insn and which is true if the corresponding bit in the CC register
3267 is set. */
3270 branch_positive_comparison_operator (op, mode)
3271 register rtx op;
3272 enum machine_mode mode;
3274 enum rtx_code code;
3276 if (! branch_comparison_operator (op, mode))
3277 return 0;
3279 code = GET_CODE (op);
3280 return (code == EQ || code == LT || code == GT
3281 || code == LTU || code == GTU
3282 || code == UNORDERED);
3286 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
3287 We check the opcode against the mode of the CC value and disallow EQ or
3288 NE comparisons for integers. */
3291 scc_comparison_operator (op, mode)
3292 register rtx op;
3293 enum machine_mode mode;
3295 enum rtx_code code = GET_CODE (op);
3296 enum machine_mode cc_mode;
3298 if (GET_MODE (op) != mode && mode != VOIDmode)
3299 return 0;
3301 if (GET_RTX_CLASS (code) != '<')
3302 return 0;
3304 cc_mode = GET_MODE (XEXP (op, 0));
3305 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3306 return 0;
3308 validate_condition_mode (code, cc_mode);
3310 if (code == NE && cc_mode != CCFPmode)
3311 return 0;
3313 return 1;
3317 trap_comparison_operator (op, mode)
3318 rtx op;
3319 enum machine_mode mode;
3321 if (mode != VOIDmode && mode != GET_MODE (op))
3322 return 0;
3323 return GET_RTX_CLASS (GET_CODE (op)) == '<';
3327 boolean_operator (op, mode)
3328 rtx op;
3329 enum machine_mode mode ATTRIBUTE_UNUSED;
3331 enum rtx_code code = GET_CODE (op);
3332 return (code == AND || code == IOR || code == XOR);
3336 boolean_or_operator (op, mode)
3337 rtx op;
3338 enum machine_mode mode ATTRIBUTE_UNUSED;
3340 enum rtx_code code = GET_CODE (op);
3341 return (code == IOR || code == XOR);
3344 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
3345 mask required to convert the result of a rotate insn into a shift
3346 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
3349 includes_lshift_p (shiftop, andop)
3350 register rtx shiftop;
3351 register rtx andop;
3353 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3355 shift_mask <<= INTVAL (shiftop);
3357 return (INTVAL (andop) & ~shift_mask) == 0;
3360 /* Similar, but for right shift. */
3363 includes_rshift_p (shiftop, andop)
3364 register rtx shiftop;
3365 register rtx andop;
3367 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3369 shift_mask >>= INTVAL (shiftop);
3371 return (INTVAL (andop) & ~shift_mask) == 0;
3374 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
3375 mask required to convert the result of a rotate insn into a shift
3376 left insn of SHIFTOP bits. */
3379 includes_lshift64_p (shiftop, andop)
3380 register rtx shiftop;
3381 register rtx andop;
3383 #if HOST_BITS_PER_WIDE_INT == 64
3384 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3386 shift_mask <<= INTVAL (shiftop);
3388 return (INTVAL (andop) & ~shift_mask) == 0;
3389 #else
3390 unsigned HOST_WIDE_INT shift_mask_low = ~(unsigned HOST_WIDE_INT) 0;
3391 unsigned HOST_WIDE_INT shift_mask_high = ~(unsigned HOST_WIDE_INT) 0;
3393 shift_mask_low <<= INTVAL (shiftop);
3395 if (INTVAL (shiftop) > 32)
3396 shift_mask_high <<= (INTVAL (shiftop) - 32);
3398 if (GET_CODE (andop) == CONST_INT)
3399 return (INTVAL (andop) & ~shift_mask_low) == 0;
3400 else
3401 return ((CONST_DOUBLE_HIGH (andop) & ~shift_mask_high) == 0
3402 && (CONST_DOUBLE_LOW (andop) & ~shift_mask_low) == 0);
3403 #endif
3406 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
3407 for lfq and stfq insns.
3409 Note reg1 and reg2 *must* be hard registers. To be sure we will
3410 abort if we are passed pseudo registers. */
3413 registers_ok_for_quad_peep (reg1, reg2)
3414 rtx reg1, reg2;
3416 /* We might have been passed a SUBREG. */
3417 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
3418 return 0;
3420 return (REGNO (reg1) == REGNO (reg2) - 1);
3423 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
3424 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
3427 addrs_ok_for_quad_peep (addr1, addr2)
3428 register rtx addr1;
3429 register rtx addr2;
3431 unsigned int reg1;
3432 int offset1;
3434 /* Extract an offset (if used) from the first addr. */
3435 if (GET_CODE (addr1) == PLUS)
3437 /* If not a REG, return zero. */
3438 if (GET_CODE (XEXP (addr1, 0)) != REG)
3439 return 0;
3440 else
3442 reg1 = REGNO (XEXP (addr1, 0));
3443 /* The offset must be constant! */
3444 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
3445 return 0;
3446 offset1 = INTVAL (XEXP (addr1, 1));
3449 else if (GET_CODE (addr1) != REG)
3450 return 0;
3451 else
3453 reg1 = REGNO (addr1);
3454 /* This was a simple (mem (reg)) expression. Offset is 0. */
3455 offset1 = 0;
3458 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
3459 if (GET_CODE (addr2) != PLUS)
3460 return 0;
3462 if (GET_CODE (XEXP (addr2, 0)) != REG
3463 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
3464 return 0;
3466 if (reg1 != REGNO (XEXP (addr2, 0)))
3467 return 0;
3469 /* The offset for the second addr must be 8 more than the first addr. */
3470 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
3471 return 0;
3473 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
3474 instructions. */
3475 return 1;
3478 /* Return the register class of a scratch register needed to copy IN into
3479 or out of a register in CLASS in MODE. If it can be done directly,
3480 NO_REGS is returned. */
3482 enum reg_class
3483 secondary_reload_class (class, mode, in)
3484 enum reg_class class;
3485 enum machine_mode mode ATTRIBUTE_UNUSED;
3486 rtx in;
3488 int regno;
3490 #if TARGET_ELF
3491 /* We can not copy a symbolic operand directly into anything other than
3492 BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS
3493 is needed as an intermediate register. */
3494 if (class != BASE_REGS
3495 && (GET_CODE (in) == SYMBOL_REF
3496 || GET_CODE (in) == HIGH
3497 || GET_CODE (in) == LABEL_REF
3498 || GET_CODE (in) == CONST))
3499 return BASE_REGS;
3500 #endif
3502 if (GET_CODE (in) == REG)
3504 regno = REGNO (in);
3505 if (regno >= FIRST_PSEUDO_REGISTER)
3507 regno = true_regnum (in);
3508 if (regno >= FIRST_PSEUDO_REGISTER)
3509 regno = -1;
3512 else if (GET_CODE (in) == SUBREG)
3514 regno = true_regnum (in);
3515 if (regno >= FIRST_PSEUDO_REGISTER)
3516 regno = -1;
3518 else
3519 regno = -1;
3521 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
3522 into anything. */
3523 if (class == GENERAL_REGS || class == BASE_REGS
3524 || (regno >= 0 && INT_REGNO_P (regno)))
3525 return NO_REGS;
3527 /* Constants, memory, and FP registers can go into FP registers. */
3528 if ((regno == -1 || FP_REGNO_P (regno))
3529 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
3530 return NO_REGS;
3532 /* We can copy among the CR registers. */
3533 if ((class == CR_REGS || class == CR0_REGS)
3534 && regno >= 0 && CR_REGNO_P (regno))
3535 return NO_REGS;
3537 /* Otherwise, we need GENERAL_REGS. */
3538 return GENERAL_REGS;
3541 /* Given a comparison operation, return the bit number in CCR to test. We
3542 know this is a valid comparison.
3544 SCC_P is 1 if this is for an scc. That means that %D will have been
3545 used instead of %C, so the bits will be in different places.
3547 Return -1 if OP isn't a valid comparison for some reason. */
3550 ccr_bit (op, scc_p)
3551 register rtx op;
3552 int scc_p;
3554 enum rtx_code code = GET_CODE (op);
3555 enum machine_mode cc_mode;
3556 int cc_regnum;
3557 int base_bit;
3558 rtx reg;
3560 if (GET_RTX_CLASS (code) != '<')
3561 return -1;
3563 reg = XEXP (op, 0);
3565 if (GET_CODE (reg) != REG
3566 || ! CR_REGNO_P (REGNO (reg)))
3567 abort ();
3569 cc_mode = GET_MODE (reg);
3570 cc_regnum = REGNO (reg);
3571 base_bit = 4 * (cc_regnum - CR0_REGNO);
3573 validate_condition_mode (code, cc_mode);
3575 switch (code)
3577 case NE:
3578 return scc_p ? base_bit + 3 : base_bit + 2;
3579 case EQ:
3580 return base_bit + 2;
3581 case GT: case GTU: case UNLE:
3582 return base_bit + 1;
3583 case LT: case LTU: case UNGE:
3584 return base_bit;
3585 case ORDERED: case UNORDERED:
3586 return base_bit + 3;
3588 case GE: case GEU:
3589 /* If scc, we will have done a cror to put the bit in the
3590 unordered position. So test that bit. For integer, this is ! LT
3591 unless this is an scc insn. */
3592 return scc_p ? base_bit + 3 : base_bit;
3594 case LE: case LEU:
3595 return scc_p ? base_bit + 3 : base_bit + 1;
3597 default:
3598 abort ();
3602 /* Return the GOT register. */
3604 struct rtx_def *
3605 rs6000_got_register (value)
3606 rtx value ATTRIBUTE_UNUSED;
3608 /* The second flow pass currently (June 1999) can't update regs_ever_live
3609 without disturbing other parts of the compiler, so update it here to
3610 make the prolog/epilogue code happy. */
3611 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
3612 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
3614 current_function_uses_pic_offset_table = 1;
3616 return pic_offset_table_rtx;
3619 /* Functions to init, mark and free struct machine_function.
3620 These will be called, via pointer variables,
3621 from push_function_context and pop_function_context. */
3623 static void
3624 rs6000_init_machine_status (p)
3625 struct function *p;
3627 p->machine = (machine_function *) xcalloc (1, sizeof (machine_function));
3630 static void
3631 rs6000_mark_machine_status (p)
3632 struct function *p;
3634 if (p->machine)
3635 ggc_mark_rtx (p->machine->ra_rtx);
3638 static void
3639 rs6000_free_machine_status (p)
3640 struct function *p;
3642 if (p->machine == NULL)
3643 return;
3645 free (p->machine);
3646 p->machine = NULL;
3650 /* Print an operand. Recognize special options, documented below. */
3652 #if TARGET_ELF
3653 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
3654 #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
3655 #else
3656 #define SMALL_DATA_RELOC "sda21"
3657 #define SMALL_DATA_REG 0
3658 #endif
3660 void
3661 print_operand (file, x, code)
3662 FILE *file;
3663 rtx x;
3664 int code;
3666 int i;
3667 HOST_WIDE_INT val;
3669 /* These macros test for integers and extract the low-order bits. */
3670 #define INT_P(X) \
3671 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
3672 && GET_MODE (X) == VOIDmode)
3674 #define INT_LOWPART(X) \
3675 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
3677 switch (code)
3679 case '.':
3680 /* Write out an instruction after the call which may be replaced
3681 with glue code by the loader. This depends on the AIX version. */
3682 asm_fprintf (file, RS6000_CALL_GLUE);
3683 return;
3685 case '$':
3686 /* Write out either a '.' or '$' for the current location, depending
3687 on whether this is Solaris or not. */
3688 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
3689 return;
3691 /* %a is output_address. */
3693 case 'A':
3694 /* If X is a constant integer whose low-order 5 bits are zero,
3695 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
3696 in the AIX assembler where "sri" with a zero shift count
3697 write a trash instruction. */
3698 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
3699 putc ('l', file);
3700 else
3701 putc ('r', file);
3702 return;
3704 case 'b':
3705 /* If constant, low-order 16 bits of constant, unsigned.
3706 Otherwise, write normally. */
3707 if (INT_P (x))
3708 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
3709 else
3710 print_operand (file, x, 0);
3711 return;
3713 case 'B':
3714 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
3715 for 64-bit mask direction. */
3716 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
3717 return;
3719 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
3720 output_operand. */
3722 case 'D':
3723 /* There used to be a comment for 'C' reading "This is an
3724 optional cror needed for certain floating-point
3725 comparisons. Otherwise write nothing." */
3727 /* Similar, except that this is for an scc, so we must be able to
3728 encode the test in a single bit that is one. We do the above
3729 for any LE, GE, GEU, or LEU and invert the bit for NE. */
3730 if (GET_CODE (x) == LE || GET_CODE (x) == GE
3731 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
3733 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3735 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
3736 base_bit + 2,
3737 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
3740 else if (GET_CODE (x) == NE)
3742 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3744 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
3745 base_bit + 2, base_bit + 2);
3747 return;
3749 case 'E':
3750 /* X is a CR register. Print the number of the EQ bit of the CR */
3751 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3752 output_operand_lossage ("invalid %%E value");
3753 else
3754 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
3755 return;
3757 case 'f':
3758 /* X is a CR register. Print the shift count needed to move it
3759 to the high-order four bits. */
3760 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3761 output_operand_lossage ("invalid %%f value");
3762 else
3763 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
3764 return;
3766 case 'F':
3767 /* Similar, but print the count for the rotate in the opposite
3768 direction. */
3769 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3770 output_operand_lossage ("invalid %%F value");
3771 else
3772 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
3773 return;
3775 case 'G':
3776 /* X is a constant integer. If it is negative, print "m",
3777 otherwise print "z". This is to make a aze or ame insn. */
3778 if (GET_CODE (x) != CONST_INT)
3779 output_operand_lossage ("invalid %%G value");
3780 else if (INTVAL (x) >= 0)
3781 putc ('z', file);
3782 else
3783 putc ('m', file);
3784 return;
3786 case 'h':
3787 /* If constant, output low-order five bits. Otherwise,
3788 write normally. */
3789 if (INT_P (x))
3790 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
3791 else
3792 print_operand (file, x, 0);
3793 return;
3795 case 'H':
3796 /* If constant, output low-order six bits. Otherwise,
3797 write normally. */
3798 if (INT_P (x))
3799 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
3800 else
3801 print_operand (file, x, 0);
3802 return;
3804 case 'I':
3805 /* Print `i' if this is a constant, else nothing. */
3806 if (INT_P (x))
3807 putc ('i', file);
3808 return;
3810 case 'j':
3811 /* Write the bit number in CCR for jump. */
3812 i = ccr_bit (x, 0);
3813 if (i == -1)
3814 output_operand_lossage ("invalid %%j code");
3815 else
3816 fprintf (file, "%d", i);
3817 return;
3819 case 'J':
3820 /* Similar, but add one for shift count in rlinm for scc and pass
3821 scc flag to `ccr_bit'. */
3822 i = ccr_bit (x, 1);
3823 if (i == -1)
3824 output_operand_lossage ("invalid %%J code");
3825 else
3826 /* If we want bit 31, write a shift count of zero, not 32. */
3827 fprintf (file, "%d", i == 31 ? 0 : i + 1);
3828 return;
3830 case 'k':
3831 /* X must be a constant. Write the 1's complement of the
3832 constant. */
3833 if (! INT_P (x))
3834 output_operand_lossage ("invalid %%k value");
3835 else
3836 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
3837 return;
3839 case 'K':
3840 /* X must be a symbolic constant on ELF. Write an
3841 expression suitable for an 'addi' that adds in the low 16
3842 bits of the MEM. */
3843 if (GET_CODE (x) != CONST)
3845 print_operand_address (file, x);
3846 fputs ("@l", file);
3848 else
3850 if (GET_CODE (XEXP (x, 0)) != PLUS
3851 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
3852 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3853 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
3854 output_operand_lossage ("invalid %%K value");
3855 print_operand_address (file, XEXP (XEXP (x, 0), 0));
3856 fputs ("@l", file);
3857 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
3859 return;
3861 /* %l is output_asm_label. */
3863 case 'L':
3864 /* Write second word of DImode or DFmode reference. Works on register
3865 or non-indexed memory only. */
3866 if (GET_CODE (x) == REG)
3867 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
3868 else if (GET_CODE (x) == MEM)
3870 /* Handle possible auto-increment. Since it is pre-increment and
3871 we have already done it, we can just use an offset of word. */
3872 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3873 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3874 output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0),
3875 UNITS_PER_WORD));
3876 else
3877 output_address (plus_constant_for_output (XEXP (x, 0),
3878 UNITS_PER_WORD));
3879 if (small_data_operand (x, GET_MODE (x)))
3880 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3881 reg_names[SMALL_DATA_REG]);
3883 return;
3885 case 'm':
3886 /* MB value for a mask operand. */
3887 if (! mask_operand (x, VOIDmode))
3888 output_operand_lossage ("invalid %%m value");
3890 val = INT_LOWPART (x);
3892 /* If the high bit is set and the low bit is not, the value is zero.
3893 If the high bit is zero, the value is the first 1 bit we find from
3894 the left. */
3895 if ((val & 0x80000000) && ((val & 1) == 0))
3897 putc ('0', file);
3898 return;
3900 else if ((val & 0x80000000) == 0)
3902 for (i = 1; i < 32; i++)
3903 if ((val <<= 1) & 0x80000000)
3904 break;
3905 fprintf (file, "%d", i);
3906 return;
3909 /* Otherwise, look for the first 0 bit from the right. The result is its
3910 number plus 1. We know the low-order bit is one. */
3911 for (i = 0; i < 32; i++)
3912 if (((val >>= 1) & 1) == 0)
3913 break;
3915 /* If we ended in ...01, i would be 0. The correct value is 31, so
3916 we want 31 - i. */
3917 fprintf (file, "%d", 31 - i);
3918 return;
3920 case 'M':
3921 /* ME value for a mask operand. */
3922 if (! mask_operand (x, VOIDmode))
3923 output_operand_lossage ("invalid %%M value");
3925 val = INT_LOWPART (x);
3927 /* If the low bit is set and the high bit is not, the value is 31.
3928 If the low bit is zero, the value is the first 1 bit we find from
3929 the right. */
3930 if ((val & 1) && ((val & 0x80000000) == 0))
3932 fputs ("31", file);
3933 return;
3935 else if ((val & 1) == 0)
3937 for (i = 0; i < 32; i++)
3938 if ((val >>= 1) & 1)
3939 break;
3941 /* If we had ....10, i would be 0. The result should be
3942 30, so we need 30 - i. */
3943 fprintf (file, "%d", 30 - i);
3944 return;
3947 /* Otherwise, look for the first 0 bit from the left. The result is its
3948 number minus 1. We know the high-order bit is one. */
3949 for (i = 0; i < 32; i++)
3950 if (((val <<= 1) & 0x80000000) == 0)
3951 break;
3953 fprintf (file, "%d", i);
3954 return;
3956 /* %n outputs the negative of its operand. */
3958 case 'N':
3959 /* Write the number of elements in the vector times 4. */
3960 if (GET_CODE (x) != PARALLEL)
3961 output_operand_lossage ("invalid %%N value");
3962 else
3963 fprintf (file, "%d", XVECLEN (x, 0) * 4);
3964 return;
3966 case 'O':
3967 /* Similar, but subtract 1 first. */
3968 if (GET_CODE (x) != PARALLEL)
3969 output_operand_lossage ("invalid %%O value");
3970 else
3971 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
3972 return;
3974 case 'p':
3975 /* X is a CONST_INT that is a power of two. Output the logarithm. */
3976 if (! INT_P (x)
3977 || (i = exact_log2 (INT_LOWPART (x))) < 0)
3978 output_operand_lossage ("invalid %%p value");
3979 else
3980 fprintf (file, "%d", i);
3981 return;
3983 case 'P':
3984 /* The operand must be an indirect memory reference. The result
3985 is the register number. */
3986 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
3987 || REGNO (XEXP (x, 0)) >= 32)
3988 output_operand_lossage ("invalid %%P value");
3989 else
3990 fprintf (file, "%d", REGNO (XEXP (x, 0)));
3991 return;
3993 case 'q':
3994 /* This outputs the logical code corresponding to a boolean
3995 expression. The expression may have one or both operands
3996 negated (if one, only the first one). For condition register
3997 logical operations, it will also treat the negated
3998 CR codes as NOTs, but not handle NOTs of them. */
4000 const char *const *t = 0;
4001 const char *s;
4002 enum rtx_code code = GET_CODE (x);
4003 static const char * const tbl[3][3] = {
4004 { "and", "andc", "nor" },
4005 { "or", "orc", "nand" },
4006 { "xor", "eqv", "xor" } };
4008 if (code == AND)
4009 t = tbl[0];
4010 else if (code == IOR)
4011 t = tbl[1];
4012 else if (code == XOR)
4013 t = tbl[2];
4014 else
4015 output_operand_lossage ("invalid %%q value");
4017 if (GET_CODE (XEXP (x, 0)) != NOT)
4018 s = t[0];
4019 else
4021 if (GET_CODE (XEXP (x, 1)) == NOT)
4022 s = t[2];
4023 else
4024 s = t[1];
4027 fputs (s, file);
4029 return;
4031 case 'R':
4032 /* X is a CR register. Print the mask for `mtcrf'. */
4033 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
4034 output_operand_lossage ("invalid %%R value");
4035 else
4036 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
4037 return;
4039 case 's':
4040 /* Low 5 bits of 32 - value */
4041 if (! INT_P (x))
4042 output_operand_lossage ("invalid %%s value");
4043 else
4044 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
4045 return;
4047 case 'S':
4048 /* PowerPC64 mask position. All 0's and all 1's are excluded.
4049 CONST_INT 32-bit mask is considered sign-extended so any
4050 transition must occur within the CONST_INT, not on the boundary. */
4051 if (! mask64_operand (x, VOIDmode))
4052 output_operand_lossage ("invalid %%S value");
4054 val = INT_LOWPART (x);
4056 if (val & 1) /* Clear Left */
4058 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4059 if (!((val >>= 1) & 1))
4060 break;
4062 #if HOST_BITS_PER_WIDE_INT == 32
4063 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4065 val = CONST_DOUBLE_HIGH (x);
4067 if (val == 0)
4068 --i;
4069 else
4070 for (i = 32; i < 64; i++)
4071 if (!((val >>= 1) & 1))
4072 break;
4074 #endif
4075 /* i = index of last set bit from right
4076 mask begins at 63 - i from left */
4077 if (i > 63)
4078 output_operand_lossage ("%%S computed all 1's mask");
4080 fprintf (file, "%d", 63 - i);
4081 return;
4083 else /* Clear Right */
4085 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4086 if ((val >>= 1) & 1)
4087 break;
4089 #if HOST_BITS_PER_WIDE_INT == 32
4090 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4092 val = CONST_DOUBLE_HIGH (x);
4094 if (val == (HOST_WIDE_INT) -1)
4095 --i;
4096 else
4097 for (i = 32; i < 64; i++)
4098 if ((val >>= 1) & 1)
4099 break;
4101 #endif
4102 /* i = index of last clear bit from right
4103 mask ends at 62 - i from left */
4104 if (i > 62)
4105 output_operand_lossage ("%%S computed all 0's mask");
4107 fprintf (file, "%d", 62 - i);
4108 return;
4111 case 'T':
4112 /* Print the symbolic name of a branch target register. */
4113 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
4114 && REGNO (x) != COUNT_REGISTER_REGNUM))
4115 output_operand_lossage ("invalid %%T value");
4116 else if (REGNO (x) == LINK_REGISTER_REGNUM)
4117 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
4118 else
4119 fputs ("ctr", file);
4120 return;
4122 case 'u':
4123 /* High-order 16 bits of constant for use in unsigned operand. */
4124 if (! INT_P (x))
4125 output_operand_lossage ("invalid %%u value");
4126 else
4127 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
4128 (INT_LOWPART (x) >> 16) & 0xffff);
4129 return;
4131 case 'v':
4132 /* High-order 16 bits of constant for use in signed operand. */
4133 if (! INT_P (x))
4134 output_operand_lossage ("invalid %%v value");
4135 else
4137 int value = (INT_LOWPART (x) >> 16) & 0xffff;
4139 /* Solaris assembler doesn't like lis 0,0x8000 */
4140 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
4141 fprintf (file, "%d", value | (~0 << 16));
4142 else
4143 fprintf (file, "0x%x", value);
4144 return;
4147 case 'U':
4148 /* Print `u' if this has an auto-increment or auto-decrement. */
4149 if (GET_CODE (x) == MEM
4150 && (GET_CODE (XEXP (x, 0)) == PRE_INC
4151 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
4152 putc ('u', file);
4153 return;
4155 case 'V':
4156 /* Print the trap code for this operand. */
4157 switch (GET_CODE (x))
4159 case EQ:
4160 fputs ("eq", file); /* 4 */
4161 break;
4162 case NE:
4163 fputs ("ne", file); /* 24 */
4164 break;
4165 case LT:
4166 fputs ("lt", file); /* 16 */
4167 break;
4168 case LE:
4169 fputs ("le", file); /* 20 */
4170 break;
4171 case GT:
4172 fputs ("gt", file); /* 8 */
4173 break;
4174 case GE:
4175 fputs ("ge", file); /* 12 */
4176 break;
4177 case LTU:
4178 fputs ("llt", file); /* 2 */
4179 break;
4180 case LEU:
4181 fputs ("lle", file); /* 6 */
4182 break;
4183 case GTU:
4184 fputs ("lgt", file); /* 1 */
4185 break;
4186 case GEU:
4187 fputs ("lge", file); /* 5 */
4188 break;
4189 default:
4190 abort ();
4192 break;
4194 case 'w':
4195 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
4196 normally. */
4197 if (INT_P (x))
4198 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
4199 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
4200 else
4201 print_operand (file, x, 0);
4202 return;
4204 case 'W':
4205 /* MB value for a PowerPC64 rldic operand. */
4206 if (! rldic_operand (x, VOIDmode))
4207 output_operand_lossage ("invalid %%W value");
4209 val = (GET_CODE (x) == CONST_INT
4210 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
4212 if (val < 0)
4213 i = -1;
4214 else
4215 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4216 if ((val <<= 1) < 0)
4217 break;
4219 #if HOST_BITS_PER_WIDE_INT == 32
4220 if (GET_CODE (x) == CONST_INT && i >= 0)
4221 i += 32; /* zero-extend high-part was all 0's */
4222 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4224 val = CONST_DOUBLE_LOW (x);
4226 if (val == 0)
4227 abort();
4228 else if (val < 0)
4229 --i;
4230 else
4231 for ( ; i < 64; i++)
4232 if ((val <<= 1) < 0)
4233 break;
4235 #endif
4237 fprintf (file, "%d", i + 1);
4238 return;
4240 case 'X':
4241 if (GET_CODE (x) == MEM
4242 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
4243 putc ('x', file);
4244 return;
4246 case 'Y':
4247 /* Like 'L', for third word of TImode */
4248 if (GET_CODE (x) == REG)
4249 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
4250 else if (GET_CODE (x) == MEM)
4252 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4253 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4254 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
4255 else
4256 output_address (plus_constant (XEXP (x, 0), 8));
4257 if (small_data_operand (x, GET_MODE (x)))
4258 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4259 reg_names[SMALL_DATA_REG]);
4261 return;
4263 case 'z':
4264 /* X is a SYMBOL_REF. Write out the name preceded by a
4265 period and without any trailing data in brackets. Used for function
4266 names. If we are configured for System V (or the embedded ABI) on
4267 the PowerPC, do not emit the period, since those systems do not use
4268 TOCs and the like. */
4269 if (GET_CODE (x) != SYMBOL_REF)
4270 abort ();
4272 if (XSTR (x, 0)[0] != '.')
4274 switch (DEFAULT_ABI)
4276 default:
4277 abort ();
4279 case ABI_AIX:
4280 putc ('.', file);
4281 break;
4283 case ABI_V4:
4284 case ABI_AIX_NODESC:
4285 case ABI_SOLARIS:
4286 break;
4289 #if TARGET_AIX
4290 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
4291 #else
4292 assemble_name (file, XSTR (x, 0));
4293 #endif
4294 return;
4296 case 'Z':
4297 /* Like 'L', for last word of TImode. */
4298 if (GET_CODE (x) == REG)
4299 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
4300 else if (GET_CODE (x) == MEM)
4302 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4303 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4304 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
4305 else
4306 output_address (plus_constant (XEXP (x, 0), 12));
4307 if (small_data_operand (x, GET_MODE (x)))
4308 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4309 reg_names[SMALL_DATA_REG]);
4311 return;
4313 case 0:
4314 if (GET_CODE (x) == REG)
4315 fprintf (file, "%s", reg_names[REGNO (x)]);
4316 else if (GET_CODE (x) == MEM)
4318 /* We need to handle PRE_INC and PRE_DEC here, since we need to
4319 know the width from the mode. */
4320 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
4321 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
4322 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4323 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
4324 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
4325 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4326 else
4327 output_address (XEXP (x, 0));
4329 else
4330 output_addr_const (file, x);
4331 return;
4333 default:
4334 output_operand_lossage ("invalid %%xn code");
4338 /* Print the address of an operand. */
4340 void
4341 print_operand_address (file, x)
4342 FILE *file;
4343 register rtx x;
4345 if (GET_CODE (x) == REG)
4346 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
4347 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
4348 || GET_CODE (x) == LABEL_REF)
4350 output_addr_const (file, x);
4351 if (small_data_operand (x, GET_MODE (x)))
4352 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4353 reg_names[SMALL_DATA_REG]);
4354 else if (TARGET_TOC)
4355 abort();
4357 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
4359 if (REGNO (XEXP (x, 0)) == 0)
4360 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
4361 reg_names[ REGNO (XEXP (x, 0)) ]);
4362 else
4363 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
4364 reg_names[ REGNO (XEXP (x, 1)) ]);
4366 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4368 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
4369 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4371 #if TARGET_ELF
4372 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
4373 && CONSTANT_P (XEXP (x, 1)))
4375 output_addr_const (file, XEXP (x, 1));
4376 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4378 #endif
4379 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
4381 if (TARGET_AIX)
4383 rtx contains_minus = XEXP (x, 1);
4384 rtx minus;
4386 /* Find the (minus (sym) (toc)) buried in X, and temporarily
4387 turn it into (sym) for output_addr_const. */
4388 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
4389 contains_minus = XEXP (contains_minus, 0);
4391 minus = XEXP (contains_minus, 0);
4392 XEXP (contains_minus, 0) = XEXP (minus, 0);
4393 output_addr_const (file, XEXP (x, 1));
4394 XEXP (contains_minus, 0) = minus;
4396 else
4397 output_addr_const (file, XEXP (x, 1));
4399 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
4401 else
4402 abort ();
4405 enum rtx_code
4406 rs6000_reverse_condition (mode, code)
4407 enum machine_mode mode;
4408 enum rtx_code code;
4410 /* Reversal of FP compares takes care -- an ordered compare
4411 becomes an unordered compare and vice versa. */
4412 if (mode == CCFPmode)
4413 return reverse_condition_maybe_unordered (code);
4414 else
4415 return reverse_condition (code);
4419 /* Generate a compare for CODE. Return a brand-new rtx that
4420 represents the result of the compare. */
4421 static rtx
4422 rs6000_generate_compare (code)
4423 enum rtx_code code;
4425 enum machine_mode comp_mode;
4426 rtx compare_result;
4428 if (rs6000_compare_fp_p)
4429 comp_mode = CCFPmode;
4430 else if (code == GTU || code == LTU
4431 || code == GEU || code == LEU)
4432 comp_mode = CCUNSmode;
4433 else
4434 comp_mode = CCmode;
4436 /* First, the compare. */
4437 compare_result = gen_reg_rtx (comp_mode);
4438 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
4439 gen_rtx_COMPARE (comp_mode,
4440 rs6000_compare_op0,
4441 rs6000_compare_op1)));
4443 /* Some kinds of FP comparisons need an OR operation. */
4444 if (rs6000_compare_fp_p
4445 && (code == LE || code == GE
4446 || code == UNEQ || code == LTGT
4447 || code == UNGT || code == UNLT))
4449 enum rtx_code or1, or2;
4450 rtx or1_rtx, or2_rtx, compare2_rtx;
4451 rtx or_result = gen_reg_rtx (CCEQmode);
4453 switch (code)
4455 case LE: or1 = LT; or2 = EQ; break;
4456 case GE: or1 = GT; or2 = EQ; break;
4457 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
4458 case LTGT: or1 = LT; or2 = GT; break;
4459 case UNGT: or1 = UNORDERED; or2 = GT; break;
4460 case UNLT: or1 = UNORDERED; or2 = LT; break;
4461 default: abort ();
4463 validate_condition_mode (or1, comp_mode);
4464 validate_condition_mode (or2, comp_mode);
4465 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
4466 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
4467 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
4468 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
4469 const_true_rtx);
4470 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
4472 compare_result = or_result;
4473 code = EQ;
4476 validate_condition_mode (code, GET_MODE (compare_result));
4478 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
4482 /* Emit the RTL for an sCOND pattern. */
4484 void
4485 rs6000_emit_sCOND (code, result)
4486 enum rtx_code code;
4487 rtx result;
4489 rtx condition_rtx;
4490 enum machine_mode op_mode;
4492 condition_rtx = rs6000_generate_compare (code);
4494 op_mode = GET_MODE (rs6000_compare_op0);
4495 if (op_mode == VOIDmode)
4496 op_mode = GET_MODE (rs6000_compare_op1);
4498 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
4500 PUT_MODE (condition_rtx, DImode);
4501 convert_move (result, condition_rtx, 0);
4503 else
4505 PUT_MODE (condition_rtx, SImode);
4506 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
4511 /* Emit a branch of kind CODE to location LOC. */
4513 void
4514 rs6000_emit_cbranch (code, loc)
4515 enum rtx_code code;
4516 rtx loc;
4518 rtx condition_rtx, loc_ref;
4520 condition_rtx = rs6000_generate_compare (code);
4521 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
4522 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4523 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
4524 loc_ref, pc_rtx)));
4528 /* Return the string to output a conditional branch to LABEL, which is
4529 the operand number of the label, or -1 if the branch is really a
4530 conditional return.
4532 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
4533 condition code register and its mode specifies what kind of
4534 comparison we made.
4536 REVERSED is non-zero if we should reverse the sense of the comparison.
4538 INSN is the insn. */
4540 char *
4541 output_cbranch (op, label, reversed, insn)
4542 rtx op;
4543 const char * label;
4544 int reversed;
4545 rtx insn;
4547 static char string[64];
4548 enum rtx_code code = GET_CODE (op);
4549 rtx cc_reg = XEXP (op, 0);
4550 enum machine_mode mode = GET_MODE (cc_reg);
4551 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
4552 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
4553 int really_reversed = reversed ^ need_longbranch;
4554 char *s = string;
4555 const char *ccode;
4556 const char *pred;
4557 rtx note;
4559 validate_condition_mode (code, mode);
4561 /* Work out which way this really branches. We could use
4562 reverse_condition_maybe_unordered here always but this
4563 makes the resulting assembler clearer. */
4564 if (really_reversed)
4565 code = rs6000_reverse_condition (mode, code);
4567 switch (code)
4569 /* Not all of these are actually distinct opcodes, but
4570 we distinguish them for clarity of the resulting assembler. */
4571 case NE: ccode = "ne"; break;
4572 case EQ: ccode = "eq"; break;
4573 case GE: case GEU: ccode = "ge"; break;
4574 case GT: case GTU: ccode = "gt"; break;
4575 case LE: case LEU: ccode = "le"; break;
4576 case LT: case LTU: ccode = "lt"; break;
4577 case UNORDERED: ccode = "un"; break;
4578 case ORDERED: ccode = "nu"; break;
4579 case UNGE: ccode = "nl"; break;
4580 case UNLE: ccode = "ng"; break;
4581 default:
4582 abort();
4585 /* Maybe we have a guess as to how likely the branch is.
4586 The old mnemonics don't have a way to specify this information. */
4587 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
4588 if (note != NULL_RTX)
4590 /* PROB is the difference from 50%. */
4591 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
4593 /* For branches that are very close to 50%, assume not-taken. */
4594 if (abs (prob) > REG_BR_PROB_BASE / 20
4595 && ((prob > 0) ^ need_longbranch))
4596 pred = "+";
4597 else
4598 pred = "-";
4600 else
4601 pred = "";
4603 if (label == NULL)
4604 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
4605 else
4606 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
4608 /* We need to escape any '%' characters in the reg_names string.
4609 Assume they'd only be the first character... */
4610 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
4611 *s++ = '%';
4612 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
4614 if (label != NULL)
4616 /* If the branch distance was too far, we may have to use an
4617 unconditional branch to go the distance. */
4618 if (need_longbranch)
4619 s += sprintf (s, ",%c$+8 ; b %s", '%', label);
4620 else
4621 s += sprintf (s, ",%s", label);
4624 return string;
4627 /* This page contains routines that are used to determine what the function
4628 prologue and epilogue code will do and write them out. */
4630 /* Return the first fixed-point register that is required to be saved. 32 if
4631 none. */
4634 first_reg_to_save ()
4636 int first_reg;
4638 /* Find lowest numbered live register. */
4639 for (first_reg = 13; first_reg <= 31; first_reg++)
4640 if (regs_ever_live[first_reg]
4641 && (! call_used_regs[first_reg]
4642 || (first_reg == PIC_OFFSET_TABLE_REGNUM
4643 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4644 && flag_pic == 1)))
4645 break;
4647 if (profile_flag)
4649 /* AIX must save/restore every register that contains a parameter
4650 before/after the .__mcount call plus an additional register
4651 for the static chain, if needed; use registers from 30 down to 22
4652 to do this. */
4653 if (DEFAULT_ABI == ABI_AIX)
4655 int last_parm_reg, profile_first_reg;
4657 /* Figure out last used parameter register. The proper thing
4658 to do is to walk incoming args of the function. A function
4659 might have live parameter registers even if it has no
4660 incoming args. */
4661 for (last_parm_reg = 10;
4662 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4663 last_parm_reg--)
4666 /* Calculate first reg for saving parameter registers
4667 and static chain.
4668 Skip reg 31 which may contain the frame pointer. */
4669 profile_first_reg = (33 - last_parm_reg
4670 - (current_function_needs_context ? 1 : 0));
4671 /* Do not save frame pointer if no parameters needs to be saved. */
4672 if (profile_first_reg == 31)
4673 profile_first_reg = 32;
4675 if (first_reg > profile_first_reg)
4676 first_reg = profile_first_reg;
4679 /* SVR4 may need one register to preserve the static chain. */
4680 else if (current_function_needs_context)
4682 /* Skip reg 31 which may contain the frame pointer. */
4683 if (first_reg > 30)
4684 first_reg = 30;
4688 return first_reg;
4691 /* Similar, for FP regs. */
4694 first_fp_reg_to_save ()
4696 int first_reg;
4698 /* Find lowest numbered live register. */
4699 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
4700 if (regs_ever_live[first_reg])
4701 break;
4703 return first_reg;
4706 /* Calculate the stack information for the current function. This is
4707 complicated by having two separate calling sequences, the AIX calling
4708 sequence and the V.4 calling sequence.
4710 AIX stack frames look like:
4711 32-bit 64-bit
4712 SP----> +---------------------------------------+
4713 | back chain to caller | 0 0
4714 +---------------------------------------+
4715 | saved CR | 4 8 (8-11)
4716 +---------------------------------------+
4717 | saved LR | 8 16
4718 +---------------------------------------+
4719 | reserved for compilers | 12 24
4720 +---------------------------------------+
4721 | reserved for binders | 16 32
4722 +---------------------------------------+
4723 | saved TOC pointer | 20 40
4724 +---------------------------------------+
4725 | Parameter save area (P) | 24 48
4726 +---------------------------------------+
4727 | Alloca space (A) | 24+P etc.
4728 +---------------------------------------+
4729 | Local variable space (L) | 24+P+A
4730 +---------------------------------------+
4731 | Float/int conversion temporary (X) | 24+P+A+L
4732 +---------------------------------------+
4733 | Save area for GP registers (G) | 24+P+A+X+L
4734 +---------------------------------------+
4735 | Save area for FP registers (F) | 24+P+A+X+L+G
4736 +---------------------------------------+
4737 old SP->| back chain to caller's caller |
4738 +---------------------------------------+
4740 The required alignment for AIX configurations is two words (i.e., 8
4741 or 16 bytes).
4744 V.4 stack frames look like:
4746 SP----> +---------------------------------------+
4747 | back chain to caller | 0
4748 +---------------------------------------+
4749 | caller's saved LR | 4
4750 +---------------------------------------+
4751 | Parameter save area (P) | 8
4752 +---------------------------------------+
4753 | Alloca space (A) | 8+P
4754 +---------------------------------------+
4755 | Varargs save area (V) | 8+P+A
4756 +---------------------------------------+
4757 | Local variable space (L) | 8+P+A+V
4758 +---------------------------------------+
4759 | Float/int conversion temporary (X) | 8+P+A+V+L
4760 +---------------------------------------+
4761 | saved CR (C) | 8+P+A+V+L+X
4762 +---------------------------------------+
4763 | Save area for GP registers (G) | 8+P+A+V+L+X+C
4764 +---------------------------------------+
4765 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
4766 +---------------------------------------+
4767 old SP->| back chain to caller's caller |
4768 +---------------------------------------+
4770 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
4771 given. (But note below and in sysv4.h that we require only 8 and
4772 may round up the size of our stack frame anyways. The historical
4773 reason is early versions of powerpc-linux which didn't properly
4774 align the stack at program startup. A happy side-effect is that
4775 -mno-eabi libraries can be used with -meabi programs.)
4778 The EABI configuration defaults to the V.4 layout, unless
4779 -mcall-aix is used, in which case the AIX layout is used. However,
4780 the stack alignment requirements may differ. If -mno-eabi is not
4781 given, the required stack alignment is 8 bytes; if -mno-eabi is
4782 given, the required alignment is 16 bytes. (But see V.4 comment
4783 above.) */
4785 #ifndef ABI_STACK_BOUNDARY
4786 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
4787 #endif
4789 rs6000_stack_t *
4790 rs6000_stack_info ()
4792 static rs6000_stack_t info, zero_info;
4793 rs6000_stack_t *info_ptr = &info;
4794 int reg_size = TARGET_POWERPC64 ? 8 : 4;
4795 enum rs6000_abi abi;
4796 int total_raw_size;
4798 /* Zero all fields portably */
4799 info = zero_info;
4801 /* Select which calling sequence */
4802 info_ptr->abi = abi = DEFAULT_ABI;
4804 /* Calculate which registers need to be saved & save area size */
4805 info_ptr->first_gp_reg_save = first_reg_to_save ();
4806 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
4807 even if it currently looks like we won't. */
4808 if (flag_pic == 1
4809 && (abi == ABI_V4 || abi == ABI_SOLARIS)
4810 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
4811 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
4812 else
4813 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4815 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
4816 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
4818 /* Does this function call anything? */
4819 info_ptr->calls_p = (! current_function_is_leaf
4820 || cfun->machine->ra_needs_full_frame);
4822 /* Determine if we need to save the link register */
4823 if (rs6000_ra_ever_killed ()
4824 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4825 #ifdef TARGET_RELOCATABLE
4826 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
4827 #endif
4828 || (info_ptr->first_fp_reg_save != 64
4829 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
4830 || (abi == ABI_V4 && current_function_calls_alloca)
4831 || (abi == ABI_SOLARIS && current_function_calls_alloca)
4832 || info_ptr->calls_p)
4834 info_ptr->lr_save_p = 1;
4835 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4838 /* Determine if we need to save the condition code registers. */
4839 if (regs_ever_live[CR2_REGNO]
4840 || regs_ever_live[CR3_REGNO]
4841 || regs_ever_live[CR4_REGNO])
4843 info_ptr->cr_save_p = 1;
4844 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4845 info_ptr->cr_size = reg_size;
4848 /* Determine various sizes */
4849 info_ptr->reg_size = reg_size;
4850 info_ptr->fixed_size = RS6000_SAVE_AREA;
4851 info_ptr->varargs_size = RS6000_VARARGS_AREA;
4852 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
4853 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
4854 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
4855 + info_ptr->gp_size
4856 + info_ptr->cr_size
4857 + info_ptr->lr_size
4858 + info_ptr->toc_size, 8);
4860 /* Calculate the offsets */
4861 switch (abi)
4863 case ABI_NONE:
4864 default:
4865 abort ();
4867 case ABI_AIX:
4868 case ABI_AIX_NODESC:
4869 info_ptr->fp_save_offset = - info_ptr->fp_size;
4870 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
4871 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
4872 info_ptr->lr_save_offset = 2*reg_size;
4873 break;
4875 case ABI_V4:
4876 case ABI_SOLARIS:
4877 info_ptr->fp_save_offset = - info_ptr->fp_size;
4878 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
4879 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
4880 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
4881 info_ptr->lr_save_offset = reg_size;
4882 break;
4885 total_raw_size = (info_ptr->vars_size
4886 + info_ptr->parm_size
4887 + info_ptr->save_size
4888 + info_ptr->varargs_size
4889 + info_ptr->fixed_size);
4891 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
4893 /* Determine if we need to allocate any stack frame:
4895 For AIX we need to push the stack if a frame pointer is needed (because
4896 the stack might be dynamically adjusted), if we are debugging, if we
4897 make calls, or if the sum of fp_save, gp_save, and local variables
4898 are more than the space needed to save all non-volatile registers:
4899 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved).
4901 For V.4 we don't have the stack cushion that AIX uses, but assume that
4902 the debugger can handle stackless frames. */
4904 if (info_ptr->calls_p)
4905 info_ptr->push_p = 1;
4907 else if (abi == ABI_V4 || abi == ABI_SOLARIS)
4908 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
4909 || info_ptr->calls_p);
4911 else
4912 info_ptr->push_p = (frame_pointer_needed
4913 || write_symbols != NO_DEBUG
4914 || ((total_raw_size - info_ptr->fixed_size)
4915 > (TARGET_32BIT ? 220 : 288)));
4917 /* Zero offsets if we're not saving those registers */
4918 if (info_ptr->fp_size == 0)
4919 info_ptr->fp_save_offset = 0;
4921 if (info_ptr->gp_size == 0)
4922 info_ptr->gp_save_offset = 0;
4924 if (! info_ptr->lr_save_p)
4925 info_ptr->lr_save_offset = 0;
4927 if (! info_ptr->cr_save_p)
4928 info_ptr->cr_save_offset = 0;
4930 if (! info_ptr->toc_save_p)
4931 info_ptr->toc_save_offset = 0;
4933 return info_ptr;
4936 void
4937 debug_stack_info (info)
4938 rs6000_stack_t *info;
4940 const char *abi_string;
4942 if (! info)
4943 info = rs6000_stack_info ();
4945 fprintf (stderr, "\nStack information for function %s:\n",
4946 ((current_function_decl && DECL_NAME (current_function_decl))
4947 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
4948 : "<unknown>"));
4950 switch (info->abi)
4952 default: abi_string = "Unknown"; break;
4953 case ABI_NONE: abi_string = "NONE"; break;
4954 case ABI_AIX: abi_string = "AIX"; break;
4955 case ABI_AIX_NODESC: abi_string = "AIX"; break;
4956 case ABI_V4: abi_string = "V.4"; break;
4957 case ABI_SOLARIS: abi_string = "Solaris"; break;
4960 fprintf (stderr, "\tABI = %5s\n", abi_string);
4962 if (info->first_gp_reg_save != 32)
4963 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
4965 if (info->first_fp_reg_save != 64)
4966 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
4968 if (info->lr_save_p)
4969 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
4971 if (info->cr_save_p)
4972 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
4974 if (info->toc_save_p)
4975 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
4977 if (info->push_p)
4978 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
4980 if (info->calls_p)
4981 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
4983 if (info->gp_save_offset)
4984 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
4986 if (info->fp_save_offset)
4987 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
4989 if (info->lr_save_offset)
4990 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
4992 if (info->cr_save_offset)
4993 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
4995 if (info->toc_save_offset)
4996 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
4998 if (info->varargs_save_offset)
4999 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
5001 if (info->total_size)
5002 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
5004 if (info->varargs_size)
5005 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
5007 if (info->vars_size)
5008 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
5010 if (info->parm_size)
5011 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
5013 if (info->fixed_size)
5014 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
5016 if (info->gp_size)
5017 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
5019 if (info->fp_size)
5020 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
5022 if (info->lr_size)
5023 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
5025 if (info->cr_size)
5026 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
5028 if (info->toc_size)
5029 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
5031 if (info->save_size)
5032 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
5034 if (info->reg_size != 4)
5035 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
5037 fprintf (stderr, "\n");
5041 rs6000_return_addr (count, frame)
5042 int count;
5043 rtx frame;
5045 rtx init, reg;
5047 /* Currently we don't optimize very well between prolog and body code and
5048 for PIC code the code can be actually quite bad, so don't try to be
5049 too clever here. */
5050 if (count != 0
5051 || flag_pic != 0
5052 || DEFAULT_ABI == ABI_AIX
5053 || DEFAULT_ABI == ABI_AIX_NODESC)
5055 cfun->machine->ra_needs_full_frame = 1;
5056 return
5057 gen_rtx_MEM (Pmode,
5058 memory_address (Pmode,
5059 plus_constant (copy_to_reg (gen_rtx_MEM (Pmode,
5060 memory_address (Pmode, frame))),
5061 RETURN_ADDRESS_OFFSET)));
5064 reg = cfun->machine->ra_rtx;
5065 if (reg == NULL)
5067 /* No rtx yet. Invent one, and initialize it from LR in
5068 the prologue. */
5069 reg = gen_reg_rtx (Pmode);
5070 cfun->machine->ra_rtx = reg;
5071 init = gen_rtx_SET (VOIDmode, reg,
5072 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5074 /* Emit the insn to the prologue with the other argument copies. */
5075 push_topmost_sequence ();
5076 emit_insn_after (init, get_insns ());
5077 pop_topmost_sequence ();
5080 return reg;
5083 static int
5084 rs6000_ra_ever_killed ()
5086 rtx top;
5088 #ifdef ASM_OUTPUT_MI_THUNK
5089 if (current_function_is_thunk)
5090 return 0;
5091 #endif
5092 if (!cfun->machine->ra_rtx || cfun->machine->ra_needs_full_frame)
5093 return regs_ever_live[LINK_REGISTER_REGNUM];
5095 push_topmost_sequence ();
5096 top = get_insns ();
5097 pop_topmost_sequence ();
5099 return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5100 top, NULL_RTX);
5103 /* Add a REG_MAYBE_DEAD note to the insn. */
5104 static void
5105 rs6000_maybe_dead (insn)
5106 rtx insn;
5108 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
5109 const0_rtx,
5110 REG_NOTES (insn));
5113 /* Emit instructions needed to load the TOC register.
5114 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
5115 a constant pool; or for SVR4 -fpic. */
5117 void
5118 rs6000_emit_load_toc_table (fromprolog)
5119 int fromprolog;
5121 rtx dest;
5122 dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
5124 if (TARGET_ELF)
5126 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5127 && flag_pic == 1)
5129 rtx temp = (fromprolog
5130 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5131 : gen_reg_rtx (Pmode));
5132 if (TARGET_32BIT)
5133 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
5134 else
5135 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_di (temp)));
5136 rs6000_maybe_dead (emit_move_insn (dest, temp));
5138 else if (flag_pic == 2)
5140 char buf[30];
5141 rtx tempLR = (fromprolog
5142 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5143 : gen_reg_rtx (Pmode));
5144 rtx temp0 = (fromprolog
5145 ? gen_rtx_REG (Pmode, 0)
5146 : gen_reg_rtx (Pmode));
5147 rtx symF;
5149 /* possibly create the toc section */
5150 if (! toc_initialized)
5152 toc_section ();
5153 function_section (current_function_decl);
5156 if (fromprolog)
5158 rtx symL;
5160 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
5161 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5163 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
5164 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5166 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
5167 symF)));
5168 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5169 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
5170 symL,
5171 symF)));
5173 else
5175 rtx tocsym;
5176 static int reload_toc_labelno = 0;
5178 tocsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name));
5180 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
5181 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5183 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
5184 symF,
5185 tocsym)));
5186 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5187 rs6000_maybe_dead (emit_move_insn (temp0,
5188 gen_rtx_MEM (Pmode, dest)));
5190 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
5192 else if (flag_pic == 0 && TARGET_MINIMAL_TOC)
5194 /* This is for AIX code running in non-PIC ELF. */
5195 char buf[30];
5196 rtx realsym;
5197 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
5198 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5200 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
5201 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
5203 else
5204 abort();
5206 else
5208 if (TARGET_32BIT)
5209 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
5210 else
5211 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
5215 int
5216 get_TOC_alias_set ()
5218 static int set = -1;
5219 if (set == -1)
5220 set = new_alias_set ();
5221 return set;
5224 /* This retuns nonzero if the current function uses the TOC. This is
5225 determined by the presence of (unspec ... 7), which is generated by
5226 the various load_toc_* patterns. */
5228 uses_TOC ()
5230 rtx insn;
5232 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5233 if (INSN_P (insn))
5235 rtx pat = PATTERN (insn);
5236 int i;
5238 if (GET_CODE (pat) == PARALLEL)
5239 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
5240 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
5241 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
5242 return 1;
5244 return 0;
5248 create_TOC_reference(symbol)
5249 rtx symbol;
5251 return gen_rtx_PLUS (Pmode,
5252 gen_rtx_REG (Pmode, TOC_REGISTER),
5253 gen_rtx_CONST (Pmode,
5254 gen_rtx_MINUS (Pmode, symbol,
5255 gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name)))));
5258 #if TARGET_AIX
5259 /* __throw will restore its own return address to be the same as the
5260 return address of the function that the throw is being made to.
5261 This is unfortunate, because we want to check the original
5262 return address to see if we need to restore the TOC.
5263 So we have to squirrel it away here.
5264 This is used only in compiling __throw and __rethrow.
5266 Most of this code should be removed by CSE. */
5267 static rtx insn_after_throw;
5269 /* This does the saving... */
5270 void
5271 rs6000_aix_emit_builtin_unwind_init ()
5273 rtx mem;
5274 rtx stack_top = gen_reg_rtx (Pmode);
5275 rtx opcode_addr = gen_reg_rtx (Pmode);
5277 insn_after_throw = gen_reg_rtx (SImode);
5279 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5280 emit_move_insn (stack_top, mem);
5282 mem = gen_rtx_MEM (Pmode,
5283 gen_rtx_PLUS (Pmode, stack_top,
5284 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5285 emit_move_insn (opcode_addr, mem);
5286 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
5289 /* Emit insns to _restore_ the TOC register, at runtime (specifically in _eh.o).
5290 Only used on AIX.
5292 The idea is that on AIX, function calls look like this:
5293 bl somefunction-trampoline
5294 lwz r2,20(sp)
5296 and later,
5297 somefunction-trampoline:
5298 stw r2,20(sp)
5299 ... load function address in the count register ...
5300 bctr
5301 or like this, if the linker determines that this is not a cross-module call
5302 and so the TOC need not be restored:
5303 bl somefunction
5305 or like this, if the compiler could determine that this is not a
5306 cross-module call:
5307 bl somefunction
5308 now, the tricky bit here is that register 2 is saved and restored
5309 by the _linker_, so we can't readily generate debugging information
5310 for it. So we need to go back up the call chain looking at the
5311 insns at return addresses to see which calls saved the TOC register
5312 and so see where it gets restored from.
5314 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
5315 just before the actual epilogue.
5317 On the bright side, this incurs no space or time overhead unless an
5318 exception is thrown, except for the extra code in libgcc.a.
5320 The parameter STACKSIZE is a register containing (at runtime)
5321 the amount to be popped off the stack in addition to the stack frame
5322 of this routine (which will be __throw or __rethrow, and so is
5323 guaranteed to have a stack frame). */
5324 void
5325 rs6000_emit_eh_toc_restore (stacksize)
5326 rtx stacksize;
5328 rtx top_of_stack;
5329 rtx bottom_of_stack = gen_reg_rtx (Pmode);
5330 rtx tocompare = gen_reg_rtx (SImode);
5331 rtx opcode = gen_reg_rtx (SImode);
5332 rtx opcode_addr = gen_reg_rtx (Pmode);
5333 rtx mem;
5334 rtx loop_start = gen_label_rtx ();
5335 rtx no_toc_restore_needed = gen_label_rtx ();
5336 rtx loop_exit = gen_label_rtx ();
5338 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5339 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5340 emit_move_insn (bottom_of_stack, mem);
5342 top_of_stack = expand_binop (Pmode, add_optab,
5343 bottom_of_stack, stacksize,
5344 NULL_RTX, 1, OPTAB_WIDEN);
5346 emit_move_insn (tocompare,
5347 GEN_INT (trunc_int_for_mode (TARGET_32BIT
5348 ? 0x80410014
5349 : 0xE8410028, SImode)));
5351 if (insn_after_throw == NULL_RTX)
5352 abort();
5353 emit_move_insn (opcode, insn_after_throw);
5355 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
5356 emit_label (loop_start);
5358 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
5359 SImode, NULL_RTX, 0, NULL_RTX,
5360 no_toc_restore_needed);
5362 mem = gen_rtx_MEM (Pmode,
5363 gen_rtx_PLUS (Pmode, bottom_of_stack,
5364 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
5365 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
5367 emit_label (no_toc_restore_needed);
5368 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
5369 Pmode, NULL_RTX, 0, NULL_RTX,
5370 loop_exit);
5372 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
5373 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5374 emit_move_insn (bottom_of_stack, mem);
5376 mem = gen_rtx_MEM (Pmode,
5377 gen_rtx_PLUS (Pmode, bottom_of_stack,
5378 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5379 emit_move_insn (opcode_addr, mem);
5380 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
5382 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
5383 emit_jump (loop_start);
5384 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
5385 emit_label (loop_exit);
5387 #endif /* TARGET_AIX */
5389 /* This ties together stack memory
5390 (MEM with an alias set of rs6000_sr_alias_set)
5391 and the change to the stack pointer. */
5392 static void
5393 rs6000_emit_stack_tie ()
5395 rtx mem;
5396 mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
5397 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5398 emit_insn (gen_stack_tie (mem));
5401 /* Emit the correct code for allocating stack space, as insns.
5402 If COPY_R12, make sure a copy of the old frame is left in r12.
5403 The generated code may use hard register 0 as a temporary. */
5405 static void
5406 rs6000_emit_allocate_stack (size, copy_r12)
5407 HOST_WIDE_INT size;
5408 int copy_r12;
5410 rtx insn;
5411 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5412 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
5413 rtx todec = GEN_INT (-size);
5415 if (current_function_limit_stack)
5417 if (REG_P (stack_limit_rtx)
5418 && REGNO (stack_limit_rtx) > 1
5419 && REGNO (stack_limit_rtx) <= 31)
5421 emit_insn (Pmode == SImode
5422 ? gen_addsi3 (tmp_reg,
5423 stack_limit_rtx,
5424 GEN_INT (size))
5425 : gen_adddi3 (tmp_reg,
5426 stack_limit_rtx,
5427 GEN_INT (size)));
5429 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5430 const0_rtx));
5432 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
5433 && TARGET_32BIT
5434 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5436 rtx toload = gen_rtx_CONST (VOIDmode,
5437 gen_rtx_PLUS (Pmode,
5438 stack_limit_rtx,
5439 GEN_INT (size)));
5441 emit_insn (gen_elf_high (tmp_reg, toload));
5442 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
5443 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5444 const0_rtx));
5446 else
5447 warning ("stack limit expression is not supported");
5450 if (copy_r12 || ! TARGET_UPDATE)
5451 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
5453 if (TARGET_UPDATE)
5455 if (size > 32767)
5457 /* Need a note here so that try_split doesn't get confused. */
5458 if (get_last_insn() == NULL_RTX)
5459 emit_note (0, NOTE_INSN_DELETED);
5460 insn = emit_move_insn (tmp_reg, todec);
5461 try_split (PATTERN (insn), insn, 0);
5462 todec = tmp_reg;
5465 if (Pmode == SImode)
5466 insn = emit_insn (gen_movsi_update (stack_reg, stack_reg,
5467 todec, stack_reg));
5468 else
5469 insn = emit_insn (gen_movdi_update (stack_reg, stack_reg,
5470 todec, stack_reg));
5472 else
5474 if (Pmode == SImode)
5475 insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec));
5476 else
5477 insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec));
5478 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
5479 gen_rtx_REG (Pmode, 12));
5482 RTX_FRAME_RELATED_P (insn) = 1;
5483 REG_NOTES (insn) =
5484 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5485 gen_rtx_SET (VOIDmode, stack_reg,
5486 gen_rtx_PLUS (Pmode, stack_reg,
5487 GEN_INT (-size))),
5488 REG_NOTES (insn));
5491 /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced with
5492 (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 is not
5493 NULL.
5494 It would be nice if dwarf2out_frame_debug_expr could deduce these
5495 equivalences by itself so it wasn't necessary to hold its hand so much. */
5497 static void
5498 rs6000_frame_related (insn, reg, val, reg2, rreg)
5499 rtx insn;
5500 rtx reg;
5501 HOST_WIDE_INT val;
5502 rtx reg2;
5503 rtx rreg;
5505 rtx real, temp;
5507 real = copy_rtx (PATTERN (insn));
5509 real = replace_rtx (real, reg,
5510 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
5511 STACK_POINTER_REGNUM),
5512 GEN_INT (val)));
5514 /* We expect that 'real' is either a SET or a PARALLEL containing
5515 SETs (and possibly other stuff). In a PARALLEL, all the SETs
5516 are important so they all have to be marked RTX_FRAME_RELATED_P. */
5518 if (GET_CODE (real) == SET)
5520 rtx set = real;
5522 temp = simplify_rtx (SET_SRC (set));
5523 if (temp)
5524 SET_SRC (set) = temp;
5525 temp = simplify_rtx (SET_DEST (set));
5526 if (temp)
5527 SET_DEST (set) = temp;
5528 if (GET_CODE (SET_DEST (set)) == MEM)
5530 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5531 if (temp)
5532 XEXP (SET_DEST (set), 0) = temp;
5535 else if (GET_CODE (real) == PARALLEL)
5537 int i;
5538 for (i = 0; i < XVECLEN (real, 0); i++)
5539 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
5541 rtx set = XVECEXP (real, 0, i);
5543 temp = simplify_rtx (SET_SRC (set));
5544 if (temp)
5545 SET_SRC (set) = temp;
5546 temp = simplify_rtx (SET_DEST (set));
5547 if (temp)
5548 SET_DEST (set) = temp;
5549 if (GET_CODE (SET_DEST (set)) == MEM)
5551 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5552 if (temp)
5553 XEXP (SET_DEST (set), 0) = temp;
5555 RTX_FRAME_RELATED_P (set) = 1;
5558 else
5559 abort();
5561 if (reg2 != NULL_RTX)
5562 real = replace_rtx (real, reg2, rreg);
5564 RTX_FRAME_RELATED_P (insn) = 1;
5565 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5566 real,
5567 REG_NOTES (insn));
5570 /* Emit function prologue as insns. */
5572 void
5573 rs6000_emit_prologue()
5575 rs6000_stack_t *info = rs6000_stack_info ();
5576 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5577 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5578 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5579 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
5580 rtx frame_reg_rtx = sp_reg_rtx;
5581 rtx cr_save_rtx = NULL;
5582 rtx insn;
5583 int saving_FPRs_inline;
5584 int using_store_multiple;
5585 HOST_WIDE_INT sp_offset = 0;
5587 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5588 && info->first_gp_reg_save < 31);
5589 saving_FPRs_inline = (info->first_fp_reg_save == 64
5590 || FP_SAVE_INLINE (info->first_fp_reg_save));
5592 /* For V.4, update stack before we do any saving and set back pointer. */
5593 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5595 if (info->total_size < 32767)
5596 sp_offset = info->total_size;
5597 else
5598 frame_reg_rtx = frame_ptr_rtx;
5599 rs6000_emit_allocate_stack (info->total_size,
5600 (frame_reg_rtx != sp_reg_rtx
5601 && (info->cr_save_p
5602 || info->lr_save_p
5603 || info->first_fp_reg_save < 64
5604 || info->first_gp_reg_save < 32
5605 )));
5606 if (frame_reg_rtx != sp_reg_rtx)
5607 rs6000_emit_stack_tie ();
5610 /* If we use the link register, get it into r0. */
5611 if (info->lr_save_p)
5612 emit_move_insn (gen_rtx_REG (Pmode, 0),
5613 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5615 /* If we need to save CR, put it into r12. */
5616 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
5618 cr_save_rtx = gen_rtx_REG (SImode, 12);
5619 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5622 /* Do any required saving of fpr's. If only one or two to save, do it
5623 ourself. Otherwise, call function. */
5624 if (saving_FPRs_inline)
5626 int i;
5627 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5628 if ((regs_ever_live[info->first_fp_reg_save+i]
5629 && ! call_used_regs[info->first_fp_reg_save+i]))
5631 rtx addr, reg, mem;
5632 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5633 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5634 GEN_INT (info->fp_save_offset
5635 + sp_offset
5636 + 8*i));
5637 mem = gen_rtx_MEM (DFmode, addr);
5638 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5640 insn = emit_move_insn (mem, reg);
5641 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5642 NULL_RTX, NULL_RTX);
5645 else if (info->first_fp_reg_save != 64)
5647 int i;
5648 char rname[30];
5649 const char *alloc_rname;
5650 rtvec p;
5651 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
5653 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
5654 gen_rtx_REG (Pmode,
5655 LINK_REGISTER_REGNUM));
5656 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
5657 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
5658 alloc_rname = ggc_strdup (rname);
5659 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
5660 gen_rtx_SYMBOL_REF (Pmode,
5661 alloc_rname));
5662 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5664 rtx addr, reg, mem;
5665 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5666 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5667 GEN_INT (info->fp_save_offset
5668 + sp_offset + 8*i));
5669 mem = gen_rtx_MEM (DFmode, addr);
5670 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5672 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
5674 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5675 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5676 NULL_RTX, NULL_RTX);
5679 /* Save GPRs. This is done as a PARALLEL if we are using
5680 the store-multiple instructions. */
5681 if (using_store_multiple)
5683 rtvec p, dwarfp;
5684 int i;
5685 p = rtvec_alloc (32 - info->first_gp_reg_save);
5686 dwarfp = rtvec_alloc (32 - info->first_gp_reg_save);
5687 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5689 rtx addr, reg, mem;
5690 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5691 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5692 GEN_INT (info->gp_save_offset
5693 + sp_offset
5694 + reg_size * i));
5695 mem = gen_rtx_MEM (reg_mode, addr);
5696 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5698 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
5700 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5701 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5702 NULL_RTX, NULL_RTX);
5704 else
5706 int i;
5707 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5708 if ((regs_ever_live[info->first_gp_reg_save+i]
5709 && ! call_used_regs[info->first_gp_reg_save+i])
5710 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
5711 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5712 && flag_pic == 1))
5714 rtx addr, reg, mem;
5715 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5716 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5717 GEN_INT (info->gp_save_offset
5718 + sp_offset
5719 + reg_size * i));
5720 mem = gen_rtx_MEM (reg_mode, addr);
5721 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5723 insn = emit_move_insn (mem, reg);
5724 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5725 NULL_RTX, NULL_RTX);
5729 /* Save lr if we used it. */
5730 if (info->lr_save_p)
5732 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5733 GEN_INT (info->lr_save_offset + sp_offset));
5734 rtx reg = gen_rtx_REG (Pmode, 0);
5735 rtx mem = gen_rtx_MEM (Pmode, addr);
5736 /* This should not be of rs6000_sr_alias_set, because of
5737 __builtin_return_address. */
5739 insn = emit_move_insn (mem, reg);
5740 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5741 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5744 /* Save CR if we use any that must be preserved. */
5745 if (info->cr_save_p)
5747 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5748 GEN_INT (info->cr_save_offset + sp_offset));
5749 rtx mem = gen_rtx_MEM (SImode, addr);
5750 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5752 /* If r12 was used to hold the original sp, copy cr into r0 now
5753 that it's free. */
5754 if (REGNO (frame_reg_rtx) == 12)
5756 cr_save_rtx = gen_rtx_REG (SImode, 0);
5757 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5759 insn = emit_move_insn (mem, cr_save_rtx);
5761 /* Now, there's no way that dwarf2out_frame_debug_expr is going
5762 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
5763 OK. All we have to do is specify that _one_ condition code
5764 register is saved in this stack slot. The thrower's epilogue
5765 will then restore all the call-saved registers. */
5766 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5767 cr_save_rtx, gen_rtx_REG (SImode, CR0_REGNO));
5770 /* Update stack and set back pointer unless this is V.4,
5771 for which it was done previously. */
5772 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
5773 rs6000_emit_allocate_stack (info->total_size, FALSE);
5775 /* Set frame pointer, if needed. */
5776 if (frame_pointer_needed)
5778 insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM),
5779 sp_reg_rtx);
5780 RTX_FRAME_RELATED_P (insn) = 1;
5783 /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
5784 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
5785 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5786 && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
5788 /* If emit_load_toc_table will use the link register, we need to save
5789 it. We use R11 for this purpose because emit_load_toc_table
5790 can use register 0. This allows us to use a plain 'blr' to return
5791 from the procedure more often. */
5792 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 &&
5793 ! info->lr_save_p);
5794 if (save_LR_around_toc_setup)
5795 emit_move_insn (gen_rtx_REG (Pmode, 11),
5796 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5798 rs6000_emit_load_toc_table (TRUE);
5800 if (save_LR_around_toc_setup)
5801 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5802 gen_rtx_REG (Pmode, 11));
5807 /* Write function prologue. */
5808 void
5809 output_prolog (file, size)
5810 FILE *file;
5811 int size ATTRIBUTE_UNUSED;
5813 rs6000_stack_t *info = rs6000_stack_info ();
5815 if (TARGET_DEBUG_STACK)
5816 debug_stack_info (info);
5818 /* Write .extern for any function we will call to save and restore fp
5819 values. */
5820 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
5821 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
5822 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
5823 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
5825 /* Write .extern for AIX common mode routines, if needed. */
5826 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
5828 fputs ("\t.extern __mulh\n", file);
5829 fputs ("\t.extern __mull\n", file);
5830 fputs ("\t.extern __divss\n", file);
5831 fputs ("\t.extern __divus\n", file);
5832 fputs ("\t.extern __quoss\n", file);
5833 fputs ("\t.extern __quous\n", file);
5834 common_mode_defined = 1;
5837 if (! HAVE_prologue)
5839 start_sequence ();
5841 /* A NOTE_INSN_DELETED is supposed to be at the start
5842 and end of the "toplevel" insn chain. */
5843 emit_note (0, NOTE_INSN_DELETED);
5844 rs6000_emit_prologue ();
5845 emit_note (0, NOTE_INSN_DELETED);
5847 if (TARGET_DEBUG_STACK)
5848 debug_rtx_list (get_insns(), 100);
5849 final (get_insns(), file, FALSE, FALSE);
5850 end_sequence ();
5853 rs6000_pic_labelno++;
5856 /* Emit function epilogue as insns.
5858 At present, dwarf2out_frame_debug_expr doesn't understand
5859 register restores, so we don't bother setting RTX_FRAME_RELATED_P
5860 anywhere in the epilogue. Most of the insns below would in any case
5861 need special notes to explain where r11 is in relation to the stack. */
5863 void
5864 rs6000_emit_epilogue(sibcall)
5865 int sibcall;
5867 rs6000_stack_t *info;
5868 int restoring_FPRs_inline;
5869 int using_load_multiple;
5870 int using_mfcr_multiple;
5871 int use_backchain_to_restore_sp;
5872 int sp_offset = 0;
5873 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
5874 rtx frame_reg_rtx = sp_reg_rtx;
5875 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5876 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5877 int i;
5879 info = rs6000_stack_info ();
5880 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5881 && info->first_gp_reg_save < 31);
5882 restoring_FPRs_inline = (sibcall
5883 || info->first_fp_reg_save == 64
5884 || FP_SAVE_INLINE (info->first_fp_reg_save));
5885 use_backchain_to_restore_sp = (frame_pointer_needed
5886 || current_function_calls_alloca
5887 || info->total_size > 32767);
5888 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
5889 || rs6000_cpu == PROCESSOR_PPC603
5890 || rs6000_cpu == PROCESSOR_PPC750
5891 || optimize_size);
5893 /* If we have a frame pointer, a call to alloca, or a large stack
5894 frame, restore the old stack pointer using the backchain. Otherwise,
5895 we know what size to update it with. */
5896 if (use_backchain_to_restore_sp)
5898 /* Under V.4, don't reset the stack pointer until after we're done
5899 loading the saved registers. */
5900 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5901 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
5903 emit_move_insn (frame_reg_rtx,
5904 gen_rtx_MEM (Pmode, sp_reg_rtx));
5907 else if (info->push_p)
5909 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5910 sp_offset = info->total_size;
5911 else
5913 emit_insn (TARGET_32BIT
5914 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
5915 GEN_INT (info->total_size))
5916 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
5917 GEN_INT (info->total_size)));
5921 /* Get the old lr if we saved it. */
5922 if (info->lr_save_p)
5924 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5925 GEN_INT (info->lr_save_offset + sp_offset));
5926 rtx mem = gen_rtx_MEM (Pmode, addr);
5927 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5929 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
5932 /* Get the old cr if we saved it. */
5933 if (info->cr_save_p)
5935 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5936 GEN_INT (info->cr_save_offset + sp_offset));
5937 rtx mem = gen_rtx_MEM (SImode, addr);
5938 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5940 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
5943 /* Set LR here to try to overlap restores below. */
5944 if (info->lr_save_p)
5945 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5946 gen_rtx_REG (Pmode, 0));
5949 /* Restore GPRs. This is done as a PARALLEL if we are using
5950 the load-multiple instructions. */
5951 if (using_load_multiple)
5953 rtvec p;
5954 p = rtvec_alloc (32 - info->first_gp_reg_save);
5955 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5957 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5958 GEN_INT (info->gp_save_offset
5959 + sp_offset
5960 + reg_size * i));
5961 rtx mem = gen_rtx_MEM (reg_mode, addr);
5962 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5964 RTVEC_ELT (p, i) =
5965 gen_rtx_SET (VOIDmode,
5966 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
5967 mem);
5969 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5971 else
5972 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5973 if ((regs_ever_live[info->first_gp_reg_save+i]
5974 && ! call_used_regs[info->first_gp_reg_save+i])
5975 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
5976 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5977 && flag_pic == 1))
5979 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5980 GEN_INT (info->gp_save_offset
5981 + sp_offset
5982 + reg_size * i));
5983 rtx mem = gen_rtx_MEM (reg_mode, addr);
5984 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5986 emit_move_insn (gen_rtx_REG (reg_mode,
5987 info->first_gp_reg_save + i),
5988 mem);
5991 /* Restore fpr's if we need to do it without calling a function. */
5992 if (restoring_FPRs_inline)
5993 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5994 if ((regs_ever_live[info->first_fp_reg_save+i]
5995 && ! call_used_regs[info->first_fp_reg_save+i]))
5997 rtx addr, mem;
5998 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5999 GEN_INT (info->fp_save_offset
6000 + sp_offset
6001 + 8*i));
6002 mem = gen_rtx_MEM (DFmode, addr);
6003 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6005 emit_move_insn (gen_rtx_REG (DFmode,
6006 info->first_fp_reg_save + i),
6007 mem);
6010 /* If we saved cr, restore it here. Just those that were used. */
6011 if (info->cr_save_p)
6013 rtx r12_rtx = gen_rtx_REG (SImode, 12);
6014 int count = 0;
6016 if (using_mfcr_multiple)
6018 for (i = 0; i < 8; i++)
6019 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6020 count++;
6021 if (count == 0)
6022 abort ();
6025 if (using_mfcr_multiple && count > 1)
6027 rtvec p;
6028 int ndx;
6030 p = rtvec_alloc (count);
6032 ndx = 0;
6033 for (i = 0; i < 8; i++)
6034 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6036 rtvec r = rtvec_alloc (2);
6037 RTVEC_ELT (r, 0) = r12_rtx;
6038 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
6039 RTVEC_ELT (p, ndx) =
6040 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
6041 gen_rtx_UNSPEC (CCmode, r, 20));
6042 ndx++;
6044 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
6045 if (ndx != count)
6046 abort ();
6048 else
6049 for (i = 0; i < 8; i++)
6050 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6052 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
6053 CR0_REGNO+i),
6054 r12_rtx));
6058 /* If this is V.4, unwind the stack pointer after all of the loads
6059 have been done. We need to emit a block here so that sched
6060 doesn't decide to move the sp change before the register restores
6061 (which may not have any obvious dependency on the stack). This
6062 doesn't hurt performance, because there is no scheduling that can
6063 be done after this point. */
6064 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6066 if (frame_reg_rtx != sp_reg_rtx)
6067 rs6000_emit_stack_tie ();
6069 if (use_backchain_to_restore_sp)
6071 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
6073 else if (sp_offset != 0)
6075 emit_insn (Pmode == SImode
6076 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
6077 GEN_INT (sp_offset))
6078 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
6079 GEN_INT (sp_offset)));
6083 if (!sibcall)
6085 rtvec p;
6086 if (! restoring_FPRs_inline)
6087 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
6088 else
6089 p = rtvec_alloc (2);
6091 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
6092 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
6093 gen_rtx_REG (Pmode,
6094 LINK_REGISTER_REGNUM));
6096 /* If we have to restore more than two FP registers, branch to the
6097 restore function. It will return to our caller. */
6098 if (! restoring_FPRs_inline)
6100 int i;
6101 char rname[30];
6102 const char *alloc_rname;
6104 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
6105 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
6106 alloc_rname = ggc_strdup (rname);
6107 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
6108 gen_rtx_SYMBOL_REF (Pmode,
6109 alloc_rname));
6111 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
6113 rtx addr, mem;
6114 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
6115 GEN_INT (info->fp_save_offset + 8*i));
6116 mem = gen_rtx_MEM (DFmode, addr);
6117 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6119 RTVEC_ELT (p, i+3) =
6120 gen_rtx_SET (VOIDmode,
6121 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
6122 mem);
6126 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
6130 /* Write function epilogue. */
6132 void
6133 output_epilog (file, size)
6134 FILE *file;
6135 int size ATTRIBUTE_UNUSED;
6137 rs6000_stack_t *info = rs6000_stack_info ();
6139 if (! HAVE_epilogue)
6141 rtx insn = get_last_insn ();
6142 /* If the last insn was a BARRIER, we don't have to write anything except
6143 the trace table. */
6144 if (GET_CODE (insn) == NOTE)
6145 insn = prev_nonnote_insn (insn);
6146 if (insn == 0 || GET_CODE (insn) != BARRIER)
6148 /* This is slightly ugly, but at least we don't have two
6149 copies of the epilogue-emitting code. */
6150 start_sequence ();
6152 /* A NOTE_INSN_DELETED is supposed to be at the start
6153 and end of the "toplevel" insn chain. */
6154 emit_note (0, NOTE_INSN_DELETED);
6155 rs6000_emit_epilogue (FALSE);
6156 emit_note (0, NOTE_INSN_DELETED);
6158 if (TARGET_DEBUG_STACK)
6159 debug_rtx_list (get_insns(), 100);
6160 final (get_insns(), file, FALSE, FALSE);
6161 end_sequence ();
6165 /* Output a traceback table here. See /usr/include/sys/debug.h for info
6166 on its format.
6168 We don't output a traceback table if -finhibit-size-directive was
6169 used. The documentation for -finhibit-size-directive reads
6170 ``don't output a @code{.size} assembler directive, or anything
6171 else that would cause trouble if the function is split in the
6172 middle, and the two halves are placed at locations far apart in
6173 memory.'' The traceback table has this property, since it
6174 includes the offset from the start of the function to the
6175 traceback table itself.
6177 System V.4 Powerpc's (and the embedded ABI derived from it) use a
6178 different traceback table. */
6179 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
6181 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
6182 int fixed_parms, float_parms, parm_info;
6183 int i;
6185 while (*fname == '.') /* V.4 encodes . in the name */
6186 fname++;
6188 /* Need label immediately before tbtab, so we can compute its offset
6189 from the function start. */
6190 if (*fname == '*')
6191 ++fname;
6192 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6193 ASM_OUTPUT_LABEL (file, fname);
6195 /* The .tbtab pseudo-op can only be used for the first eight
6196 expressions, since it can't handle the possibly variable
6197 length fields that follow. However, if you omit the optional
6198 fields, the assembler outputs zeros for all optional fields
6199 anyways, giving each variable length field is minimum length
6200 (as defined in sys/debug.h). Thus we can not use the .tbtab
6201 pseudo-op at all. */
6203 /* An all-zero word flags the start of the tbtab, for debuggers
6204 that have to find it by searching forward from the entry
6205 point or from the current pc. */
6206 fputs ("\t.long 0\n", file);
6208 /* Tbtab format type. Use format type 0. */
6209 fputs ("\t.byte 0,", file);
6211 /* Language type. Unfortunately, there doesn't seem to be any
6212 official way to get this info, so we use language_string. C
6213 is 0. C++ is 9. No number defined for Obj-C, so use the
6214 value for C for now. There is no official value for Java,
6215 although IBM appears to be using 13. There is no official value
6216 for Chill, so we've choosen 44 pseudo-randomly. */
6217 if (! strcmp (language_string, "GNU C")
6218 || ! strcmp (language_string, "GNU Objective-C"))
6219 i = 0;
6220 else if (! strcmp (language_string, "GNU F77"))
6221 i = 1;
6222 else if (! strcmp (language_string, "GNU Ada"))
6223 i = 3;
6224 else if (! strcmp (language_string, "GNU Pascal"))
6225 i = 2;
6226 else if (! strcmp (language_string, "GNU C++"))
6227 i = 9;
6228 else if (! strcmp (language_string, "GNU Java"))
6229 i = 13;
6230 else if (! strcmp (language_string, "GNU CHILL"))
6231 i = 44;
6232 else
6233 abort ();
6234 fprintf (file, "%d,", i);
6236 /* 8 single bit fields: global linkage (not set for C extern linkage,
6237 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
6238 from start of procedure stored in tbtab, internal function, function
6239 has controlled storage, function has no toc, function uses fp,
6240 function logs/aborts fp operations. */
6241 /* Assume that fp operations are used if any fp reg must be saved. */
6242 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
6244 /* 6 bitfields: function is interrupt handler, name present in
6245 proc table, function calls alloca, on condition directives
6246 (controls stack walks, 3 bits), saves condition reg, saves
6247 link reg. */
6248 /* The `function calls alloca' bit seems to be set whenever reg 31 is
6249 set up as a frame pointer, even when there is no alloca call. */
6250 fprintf (file, "%d,",
6251 ((1 << 6) | (frame_pointer_needed << 5)
6252 | (info->cr_save_p << 1) | (info->lr_save_p)));
6254 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
6255 (6 bits). */
6256 fprintf (file, "%d,",
6257 (info->push_p << 7) | (64 - info->first_fp_reg_save));
6259 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
6260 fprintf (file, "%d,", (32 - first_reg_to_save ()));
6263 /* Compute the parameter info from the function decl argument
6264 list. */
6265 tree decl;
6266 int next_parm_info_bit;
6268 next_parm_info_bit = 31;
6269 parm_info = 0;
6270 fixed_parms = 0;
6271 float_parms = 0;
6273 for (decl = DECL_ARGUMENTS (current_function_decl);
6274 decl; decl = TREE_CHAIN (decl))
6276 rtx parameter = DECL_INCOMING_RTL (decl);
6277 enum machine_mode mode = GET_MODE (parameter);
6279 if (GET_CODE (parameter) == REG)
6281 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6283 int bits;
6285 float_parms++;
6287 if (mode == SFmode)
6288 bits = 0x2;
6289 else if (mode == DFmode)
6290 bits = 0x3;
6291 else
6292 abort ();
6294 /* If only one bit will fit, don't or in this entry. */
6295 if (next_parm_info_bit > 0)
6296 parm_info |= (bits << (next_parm_info_bit - 1));
6297 next_parm_info_bit -= 2;
6299 else
6301 fixed_parms += ((GET_MODE_SIZE (mode)
6302 + (UNITS_PER_WORD - 1))
6303 / UNITS_PER_WORD);
6304 next_parm_info_bit -= 1;
6310 /* Number of fixed point parameters. */
6311 /* This is actually the number of words of fixed point parameters; thus
6312 an 8 byte struct counts as 2; and thus the maximum value is 8. */
6313 fprintf (file, "%d,", fixed_parms);
6315 /* 2 bitfields: number of floating point parameters (7 bits), parameters
6316 all on stack. */
6317 /* This is actually the number of fp registers that hold parameters;
6318 and thus the maximum value is 13. */
6319 /* Set parameters on stack bit if parameters are not in their original
6320 registers, regardless of whether they are on the stack? Xlc
6321 seems to set the bit when not optimizing. */
6322 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
6324 /* Optional fields follow. Some are variable length. */
6326 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
6327 11 double float. */
6328 /* There is an entry for each parameter in a register, in the order that
6329 they occur in the parameter list. Any intervening arguments on the
6330 stack are ignored. If the list overflows a long (max possible length
6331 34 bits) then completely leave off all elements that don't fit. */
6332 /* Only emit this long if there was at least one parameter. */
6333 if (fixed_parms || float_parms)
6334 fprintf (file, "\t.long %d\n", parm_info);
6336 /* Offset from start of code to tb table. */
6337 fputs ("\t.long ", file);
6338 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6339 #if TARGET_AIX
6340 RS6000_OUTPUT_BASENAME (file, fname);
6341 #else
6342 assemble_name (file, fname);
6343 #endif
6344 fputs ("-.", file);
6345 #if TARGET_AIX
6346 RS6000_OUTPUT_BASENAME (file, fname);
6347 #else
6348 assemble_name (file, fname);
6349 #endif
6350 putc ('\n', file);
6352 /* Interrupt handler mask. */
6353 /* Omit this long, since we never set the interrupt handler bit
6354 above. */
6356 /* Number of CTL (controlled storage) anchors. */
6357 /* Omit this long, since the has_ctl bit is never set above. */
6359 /* Displacement into stack of each CTL anchor. */
6360 /* Omit this list of longs, because there are no CTL anchors. */
6362 /* Length of function name. */
6363 fprintf (file, "\t.short %d\n", (int) strlen (fname));
6365 /* Function name. */
6366 assemble_string (fname, strlen (fname));
6368 /* Register for alloca automatic storage; this is always reg 31.
6369 Only emit this if the alloca bit was set above. */
6370 if (frame_pointer_needed)
6371 fputs ("\t.byte 31\n", file);
6375 /* A C compound statement that outputs the assembler code for a thunk function,
6376 used to implement C++ virtual function calls with multiple inheritance. The
6377 thunk acts as a wrapper around a virtual function, adjusting the implicit
6378 object parameter before handing control off to the real function.
6380 First, emit code to add the integer DELTA to the location that contains the
6381 incoming first argument. Assume that this argument contains a pointer, and
6382 is the one used to pass the `this' pointer in C++. This is the incoming
6383 argument *before* the function prologue, e.g. `%o0' on a sparc. The
6384 addition must preserve the values of all other incoming arguments.
6386 After the addition, emit code to jump to FUNCTION, which is a
6387 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
6388 the return address. Hence returning from FUNCTION will return to whoever
6389 called the current `thunk'.
6391 The effect must be as if FUNCTION had been called directly with the adjusted
6392 first argument. This macro is responsible for emitting all of the code for
6393 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
6394 invoked.
6396 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
6397 extracted from it.) It might possibly be useful on some targets, but
6398 probably not.
6400 If you do not define this macro, the target-independent code in the C++
6401 frontend will generate a less efficient heavyweight thunk that calls
6402 FUNCTION instead of jumping to it. The generic approach does not support
6403 varargs. */
6405 void
6406 output_mi_thunk (file, thunk_fndecl, delta, function)
6407 FILE *file;
6408 tree thunk_fndecl ATTRIBUTE_UNUSED;
6409 int delta;
6410 tree function;
6412 const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
6413 const char *prefix;
6414 const char *fname;
6415 const char *r0 = reg_names[0];
6416 const char *toc = reg_names[2];
6417 const char *schain = reg_names[11];
6418 const char *r12 = reg_names[12];
6419 char buf[512];
6420 static int labelno = 0;
6422 /* Small constants that can be done by one add instruction */
6423 if (delta >= -32768 && delta <= 32767)
6425 if (! TARGET_NEW_MNEMONICS)
6426 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
6427 else
6428 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
6431 /* Large constants that can be done by one addis instruction */
6432 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
6433 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6434 delta >> 16);
6436 /* 32-bit constants that can be done by an add and addis instruction. */
6437 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
6439 /* Break into two pieces, propagating the sign bit from the low word to
6440 the upper word. */
6441 int delta_high = delta >> 16;
6442 int delta_low = delta & 0xffff;
6443 if ((delta_low & 0x8000) != 0)
6445 delta_high++;
6446 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
6449 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6450 delta_high);
6452 if (! TARGET_NEW_MNEMONICS)
6453 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
6454 else
6455 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
6458 /* 64-bit constants, fixme */
6459 else
6460 abort ();
6462 /* Get the prefix in front of the names. */
6463 switch (DEFAULT_ABI)
6465 default:
6466 abort ();
6468 case ABI_AIX:
6469 prefix = ".";
6470 break;
6472 case ABI_V4:
6473 case ABI_AIX_NODESC:
6474 case ABI_SOLARIS:
6475 prefix = "";
6476 break;
6479 /* If the function is compiled in this module, jump to it directly.
6480 Otherwise, load up its address and jump to it. */
6482 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
6484 if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode)
6485 && ! lookup_attribute ("longcall",
6486 TYPE_ATTRIBUTES (TREE_TYPE (function))))
6488 fprintf (file, "\tb %s", prefix);
6489 assemble_name (file, fname);
6490 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
6491 putc ('\n', file);
6494 else
6496 switch (DEFAULT_ABI)
6498 default:
6499 abort ();
6501 case ABI_AIX:
6502 /* Set up a TOC entry for the function. */
6503 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
6504 toc_section ();
6505 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
6506 labelno++;
6508 /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since
6509 there will be only one TOC entry for this function. */
6510 fputs ("\t.tc\t", file);
6511 assemble_name (file, buf);
6512 fputs ("[TC],", file);
6513 assemble_name (file, buf);
6514 putc ('\n', file);
6515 text_section ();
6516 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12);
6517 assemble_name (file, buf);
6518 asm_fprintf (file, "(%s)\n", reg_names[2]);
6519 asm_fprintf (file,
6520 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
6521 r0, r12);
6523 asm_fprintf (file,
6524 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
6525 toc, r12);
6527 asm_fprintf (file, "\tmtctr %s\n", r0);
6528 asm_fprintf (file,
6529 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
6530 schain, r12);
6532 asm_fprintf (file, "\tbctr\n");
6533 break;
6535 case ABI_AIX_NODESC:
6536 case ABI_SOLARIS:
6537 case ABI_V4:
6538 fprintf (file, "\tb %s", prefix);
6539 assemble_name (file, fname);
6540 if (flag_pic) fputs ("@plt", file);
6541 putc ('\n', file);
6542 break;
6548 /* A quick summary of the various types of 'constant-pool tables'
6549 under PowerPC:
6551 Target Flags Name One table per
6552 AIX (none) AIX TOC object file
6553 AIX -mfull-toc AIX TOC object file
6554 AIX -mminimal-toc AIX minimal TOC translation unit
6555 SVR4/EABI (none) SVR4 SDATA object file
6556 SVR4/EABI -fpic SVR4 pic object file
6557 SVR4/EABI -fPIC SVR4 PIC translation unit
6558 SVR4/EABI -mrelocatable EABI TOC function
6559 SVR4/EABI -maix AIX TOC object file
6560 SVR4/EABI -maix -mminimal-toc
6561 AIX minimal TOC translation unit
6563 Name Reg. Set by entries contains:
6564 made by addrs? fp? sum?
6566 AIX TOC 2 crt0 as Y option option
6567 AIX minimal TOC 30 prolog gcc Y Y option
6568 SVR4 SDATA 13 crt0 gcc N Y N
6569 SVR4 pic 30 prolog ld Y not yet N
6570 SVR4 PIC 30 prolog gcc Y option option
6571 EABI TOC 30 prolog gcc Y option option
6575 /* Hash table stuff for keeping track of TOC entries. */
6577 struct toc_hash_struct
6579 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
6580 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
6581 rtx key;
6582 enum machine_mode key_mode;
6583 int labelno;
6586 static htab_t toc_hash_table;
6588 /* Hash functions for the hash table. */
6590 static unsigned
6591 rs6000_hash_constant (k)
6592 rtx k;
6594 unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k);
6595 const char *format = GET_RTX_FORMAT (GET_CODE (k));
6596 int flen = strlen (format);
6597 int fidx;
6599 if (GET_CODE (k) == LABEL_REF)
6600 return result * 1231 + X0INT (XEXP (k, 0), 3);
6602 if (GET_CODE (k) == CONST_DOUBLE)
6603 fidx = 2;
6604 else if (GET_CODE (k) == CODE_LABEL)
6605 fidx = 3;
6606 else
6607 fidx = 0;
6609 for (; fidx < flen; fidx++)
6610 switch (format[fidx])
6612 case 's':
6614 unsigned i, len;
6615 const char *str = XSTR (k, fidx);
6616 len = strlen (str);
6617 result = result * 613 + len;
6618 for (i = 0; i < len; i++)
6619 result = result * 613 + (unsigned) str[i];
6620 break;
6622 case 'u':
6623 case 'e':
6624 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
6625 break;
6626 case 'i':
6627 case 'n':
6628 result = result * 613 + (unsigned) XINT (k, fidx);
6629 break;
6630 case 'w':
6631 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
6632 result = result * 613 + (unsigned) XWINT (k, fidx);
6633 else
6635 size_t i;
6636 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
6637 result = result * 613 + (unsigned) (XWINT (k, fidx)
6638 >> CHAR_BIT * i);
6640 break;
6641 default:
6642 abort();
6644 return result;
6647 static unsigned
6648 toc_hash_function (hash_entry)
6649 const void * hash_entry;
6651 const struct toc_hash_struct *thc =
6652 (const struct toc_hash_struct *) hash_entry;
6653 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
6656 /* Compare H1 and H2 for equivalence. */
6658 static int
6659 toc_hash_eq (h1, h2)
6660 const void * h1;
6661 const void * h2;
6663 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
6664 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
6666 if (((const struct toc_hash_struct *) h1)->key_mode
6667 != ((const struct toc_hash_struct *) h2)->key_mode)
6668 return 0;
6670 /* Gotcha: One of these const_doubles will be in memory.
6671 The other may be on the constant-pool chain.
6672 So rtx_equal_p will think they are different... */
6673 if (r1 == r2)
6674 return 1;
6675 if (GET_CODE (r1) != GET_CODE (r2)
6676 || GET_MODE (r1) != GET_MODE (r2))
6677 return 0;
6678 if (GET_CODE (r1) == CONST_DOUBLE)
6680 int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE));
6681 int i;
6682 for (i = 2; i < format_len; i++)
6683 if (XWINT (r1, i) != XWINT (r2, i))
6684 return 0;
6686 return 1;
6688 else if (GET_CODE (r1) == LABEL_REF)
6689 return (CODE_LABEL_NUMBER (XEXP (r1, 0))
6690 == CODE_LABEL_NUMBER (XEXP (r2, 0)));
6691 else
6692 return rtx_equal_p (r1, r2);
6695 /* Mark the hash table-entry HASH_ENTRY. */
6697 static int
6698 toc_hash_mark_entry (hash_slot, unused)
6699 void ** hash_slot;
6700 void * unused ATTRIBUTE_UNUSED;
6702 const struct toc_hash_struct * hash_entry =
6703 *(const struct toc_hash_struct **) hash_slot;
6704 rtx r = hash_entry->key;
6705 ggc_set_mark (hash_entry);
6706 /* For CODE_LABELS, we don't want to drag in the whole insn chain... */
6707 if (GET_CODE (r) == LABEL_REF)
6709 ggc_set_mark (r);
6710 ggc_set_mark (XEXP (r, 0));
6712 else
6713 ggc_mark_rtx (r);
6714 return 1;
6717 /* Mark all the elements of the TOC hash-table *HT. */
6719 static void
6720 toc_hash_mark_table (vht)
6721 void *vht;
6723 htab_t *ht = vht;
6725 htab_traverse (*ht, toc_hash_mark_entry, (void *)0);
6728 /* These are the names given by the C++ front-end to vtables, and
6729 vtable-like objects. Ideally, this logic should not be here;
6730 instead, there should be some programmatic way of inquiring as
6731 to whether or not an object is a vtable. */
6733 #define VTABLE_NAME_P(NAME) \
6734 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
6735 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
6736 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
6737 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
6739 void
6740 rs6000_output_symbol_ref (file, x)
6741 FILE *file;
6742 rtx x;
6744 /* Currently C++ toc references to vtables can be emitted before it
6745 is decided whether the vtable is public or private. If this is
6746 the case, then the linker will eventually complain that there is
6747 a reference to an unknown section. Thus, for vtables only,
6748 we emit the TOC reference to reference the symbol and not the
6749 section. */
6750 const char *name = XSTR (x, 0);
6752 if (VTABLE_NAME_P (name))
6754 RS6000_OUTPUT_BASENAME (file, name);
6756 else
6757 assemble_name (file, name);
6760 /* Output a TOC entry. We derive the entry name from what is
6761 being written. */
6763 void
6764 output_toc (file, x, labelno, mode)
6765 FILE *file;
6766 rtx x;
6767 int labelno;
6768 enum machine_mode mode;
6770 char buf[256];
6771 const char *name = buf;
6772 const char *real_name;
6773 rtx base = x;
6774 int offset = 0;
6776 if (TARGET_NO_TOC)
6777 abort ();
6779 /* When the linker won't eliminate them, don't output duplicate
6780 TOC entries (this happens on AIX if there is any kind of TOC,
6781 and on SVR4 under -fPIC or -mrelocatable). */
6782 if (TARGET_TOC)
6784 struct toc_hash_struct *h;
6785 void * * found;
6787 h = ggc_alloc (sizeof (*h));
6788 h->key = x;
6789 h->key_mode = mode;
6790 h->labelno = labelno;
6792 found = htab_find_slot (toc_hash_table, h, 1);
6793 if (*found == NULL)
6794 *found = h;
6795 else /* This is indeed a duplicate.
6796 Set this label equal to that label. */
6798 fputs ("\t.set ", file);
6799 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6800 fprintf (file, "%d,", labelno);
6801 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
6802 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
6803 found)->labelno));
6804 return;
6808 /* If we're going to put a double constant in the TOC, make sure it's
6809 aligned properly when strict alignment is on. */
6810 if (GET_CODE (x) == CONST_DOUBLE
6811 && STRICT_ALIGNMENT
6812 && GET_MODE_BITSIZE (mode) >= 64
6813 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
6814 ASM_OUTPUT_ALIGN (file, 3);
6817 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
6819 /* Handle FP constants specially. Note that if we have a minimal
6820 TOC, things we put here aren't actually in the TOC, so we can allow
6821 FP constants. */
6822 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
6824 REAL_VALUE_TYPE rv;
6825 long k[2];
6827 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
6828 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
6830 if (TARGET_64BIT)
6832 if (TARGET_MINIMAL_TOC)
6833 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
6834 else
6835 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
6836 k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff);
6837 return;
6839 else
6841 if (TARGET_MINIMAL_TOC)
6842 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]);
6843 else
6844 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n",
6845 k[0], k[1], k[0], k[1]);
6846 return;
6849 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
6851 REAL_VALUE_TYPE rv;
6852 long l;
6854 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
6855 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
6857 if (TARGET_64BIT)
6859 if (TARGET_MINIMAL_TOC)
6860 fprintf (file, "\t.llong 0x%lx00000000\n", l);
6861 else
6862 fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l);
6863 return;
6865 else
6867 if (TARGET_MINIMAL_TOC)
6868 fprintf (file, "\t.long 0x%lx\n", l);
6869 else
6870 fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l);
6871 return;
6874 else if (GET_MODE (x) == VOIDmode
6875 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
6877 unsigned HOST_WIDE_INT low;
6878 HOST_WIDE_INT high;
6880 if (GET_CODE (x) == CONST_DOUBLE)
6882 low = CONST_DOUBLE_LOW (x);
6883 high = CONST_DOUBLE_HIGH (x);
6885 else
6886 #if HOST_BITS_PER_WIDE_INT == 32
6888 low = INTVAL (x);
6889 high = (low & 0x80000000) ? ~0 : 0;
6891 #else
6893 low = INTVAL (x) & 0xffffffff;
6894 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
6896 #endif
6898 /* TOC entries are always Pmode-sized, but since this
6899 is a bigendian machine then if we're putting smaller
6900 integer constants in the TOC we have to pad them.
6901 (This is still a win over putting the constants in
6902 a separate constant pool, because then we'd have
6903 to have both a TOC entry _and_ the actual constant.)
6905 For a 32-bit target, CONST_INT values are loaded and shifted
6906 entirely within `low' and can be stored in one TOC entry. */
6908 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
6909 abort ();/* It would be easy to make this work, but it doesn't now. */
6911 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
6912 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
6913 POINTER_SIZE, &low, &high, 0);
6915 if (TARGET_64BIT)
6917 if (TARGET_MINIMAL_TOC)
6918 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
6919 else
6920 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
6921 (long)high, (long)low, (long)high, (long)low);
6922 return;
6924 else
6926 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
6928 if (TARGET_MINIMAL_TOC)
6929 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n",
6930 (long)high, (long)low);
6931 else
6932 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n",
6933 (long)high, (long)low, (long)high, (long)low);
6935 else
6937 if (TARGET_MINIMAL_TOC)
6938 fprintf (file, "\t.long 0x%lx\n",
6939 (long)low);
6940 else
6941 fprintf (file, "\t.tc IS_%lx[TC],0x%lx\n",
6942 (long)low, (long)low);
6944 return;
6948 if (GET_CODE (x) == CONST)
6950 base = XEXP (XEXP (x, 0), 0);
6951 offset = INTVAL (XEXP (XEXP (x, 0), 1));
6954 if (GET_CODE (base) == SYMBOL_REF)
6955 name = XSTR (base, 0);
6956 else if (GET_CODE (base) == LABEL_REF)
6957 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
6958 else if (GET_CODE (base) == CODE_LABEL)
6959 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
6960 else
6961 abort ();
6963 STRIP_NAME_ENCODING (real_name, name);
6964 if (TARGET_MINIMAL_TOC)
6965 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
6966 else
6968 fprintf (file, "\t.tc %s", real_name);
6970 if (offset < 0)
6971 fprintf (file, ".N%d", - offset);
6972 else if (offset)
6973 fprintf (file, ".P%d", offset);
6975 fputs ("[TC],", file);
6978 /* Currently C++ toc references to vtables can be emitted before it
6979 is decided whether the vtable is public or private. If this is
6980 the case, then the linker will eventually complain that there is
6981 a TOC reference to an unknown section. Thus, for vtables only,
6982 we emit the TOC reference to reference the symbol and not the
6983 section. */
6984 if (VTABLE_NAME_P (name))
6986 RS6000_OUTPUT_BASENAME (file, name);
6987 if (offset < 0)
6988 fprintf (file, "%d", offset);
6989 else if (offset > 0)
6990 fprintf (file, "+%d", offset);
6992 else
6993 output_addr_const (file, x);
6994 putc ('\n', file);
6997 /* Output an assembler pseudo-op to write an ASCII string of N characters
6998 starting at P to FILE.
7000 On the RS/6000, we have to do this using the .byte operation and
7001 write out special characters outside the quoted string.
7002 Also, the assembler is broken; very long strings are truncated,
7003 so we must artificially break them up early. */
7005 void
7006 output_ascii (file, p, n)
7007 FILE *file;
7008 const char *p;
7009 int n;
7011 char c;
7012 int i, count_string;
7013 const char *for_string = "\t.byte \"";
7014 const char *for_decimal = "\t.byte ";
7015 const char *to_close = NULL;
7017 count_string = 0;
7018 for (i = 0; i < n; i++)
7020 c = *p++;
7021 if (c >= ' ' && c < 0177)
7023 if (for_string)
7024 fputs (for_string, file);
7025 putc (c, file);
7027 /* Write two quotes to get one. */
7028 if (c == '"')
7030 putc (c, file);
7031 ++count_string;
7034 for_string = NULL;
7035 for_decimal = "\"\n\t.byte ";
7036 to_close = "\"\n";
7037 ++count_string;
7039 if (count_string >= 512)
7041 fputs (to_close, file);
7043 for_string = "\t.byte \"";
7044 for_decimal = "\t.byte ";
7045 to_close = NULL;
7046 count_string = 0;
7049 else
7051 if (for_decimal)
7052 fputs (for_decimal, file);
7053 fprintf (file, "%d", c);
7055 for_string = "\n\t.byte \"";
7056 for_decimal = ", ";
7057 to_close = "\n";
7058 count_string = 0;
7062 /* Now close the string if we have written one. Then end the line. */
7063 if (to_close)
7064 fputs (to_close, file);
7067 /* Generate a unique section name for FILENAME for a section type
7068 represented by SECTION_DESC. Output goes into BUF.
7070 SECTION_DESC can be any string, as long as it is different for each
7071 possible section type.
7073 We name the section in the same manner as xlc. The name begins with an
7074 underscore followed by the filename (after stripping any leading directory
7075 names) with the last period replaced by the string SECTION_DESC. If
7076 FILENAME does not contain a period, SECTION_DESC is appended to the end of
7077 the name. */
7079 void
7080 rs6000_gen_section_name (buf, filename, section_desc)
7081 char **buf;
7082 const char *filename;
7083 const char *section_desc;
7085 const char *q, *after_last_slash, *last_period = 0;
7086 char *p;
7087 int len;
7089 after_last_slash = filename;
7090 for (q = filename; *q; q++)
7092 if (*q == '/')
7093 after_last_slash = q + 1;
7094 else if (*q == '.')
7095 last_period = q;
7098 len = strlen (after_last_slash) + strlen (section_desc) + 2;
7099 *buf = (char *) permalloc (len);
7101 p = *buf;
7102 *p++ = '_';
7104 for (q = after_last_slash; *q; q++)
7106 if (q == last_period)
7108 strcpy (p, section_desc);
7109 p += strlen (section_desc);
7112 else if (ISALNUM (*q))
7113 *p++ = *q;
7116 if (last_period == 0)
7117 strcpy (p, section_desc);
7118 else
7119 *p = '\0';
7123 /* Emit profile function. */
7124 void
7125 output_profile_hook (labelno)
7126 int labelno;
7128 if (DEFAULT_ABI == ABI_AIX)
7130 char buf[30];
7131 char *label_name;
7132 rtx fun;
7134 labelno += 1;
7136 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7137 STRIP_NAME_ENCODING (label_name, ggc_strdup (buf));
7138 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
7140 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
7141 fun, Pmode);
7145 /* Write function profiler code. */
7147 void
7148 output_function_profiler (file, labelno)
7149 FILE *file;
7150 int labelno;
7152 /* The last used parameter register. */
7153 int last_parm_reg;
7154 int i, j;
7155 char buf[100];
7157 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7158 switch (DEFAULT_ABI)
7160 default:
7161 abort ();
7163 case ABI_V4:
7164 case ABI_SOLARIS:
7165 case ABI_AIX_NODESC:
7166 fprintf (file, "\tmflr %s\n", reg_names[0]);
7167 if (flag_pic == 1)
7169 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
7170 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7171 reg_names[0], reg_names[1]);
7172 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
7173 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
7174 assemble_name (file, buf);
7175 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
7177 else if (flag_pic > 1)
7179 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7180 reg_names[0], reg_names[1]);
7181 /* Now, we need to get the address of the label. */
7182 fputs ("\tbl 1f\n\t.long ", file);
7183 assemble_name (file, buf);
7184 fputs ("-.\n1:", file);
7185 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
7186 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
7187 reg_names[0], reg_names[11]);
7188 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
7189 reg_names[0], reg_names[0], reg_names[11]);
7191 else
7193 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
7194 assemble_name (file, buf);
7195 fputs ("@ha\n", file);
7196 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7197 reg_names[0], reg_names[1]);
7198 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
7199 assemble_name (file, buf);
7200 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
7203 if (current_function_needs_context)
7204 asm_fprintf (file, "\tmr %s,%s\n",
7205 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
7206 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
7207 if (current_function_needs_context)
7208 asm_fprintf (file, "\tmr %s,%s\n",
7209 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
7210 break;
7212 case ABI_AIX:
7213 /* Don't do anything, done in output_profile_hook (). */
7214 break;
7219 /* Adjust the cost of a scheduling dependency. Return the new cost of
7220 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7223 rs6000_adjust_cost (insn, link, dep_insn, cost)
7224 rtx insn;
7225 rtx link;
7226 rtx dep_insn ATTRIBUTE_UNUSED;
7227 int cost;
7229 if (! recog_memoized (insn))
7230 return 0;
7232 if (REG_NOTE_KIND (link) != 0)
7233 return 0;
7235 if (REG_NOTE_KIND (link) == 0)
7237 /* Data dependency; DEP_INSN writes a register that INSN reads some
7238 cycles later. */
7240 /* Tell the first scheduling pass about the latency between a mtctr
7241 and bctr (and mtlr and br/blr). The first scheduling pass will not
7242 know about this latency since the mtctr instruction, which has the
7243 latency associated to it, will be generated by reload. */
7244 if (get_attr_type (insn) == TYPE_JMPREG)
7245 return TARGET_POWER ? 5 : 4;
7247 /* Fall out to return default cost. */
7250 return cost;
7253 /* A C statement (sans semicolon) to update the integer scheduling priority
7254 INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier,
7255 increase the priority to execute INSN later. Do not define this macro if
7256 you do not need to adjust the scheduling priorities of insns. */
7259 rs6000_adjust_priority (insn, priority)
7260 rtx insn ATTRIBUTE_UNUSED;
7261 int priority;
7263 /* On machines (like the 750) which have asymetric integer units, where one
7264 integer unit can do multiply and divides and the other can't, reduce the
7265 priority of multiply/divide so it is scheduled before other integer
7266 operationss. */
7268 #if 0
7269 if (! INSN_P (insn))
7270 return priority;
7272 if (GET_CODE (PATTERN (insn)) == USE)
7273 return priority;
7275 switch (rs6000_cpu_attr) {
7276 case CPU_PPC750:
7277 switch (get_attr_type (insn))
7279 default:
7280 break;
7282 case TYPE_IMUL:
7283 case TYPE_IDIV:
7284 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
7285 priority, priority);
7286 if (priority >= 0 && priority < 0x01000000)
7287 priority >>= 3;
7288 break;
7291 #endif
7293 return priority;
7296 /* Return how many instructions the machine can issue per cycle */
7297 int get_issue_rate()
7299 switch (rs6000_cpu_attr) {
7300 case CPU_RIOS1: /* ? */
7301 case CPU_RS64A:
7302 case CPU_PPC601: /* ? */
7303 return 3;
7304 case CPU_PPC603:
7305 case CPU_PPC750:
7306 return 2;
7307 case CPU_RIOS2:
7308 case CPU_PPC604:
7309 case CPU_PPC604E:
7310 case CPU_PPC620:
7311 case CPU_PPC630:
7312 return 4;
7313 default:
7314 return 1;
7319 /* Length in units of the trampoline for entering a nested function. */
7322 rs6000_trampoline_size ()
7324 int ret = 0;
7326 switch (DEFAULT_ABI)
7328 default:
7329 abort ();
7331 case ABI_AIX:
7332 ret = (TARGET_32BIT) ? 12 : 24;
7333 break;
7335 case ABI_V4:
7336 case ABI_SOLARIS:
7337 case ABI_AIX_NODESC:
7338 ret = (TARGET_32BIT) ? 40 : 48;
7339 break;
7342 return ret;
7345 /* Emit RTL insns to initialize the variable parts of a trampoline.
7346 FNADDR is an RTX for the address of the function's pure code.
7347 CXT is an RTX for the static chain value for the function. */
7349 void
7350 rs6000_initialize_trampoline (addr, fnaddr, cxt)
7351 rtx addr;
7352 rtx fnaddr;
7353 rtx cxt;
7355 enum machine_mode pmode = Pmode;
7356 int regsize = (TARGET_32BIT) ? 4 : 8;
7357 rtx ctx_reg = force_reg (pmode, cxt);
7359 switch (DEFAULT_ABI)
7361 default:
7362 abort ();
7364 /* Macros to shorten the code expansions below. */
7365 #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
7366 #define MEM_PLUS(addr,offset) \
7367 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7369 /* Under AIX, just build the 3 word function descriptor */
7370 case ABI_AIX:
7372 rtx fn_reg = gen_reg_rtx (pmode);
7373 rtx toc_reg = gen_reg_rtx (pmode);
7374 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
7375 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
7376 emit_move_insn (MEM_DEREF (addr), fn_reg);
7377 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
7378 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
7380 break;
7382 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
7383 case ABI_V4:
7384 case ABI_SOLARIS:
7385 case ABI_AIX_NODESC:
7386 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7387 FALSE, VOIDmode, 4,
7388 addr, pmode,
7389 GEN_INT (rs6000_trampoline_size ()), SImode,
7390 fnaddr, pmode,
7391 ctx_reg, pmode);
7392 break;
7395 return;
7399 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7400 with arguments ARGS is a valid machine specific attribute for DECL.
7401 The attributes in ATTRIBUTES have previously been assigned to DECL. */
7404 rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
7405 tree decl ATTRIBUTE_UNUSED;
7406 tree attributes ATTRIBUTE_UNUSED;
7407 tree identifier ATTRIBUTE_UNUSED;
7408 tree args ATTRIBUTE_UNUSED;
7410 return 0;
7413 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7414 with arguments ARGS is a valid machine specific attribute for TYPE.
7415 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
7418 rs6000_valid_type_attribute_p (type, attributes, identifier, args)
7419 tree type;
7420 tree attributes ATTRIBUTE_UNUSED;
7421 tree identifier;
7422 tree args;
7424 if (TREE_CODE (type) != FUNCTION_TYPE
7425 && TREE_CODE (type) != FIELD_DECL
7426 && TREE_CODE (type) != TYPE_DECL)
7427 return 0;
7429 /* Longcall attribute says that the function is not within 2**26 bytes
7430 of the current function, and to do an indirect call. */
7431 if (is_attribute_p ("longcall", identifier))
7432 return (args == NULL_TREE);
7434 return 0;
7437 /* If defined, a C expression whose value is zero if the attributes on
7438 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
7439 two if they are nearly compatible (which causes a warning to be
7440 generated). */
7443 rs6000_comp_type_attributes (type1, type2)
7444 tree type1 ATTRIBUTE_UNUSED;
7445 tree type2 ATTRIBUTE_UNUSED;
7447 return 1;
7450 /* If defined, a C statement that assigns default attributes to newly
7451 defined TYPE. */
7453 void
7454 rs6000_set_default_type_attributes (type)
7455 tree type ATTRIBUTE_UNUSED;
7457 return;
7460 /* Return a reference suitable for calling a function with the
7461 longcall attribute. */
7462 struct rtx_def *
7463 rs6000_longcall_ref (call_ref)
7464 rtx call_ref;
7466 const char *call_name;
7467 tree node;
7469 if (GET_CODE (call_ref) != SYMBOL_REF)
7470 return call_ref;
7472 /* System V adds '.' to the internal name, so skip them. */
7473 call_name = XSTR (call_ref, 0);
7474 if (*call_name == '.')
7476 while (*call_name == '.')
7477 call_name++;
7479 node = get_identifier (call_name);
7480 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
7483 return force_reg (Pmode, call_ref);
7487 /* A C statement or statements to switch to the appropriate section
7488 for output of RTX in mode MODE. You can assume that RTX is some
7489 kind of constant in RTL. The argument MODE is redundant except in
7490 the case of a `const_int' rtx. Select the section by calling
7491 `text_section' or one of the alternatives for other sections.
7493 Do not define this macro if you put all constants in the read-only
7494 data section. */
7496 #ifdef USING_SVR4_H
7498 void
7499 rs6000_select_rtx_section (mode, x)
7500 enum machine_mode mode;
7501 rtx x;
7503 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7504 toc_section ();
7505 else
7506 const_section ();
7509 /* A C statement or statements to switch to the appropriate
7510 section for output of DECL. DECL is either a `VAR_DECL' node
7511 or a constant of some sort. RELOC indicates whether forming
7512 the initial value of DECL requires link-time relocations. */
7514 void
7515 rs6000_select_section (decl, reloc)
7516 tree decl;
7517 int reloc;
7519 int size = int_size_in_bytes (TREE_TYPE (decl));
7520 int needs_sdata;
7521 int readonly;
7522 static void (* const sec_funcs[4]) PARAMS ((void)) = {
7523 &const_section,
7524 &sdata2_section,
7525 &data_section,
7526 &sdata_section
7529 needs_sdata = (size > 0
7530 && size <= g_switch_value
7531 && rs6000_sdata != SDATA_NONE
7532 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7534 if (TREE_CODE (decl) == STRING_CST)
7535 readonly = ! flag_writable_strings;
7536 else if (TREE_CODE (decl) == VAR_DECL)
7537 readonly = (! (flag_pic && reloc)
7538 && TREE_READONLY (decl)
7539 && ! TREE_SIDE_EFFECTS (decl)
7540 && DECL_INITIAL (decl)
7541 && DECL_INITIAL (decl) != error_mark_node
7542 && TREE_CONSTANT (DECL_INITIAL (decl)));
7543 else
7544 readonly = 1;
7545 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7546 readonly = 0;
7548 (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])();
7551 /* A C statement to build up a unique section name, expressed as a
7552 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
7553 RELOC indicates whether the initial value of EXP requires
7554 link-time relocations. If you do not define this macro, GCC will use
7555 the symbol name prefixed by `.' as the section name. Note - this
7556 macro can now be called for unitialised data items as well as
7557 initialised data and functions. */
7559 void
7560 rs6000_unique_section (decl, reloc)
7561 tree decl;
7562 int reloc;
7564 int size = int_size_in_bytes (TREE_TYPE (decl));
7565 int needs_sdata;
7566 int readonly;
7567 int len;
7568 int sec;
7569 const char *name;
7570 char *string;
7571 const char *prefix;
7573 static const char *const prefixes[7][2] =
7575 { ".text.", ".gnu.linkonce.t." },
7576 { ".rodata.", ".gnu.linkonce.r." },
7577 { ".sdata2.", ".gnu.linkonce.s2." },
7578 { ".data.", ".gnu.linkonce.d." },
7579 { ".sdata.", ".gnu.linkonce.s." },
7580 { ".bss.", ".gnu.linkonce.b." },
7581 { ".sbss.", ".gnu.linkonce.sb." }
7584 needs_sdata = (TREE_CODE (decl) != FUNCTION_DECL
7585 && size > 0
7586 && size <= g_switch_value
7587 && rs6000_sdata != SDATA_NONE
7588 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7590 if (TREE_CODE (decl) == STRING_CST)
7591 readonly = ! flag_writable_strings;
7592 else if (TREE_CODE (decl) == VAR_DECL)
7593 readonly = (! (flag_pic && reloc)
7594 && TREE_READONLY (decl)
7595 && ! TREE_SIDE_EFFECTS (decl)
7596 && DECL_INITIAL (decl)
7597 && DECL_INITIAL (decl) != error_mark_node
7598 && TREE_CONSTANT (DECL_INITIAL (decl)));
7599 else
7600 readonly = 1;
7601 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7602 readonly = 0;
7604 sec = ((TREE_CODE (decl) == FUNCTION_DECL ? 0 : 1)
7605 + (readonly ? 0 : 2)
7606 + (needs_sdata ? 1 : 0)
7607 + (DECL_INITIAL (decl) == 0
7608 || DECL_INITIAL (decl) == error_mark_node) ? 4 : 0);
7610 STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7611 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
7612 len = strlen (name) + strlen (prefix);
7613 string = alloca (len + 1);
7615 sprintf (string, "%s%s", prefix, name);
7617 DECL_SECTION_NAME (decl) = build_string (len, string);
7621 /* If we are referencing a function that is static or is known to be
7622 in this file, make the SYMBOL_REF special. We can use this to indicate
7623 that we can branch to this function without emitting a no-op after the
7624 call. For real AIX calling sequences, we also replace the
7625 function name with the real name (1 or 2 leading .'s), rather than
7626 the function descriptor name. This saves a lot of overriding code
7627 to read the prefixes. */
7629 void
7630 rs6000_encode_section_info (decl)
7631 tree decl;
7633 if (TREE_CODE (decl) == FUNCTION_DECL)
7635 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7636 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
7637 && ! DECL_WEAK (decl))
7638 SYMBOL_REF_FLAG (sym_ref) = 1;
7640 if (DEFAULT_ABI == ABI_AIX)
7642 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
7643 size_t len2 = strlen (XSTR (sym_ref, 0));
7644 char *str = alloca (len1 + len2 + 1);
7645 str[0] = '.';
7646 str[1] = '.';
7647 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
7649 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
7652 else if (rs6000_sdata != SDATA_NONE
7653 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7654 && TREE_CODE (decl) == VAR_DECL)
7656 int size = int_size_in_bytes (TREE_TYPE (decl));
7657 tree section_name = DECL_SECTION_NAME (decl);
7658 const char *name = (char *)0;
7659 int len = 0;
7661 if (section_name)
7663 if (TREE_CODE (section_name) == STRING_CST)
7665 name = TREE_STRING_POINTER (section_name);
7666 len = TREE_STRING_LENGTH (section_name);
7668 else
7669 abort ();
7672 if ((size > 0 && size <= g_switch_value)
7673 || (name
7674 && ((len == sizeof (".sdata") - 1
7675 && strcmp (name, ".sdata") == 0)
7676 || (len == sizeof (".sdata2") - 1
7677 && strcmp (name, ".sdata2") == 0)
7678 || (len == sizeof (".sbss") - 1
7679 && strcmp (name, ".sbss") == 0)
7680 || (len == sizeof (".sbss2") - 1
7681 && strcmp (name, ".sbss2") == 0)
7682 || (len == sizeof (".PPC.EMB.sdata0") - 1
7683 && strcmp (name, ".PPC.EMB.sdata0") == 0)
7684 || (len == sizeof (".PPC.EMB.sbss0") - 1
7685 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
7687 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7688 size_t len = strlen (XSTR (sym_ref, 0));
7689 char *str = alloca (len + 2);
7691 str[0] = '@';
7692 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
7693 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
7698 #endif /* USING_SVR4_H */
7701 /* Return a REG that occurs in ADDR with coefficient 1.
7702 ADDR can be effectively incremented by incrementing REG.
7704 r0 is special and we must not select it as an address
7705 register by this routine since our caller will try to
7706 increment the returned register via an "la" instruction. */
7708 struct rtx_def *
7709 find_addr_reg (addr)
7710 rtx addr;
7712 while (GET_CODE (addr) == PLUS)
7714 if (GET_CODE (XEXP (addr, 0)) == REG
7715 && REGNO (XEXP (addr, 0)) != 0)
7716 addr = XEXP (addr, 0);
7717 else if (GET_CODE (XEXP (addr, 1)) == REG
7718 && REGNO (XEXP (addr, 1)) != 0)
7719 addr = XEXP (addr, 1);
7720 else if (CONSTANT_P (XEXP (addr, 0)))
7721 addr = XEXP (addr, 1);
7722 else if (CONSTANT_P (XEXP (addr, 1)))
7723 addr = XEXP (addr, 0);
7724 else
7725 abort ();
7727 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
7728 return addr;
7729 abort ();
7732 void
7733 rs6000_fatal_bad_address (op)
7734 rtx op;
7736 fatal_insn ("bad address", op);
7739 /* Called to register all of our global variables with the garbage
7740 collector. */
7742 static void
7743 rs6000_add_gc_roots ()
7745 ggc_add_rtx_root (&rs6000_compare_op0, 1);
7746 ggc_add_rtx_root (&rs6000_compare_op1, 1);
7748 toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL);
7749 ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table),
7750 toc_hash_mark_table);